Separating concerns.
WHAT LAYERING PROVIDES
Each concern in one place, testable and replaceable.
WHAT THE TYPICAL LAYERS ARE
- Interface: handling requests
- Application: orchestrating use cases
- Domain: business rules
- Infrastructure: databases, external services, messaging
WHAT THE DEPENDENCY RULE IS
Inner layers know nothing of outer ones.
WHAT THAT MEANS
Business rules do not reference the database or the web framework.
WHY THAT MATTERS
The rules can be tested without any infrastructure, and infrastructure can be replaced.
HOW IT IS ACHIEVED
The domain defines interfaces; infrastructure implements them.
WHAT THAT COSTS
More indirection More files More ceremony for simple operations
WHEN IT IS WARRANTED
Complex business rules Long-lived systems Systems where infrastructure is expected to change
WHEN IT IS NOT
Simple applications, where it obscures rather than clarifies.
WHAT TO AVOID
Applying it dogmatically Layers that only pass calls through
WHAT TO KEEP
The principle: business rules independent of delivery and storage.