Overview of The Clean Architecture
Above, Robert C. Martin’s description of The Clean Architecture
1. The Clean Architecture is methodology, not concrete
When we talk about architecture, many people automatically think of patterns like monolithic architecture, microservices, or Spring buckets.
The Clean Architecture has nothing to do with that, it is a methodology. That is:
- It’s not tied to a specific language or framework
- It is not tied to a specific technical direction
1.1 Not associated with language and framework
Need to keep in mind, not Java application to The Architecture, in fact, The Clean Architecture suitable for all language, The author used several languages, Java, TypeScript, Kotlin, Swift, etc., All can use The Clean Architecture mentioned above
So, of course, it’s not tied to specific technologies. In fact, The technology is The implementation detail, and The outermost layer of The circular layer in The figure, which The Clean Architecture considers The least important.
No matter what technical framework you are using, such as relational or non-relational databases, JPA or Mybatis, or even traditional and reactive programming, clean architectures can and should be applied
1.2 Not associated with specific technical direction
When we say architecture, it’s easy to think that this is just for architects, and the term architect is usually applied to the backend, which is currently dominated by Java. Many people take it for granted that architectural things are only associated with the background.
This is a huge misunderstanding
In fact, this was taken for granted when I was only working on back-end development. However, when I led the development of Android,iOS and front-end React and TypeScript projects in recent years, I gradually came to understand that this is a wrong understanding
Clean architectures can and should actually work in all directions, especially front-end, mobile, etc., where technicians tend to have less of a holistic view of the architecture and get bogged down in technical details.
I will continue to discuss how to apply a similar clean architecture and domain-driven style of design to the front end or mobile
2. Basic features of The Clean Architecture
If you understand or understand that what I mean by clean architecture is independent of language, framework, and technical direction, then the following feature-based approach makes it even more clear.
Robert C. Martin discussed several basic characteristics of The Clean Architecture
- It has nothing to do with the technical framework
- Testable and free from external influences such as UI, database, and third party services
- UI-independent
- Not dependent on third-party services, decoupled from them
Based on The above features, it can be further demonstrated that The Clean Architecture is independent of language, framework and technical direction. In fact, no matter what kind of development you do, the above principles should be the basic principles you should refer to in the process of coding, it is also the basic guarantee of maintainability, without these principles, your code is like the attic, impossible to maintainability
In fact, that’s exactly what most of us programmers don’t care about. Many programmers automatically ask: What’s the point of isolating specific technologies? Hibernate doesn’t change at all
This is a sign of great immaturity. Why is this idea very naive and immature
3. The Clean Architecture’s principle of layering and dependence
3.1 Stratification of The Clean Architecture
As can be seen from The figure, The Clean Architecture can be roughly divided into The following layers
- Entities
- Use Cases
- Interface Adapters
- Frameworks and Drivers.
Of course, this is just an overview, and in fact, depending on the project, you can add other layers to it.
I will discuss these layers later. Before that, I should first clarify a golden principle, that is, the principle of dependence
3.2 The golden principle of The Clean Architecture
One principle that must be clarified before any of The others can be described is The Clean Architecture’s principle of dependency
Dependencies are outside-in, that is, the outer layer knows and depends on the inner layer, which does not know and cannot call the outer layer at all
This is the golden rule and needs to be repeated.
In this architecture, the specific technology, the framework. For example, databases, network frameworks, etc., are in the outermost layer. This means that the core business in your project cannot make any API calls that are aware of things like JPA or Hibernate.
A lot of people ask, how?
The following author will come slowly.
This series of articles
1. Why Clean Architecture
This article was first published on my website lingenliu.cc