Ensuring domain independence
The independence of the Domain layer is a cornerstone of Clean Architecture, directly tied to the Dependency Rule we first introduced in Chapter 1. This rule, stating that dependencies should only point inward toward the Domain layer, is crucial for maintaining the purity and flexibility of our core business logic. In this section, we’ll explore practical applications of this rule and strategies to ensure domain independence.
The Dependency Rule in practice
Let’s examine how the Dependency Rule applies to our task management system, using examples that highlight common violations and their corrections.
Example 1
Task entity with database dependency:
@dataclass
class TaskWithDatabase:
title: str
description: str
db: DbConnection # This violates the Dependency Rule
due_date: Optional[Deadline] = None
...