设定一个场景:公司要对接两家服务商的业务,业务是相同的,但是两家服务商的接口表现形式是不同的,需要我们对其做一层封装,让它们实现我们统一的接口,以便于公司内部调用。

假设业务包括会员和优惠券两个部分,首先我们需要 创建一个ErpService.Abstract项目,并为这两个业务定义两个统一的接口以及一个抽象工厂接口。

//会员接口
public interface IVipService
{
    int AddVip(Vip vip);
}
//优惠券接口
public interface ICouponService
{
    int AddCouponPlan(CouponPlan couponPlan);
}
public class Vip
{
    public string mobile { get; set; }
    public string vipName { get; set; }
    public short sex { get; set; }
}
public class CouponPlan
{
    public int planId { get; set; }
    public string planName { get; set; }
    public string remark { get; set; }
}
//抽象工厂接口
public interface IErpServiceFactory
{
    IVipService GetVipInstance();

    ICouponService GetCouponInstance();
}
View Code

相关文章:

  • 2021-10-29
  • 2021-10-15
  • 2021-11-16
  • 2021-11-11
猜你喜欢
  • 2021-08-03
  • 2021-11-08
  • 2021-06-16
  • 2021-12-13
  • 2021-07-01
  • 2022-01-20
  • 2021-11-06
相关资源
相似解决方案