Why COLA 3.0 Strips Away Complexity: An Ockham’s Razor‑Driven Refactor
This article examines the COLA application‑architecture framework, explains how the author applied Ockham’s razor to prune unnecessary concepts such as Command, Interceptor, and Convertor/Validator/Assembler, and shows concrete code before and after the simplification, culminating in a leaner, more maintainable backend design.
Background
COLA is an application‑architecture framework for Java services that aggregates concepts from onion architecture, adapters, DDD, clean architecture and TMF. It is adopted as one of Alibaba Cloud’s Java initialization options.
Motivation for COLA 3.0
In practice the original design introduced unnecessary abstractions that made the code harder to read and maintain. The upgrade follows the principle of Ockham’s razor: remove superfluous concepts without adding new features.
Ockham’s Razor Principle
The simplest solution that works is preferred; design elements that add cognitive overhead without clear benefit should be eliminated.
Typical Over‑design Patterns
Complex pipeline designs that split a business operation into many tiny steps, obscuring the overall flow.
Command‑Bus patterns borrowed from CQRS that force commands and queries into separate executors, increasing indirection.
Convertor, Validator, and Assembler layers that duplicate naming conventions and add little functional value.
Refactor Steps
1. Remove Command
The CommandBus is eliminated and service methods are invoked directly, preserving extension points while simplifying the call chain.
public class CreateCSPUExecutor {
@Resource private InitContextStep initContextStep;
@Resource private CheckRequiredParamStep checkRequiredParamStep;
// ... other steps omitted for brevity ...
public Long create(MyCspuSaveParam param){
SaveCSPUContext ctx = initContextStep.initContext(param);
checkRequiredParamStep.check(ctx);
// other checks ...
createCSPUStep.create(ctx);
createCSPULogStep.log(ctx);
sendCSPUCreatedEventStep.sendEvent(ctx);
return ctx.getCspu().getId();
}
}2. Remove Interceptor
Interceptors were added to the CommandBus for AOP‑style processing. Since Spring’s native AOP already satisfies most needs, the interceptor layer is removed to reduce indirection.
3. Remove Convertor, Validator, Assembler
These layers were intended only to standardise naming and provided little functional benefit. They are removed, allowing each team to define its own naming conventions.
4. Optimize Class Scanning
The original TMF‑based class‑scanning duplicated Spring’s capabilities. The refactor switches to Spring’s ListableBeanFactory.getBeansWithAnnotation to discover @Extension beans, simplifying the implementation.
String[] beanNames = beanFactory.getBeanNamesForAnnotation(Extension.class);
for (String name : beanNames) {
Object bean = beanFactory.getBean(name);
// register extension point
}Result
After simplification COLA retains its core extension‑point model while shedding most heavyweight infrastructure. CQRS becomes optional rather than mandatory, and the framework now follows a minimal “Ockham‑compliant” approach that improves readability, reduces maintenance cost, and remains suitable for large‑scale Alibaba Cloud Java applications.
References
COLA open‑source repository: https://github.com/alibaba/COLA
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 Native
We publish cloud-native tech news, curate in-depth content, host regular events and live streams, and share Alibaba product and user case studies. Join us to explore and share the cloud-native insights you need.
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.
