首先介绍一下JD-matrix:通过对matrix框架的架构了解,发现JD的matrix是对DDD领域驱动设计理念的一种具体实现。
matrix框架中包含有一下注解:
@APP @prodect @Domain @DomainService @DomianAbility @DomainAbilityExtension @Extension
@APP表示垂直业务身份
内容包含
/** * 业务身份定义类 * code 业务身份code * name 业务身份名称 * priority 优先级,数值越大优先级约高 * parserClass 业务身份解析类 */ @App(code = BizApp.CODE, name = "XXX", priority = 300, version = "1.0.0", parserClass = BizAppCodeParser.class) public class BizApp extends BaseApp { public static final String CODE="XXX"; }
@Product表示水平业务身份
/** * 业务身份定义类 * code 业务身份code * name 业务身份名称 **/ @Product(code = ProductAProduct.CODE, name = "水平业务身份A") public class ProductAProduct extends BaseProduct { public static final String CODE = "productA"; /** * 判断水平业务身份是否被击中 返回true则为击中 */ @Override public boolean isEffect(DomainModel domainModel) { return true; } /** * 返回禁止掉的水平业务身份code集合 */ @Override public Collection<String> getDisabledExtCodes() { return null; } }
@Domain(code = UseDomain.CODE, name = "用户") public class UseDomain { public static final String CODE="TRADE.cart.user"; }
public interface GetUserDiscountService extends IDomainService { String ITEM_SERVICE_SAVING_ORDER = "DOMAIN_SERVICE_GETDISCOUNT"; @DomainService( parent = UseDomain.CODE, code = ITEM_SERVICE_SAVING_ORDER, name = "XXX" ) public Double getDiscount(OrderModel order); }
/** * CheckSubmitOrderAbility简介 * 能力类 * 需要@DomainAbility注解 parent 为领域code * 需要继承BaseDomainAbility类 第一个泛型orderModel用于判断业务身份,垂直业务身份,水平业务身份是否击中的入参参考 * com.jd.migration.matrx2.fresh7.ext.BizAppCodeParser类的三个方法 。第二个泛型为能力要调用的拓展点方法。 */ @DomainAbility(name = "XXX", parent = TesthjzDomain.CODE) public class CheckSubmitOrderAbility extends BaseDomainAbility<OrderModel, CheckSubmitOrderExt> { .... }
public interface GetUserDiscountExt extends IDomainAbilityExtension { String EXT_CHECK_CODE="EXT_TRADE_CART_USE_GetUserDiscountExt_getDiscount"; @DomainAbilityExtension( code = EXT_CHECK_CODE, name = "XXX" ) public ResponseResult getDiscount(OrderModel order); }
@Extension(code = BrandFlashApp.CODE,scenario = "nike" ,index = 1) public class BrandFlashGetUserDiscountExtImpl implements GetUserDiscountExt { .... }