How to Code Complex Applications: Core Java Technology and Architecture

Processing of Complex Application: Background

Process Decomposition

@Command
public class OnSaleNormalItemCmdExe {
@Resource
private OnSaleContextInitPhase onSaleContextInitPhase;
@Resource
private OnSaleDataCheckPhase onSaleDataCheckPhase;
@Resource
private OnSaleProcessPhase onSaleProcessPhase;
@Override
public Response execute(OnSaleNormalItemCmd cmd) {

OnSaleContext onSaleContext = init(cmd);

checkData(onSaleContext);
process(onSaleContext); return Response.buildSuccess();
}
private OnSaleContext init(OnSaleNormalItemCmd cmd) {
return onSaleContextInitPhase.init(cmd);
}
private void checkData(OnSaleContext onSaleContext) {
onSaleDataCheckPhase.check(onSaleContext);
}
private void process(OnSaleContext onSaleContext) {
onSaleProcessPhase.process(onSaleContext);
}
}
@Phase
public class OnSaleProcessPhase {
@Resource
private PublishOfferStep publishOfferStep;
@Resource
private BackOfferBindStep backOfferBindStep;
//omit other steps
public void process(OnSaleContext onSaleContext){
SupplierItem supplierItem = onSaleContext.getSupplierItem();
// generate OfferGroupNo
generateOfferGroupNo(supplierItem);

// publish offer
publishOffer(supplierItem);
// bind back offer stock
bindBackOfferStock(supplierItem);
// synchroize sotck
syncStockRoute(supplierItem);
// set virtual product tag
setVirtualProductExtension(supplierItem);
// set procteciton label
markSendProtection(supplierItem);
// record Change Details
recordChangeDetail(supplierItem);
// synchronize price
syncSupplyPriceToBackOffer(supplierItem);
// set exteinsion info
setCombineProductExtension(supplierItem);
// remove sellout tag
removeSellOutTag(offerId);
// fire domian event
fireDomainEvent(supplierItem);

// close to-do issues
closeIssues(supplierItem);
}
}

Post Process Decomposition Challenges

boolean isCombineProduct = supplierItem.getSign().isCombProductQuote();// supplier.usc warehouse needn't check
if (WarehouseTypeEnum.isAliWarehouse(supplierItem.getWarehouseType())) {
// quote warehosue check
if (CollectionUtil.isEmpty(supplierItem.getWarehouseIdList()) && !isCombineProduct) {
throw ExceptionFactory.makeFault(ServiceExceptionCode.SYSTEM_ERROR, "You cant publish offer, since there is no warehouse info");
}
// inventory amount check
Long sellableAmount = 0L;
if (!isCombineProduct) {
sellableAmount = normalBiz.acquireSellableAmount(supplierItem.getBackOfferId(), supplierItem.getWarehouseIdList());
} else {
//combination product
OfferModel backOffer = backOfferQueryService.getBackOffer(supplierItem.getBackOfferId());
if (backOffer != null) {
sellableAmount = backOffer.getOffer().getTradeModel().getTradeCondition().getAmountOnSale();
}
}
if (sellableAmount < 1) {
throw ExceptionFactory.makeFault(ServiceExceptionCode.SYSTEM_ERROR, "Your stock is less than 1, please supply more items. The product id:" + supplierItem.getId() + "]");
}
}
if(backOffer.isCloudWarehouse()){
return;
}
if (backOffer.isNonInWarehouse()){
throw new BizException("You cant publish offer, since there is no warehouse info");
}
if (backOffer.getStockAmount() < 1){
throw new BizException("Your stock is less than 1, please supply more items,The product id:" + backOffer.getSupplierItem().getCspuCode() + "]");
}

Process Decomposition Plus Object Models

Methodologies Used to Code Complex Applications

Top-down and Bottom-up Combination

Capability Sink-in

Code Reusability and Cohesion: Two Key criteria in the Sink-in

public class CSPU {
private String code;
private String baseCode;
//omit other attributes
/**
* check if it is minimumu unit
*
*/
public boolean isMinimumUnit(){
return StringUtils.equals(code, baseCode);
}
/**
* check if it is middle package
*
*/
public boolean isMidPackage(){
return StringUtils.equals(code, midPackageCode);
}
}

How Should We Practice Application Development

Postscript

Original Source

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store