COLA 是 Clean Object-Oriented and Layered Architecture的缩写,代表“整洁面向对象分层架构”。 目前COLA已经发展到COLA v5。
- 想了解更多COLA信息,请关注微信公众号:
- 想了解更多COLA背后的故事,请支持我的新书《程序员的底层思维》
COLA分为两个部分,COLA架构和COLA组件。
架构的意义 就是 要素结构:
而 应用架构的意义 就在于
COLA架构就是为此而生,其核心职责就是定义良好的应用结构,提供最佳应用架构的最佳实践。通过不断探索,我们发现良好的分层结构,良好的包结构定义,可以帮助我们治理混乱不堪的业务应用系统。
经过多次迭代,我们定义出了相对稳定、可靠的应用架构:
好的应用架构,都遵循一些共同模式,不管是六边形架构、洋葱圈架构、整洁架构、还是COLA架构,都提倡以业务为核心,解耦外部依赖,分离业务复杂度和技术复杂度等。
COLA架构区别于这些架构的地方,在于除了思想之外,我们还提供了可落地的工具和实践指导。
为了能够快速创建满足COLA架构的应用,我们提供了两个archetype
,位于cola-archetypes
目录下:
cola-archetype-service
:用来创建纯后端服务的archetype
。cola-archetype-web
:用来创建adapter
和后端服务一体的web
应用archetype
。此外,我们还提供了一些非常有用的通用组件,这些组件可以帮助我们提升研发效率。
这些功能组件被收拢在cola-components
目录下面。到目前为止,我们已经沉淀了以下组件:
cola-component-dto
定义了DTO
格式,包括分页 无 cola-component-exception
定义了异常格式,
BizException
和SysException
无 cola-component-statemachine
状态机组件 无 cola-component-domain-starter
Spring
托管的领域实体组件 无 cola-component-catchlog-starter
异常处理和日志组件 exception
、dto
组件 cola-component-extension-starter
扩展点组件 无 cola-component-test-container
测试容器组件 无
执行以下命令:
mvn archetype:generate \ -DgroupId=com.alibaba.cola.demo.web \ -DartifactId=demo-web \ -Dversion=1.0.0-SNAPSHOT \ -Dpackage=com.alibaba.demo \ -DarchetypeArtifactId=cola-framework-archetype-web \ -DarchetypeGroupId=com.alibaba.cola \ -DarchetypeVersion=5.0.0
命令执行成功的话,会看到如下的应用代码结构:
项目
目录下运行mvn install
(如果不想运行测试,可以加上-DskipTests
参数)。start
目录,执行mvn spring-boot:run
。SpringBoot
启动成功的界面。Rest
请求,可以在浏览器中输入 http://localhost:8080/helloworld 进行测试。如果要生成不是web
工程而是service
工程也类似,执行的是下面的命令:
mvn archetype:generate \ -DgroupId=com.alibaba.cola.demo.service \ -DartifactId=demo-service \ -Dversion=1.0.0-SNAPSHOT \ -Dpackage=com.alibaba.demo \ -DarchetypeArtifactId=cola-framework-archetype-service \ -DarchetypeGroupId=com.alibaba.cola \ -DarchetypeVersion=5.0.0
https://blog.csdn.net/significantfrank/article/details/110934799
https://blog.csdn.net/significantfrank/article/details/109529311
cola-core
,只保留了扩展能力。exception
从cola-core
移入到cola-common
。archetype
中的分包逻辑进行重构,改成按照domain
做划分。cola-archetype-web
中的controller
改名为adapter
,为了呼应六边形架构的命名。https://blog.csdn.net/significantfrank/article/details/106976804
https://blog.csdn.net/significantfrank/article/details/100074716
https://blog.csdn.net/significantfrank/article/details/85785565
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4