Mastering Complex Business Code: Structured Decomposition & Domain Modeling
This article presents a practical methodology for handling complex business scenarios by combining top‑down process decomposition with bottom‑up domain modeling, illustrated through Alibaba's retail‑to‑store product onboarding case, complete with code examples and architectural guidance.
Complex Business Process Handling
Alibaba senior technical expert Zhang Jianfei shares a methodology for writing complex business code, using the retail‑to‑store product domain as a case study.
Business Background
Retail‑to‑store is a B2B supply model that digitizes traditional supply chains to improve efficiency; Alibaba acts as the platform providing service functions.
Product lifecycle and the critical “on‑sale” operation are illustrated with diagrams.
Process Decomposition
The author advocates dividing a large service method into phases and steps, avoiding monolithic code. Simple pipeline or no tool is preferred over heavyweight workflow engines.
Code example of an OnSaleNormalItemCmdExe command shows three phases: init, data check, and process.
@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);
}
}The OnSaleProcessPhase further breaks down into multiple steps such as publishing offers, binding stock, and sending domain events.
@Phase
public class OnSaleProcessPhase {
@Resource
private PublishOfferStep publishOfferStep;
@Resource
private BackOfferBindStep backOfferBindStep;
// other steps omitted
public void process(OnSaleContext onSaleContext) {
SupplierItem supplierItem = onSaleContext.getSupplierItem();
generateOfferGroupNo(supplierItem);
publishOffer(supplierItem);
bindBackOfferStock(supplierItem);
syncStockRoute(supplierItem);
setVirtualProductExtension(supplierItem);
markSendProtection(supplierItem);
recordChangeDetail(supplierItem);
syncSupplyPriceToBackOffer(supplierItem);
setCombineProductExtension(supplierItem);
removeSellOutTag(offerId);
fireDomainEvent(supplierItem);
closeIssues(supplierItem);
}
}Domain Modeling Benefits
Introducing domain models (e.g., CSPU) replaces scattered string comparisons with clear methods like isMinimumUnit() and isMidPackage(), improving readability and reducing duplication.
public class CSPU {
private String code;
private String baseCode;
// ...
public boolean isMinimumUnit() {
return StringUtils.equals(code, baseCode);
}
public boolean isMidPackage() {
return StringUtils.equals(code, midPackageCode);
}
}Ability Sinking Strategy
Instead of forcing all logic into the domain layer, the author proposes “ability sinking”: only abstract and place reusable capabilities in the domain, while use‑case‑specific steps stay in the application layer.
Conclusion
Combining top‑down process decomposition with bottom‑up object modeling yields clean, maintainable code for complex business scenarios, and the same principles can be applied across domains.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Alibaba Cloud Developer
Alibaba's official tech channel, featuring all of its technology innovations.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
