Architecture decisions are often justified by authority: this is how the vendor does it. For one of the most widely adopted patterns in Android development, that justification does not hold, and the vendor has said so in writing.
Same Words, Different Design
Clean Architecture and Google's recommended app architecture both talk about a domain layer and use cases. Our own article presented them as one thing until this month. Google's page carries a note that the term is used in clean architecture as well "and has a different meaning there", and asks readers not to confuse its definition "with other definitions you may have read elsewhere" (Android).
The difference is which part of the system is allowed to know about which. In Google's version, the layer holding business rules may depend on the layer that talks to databases and servers. In Clean Architecture that dependency is reversed, so the business rules know nothing about storage or networking at all.
What Each One Costs
The strict version buys independence. Business rules can be tested without a device and survive a change of database or API. The price is more code: an interface and a translation step at every boundary.
Google's version is lighter, and its page treats the layer itself as optional: it "is an optional layer that sits between the UI layer and the data layer". It also names the failure mode of strictness, that it "forces you to add use cases even when they are just simple function calls to the data layer, which can add complexity for little benefit."
Neither is wrong. What is wrong is paying the price of the strict version while believing it is the default, or adopting the light version and expecting the independence.
Enforce It or Do Not Claim It
A dependency rule that lives in a document is a preference. The same rule expressed in the build, where the business module physically cannot reference the networking library, is a guarantee. If the architecture matters enough to mandate, it matters enough to enforce mechanically.
What to Ask Your Team
- Which architecture did we adopt, and can we name the trade-off we accepted?
- Is our layering enforced by the build or by code review?
- How many of our abstractions do nothing but pass a call through?
-Rocky
#SoftwareArchitecture #CleanArchitecture #TechnicalLeadership #EngineeringDreams #StrategiaX
Originally published on ANDROID-ARCHITECT, the Android engineering blog of Strategia-X, with the full module structure and code.
