Abstract Repository Combining Two/Multiple Repositories (OrderDocumentRepo)
Source: Dev.to
In this approach, you create an OrderDocumentRepo that combines both the OrderRepo and DocumentRepo into a single abstract repository, managing the transaction within this repository.
Pros
- Single Responsibility – Encapsulates the entire transaction logic related to both orders and documents within one repository, making it easy to manage.
- Consistency – Ensures that order and document operations are tightly coupled within the same transaction scope, reducing the risk of partial failures.
Cons
- Complexity – The repository handles more than one entity, potentially violating the Single Responsibility Principle.
- Tight Coupling – Couples
OrderRepoandDocumentRepo, making independent reuse or testing harder. - Scalability – Adding additional repositories to the transaction requires modifying
OrderDocumentRepo, reducing flexibility.
Best Practice
- Use this pattern when operations on orders and documents are always tied together and never operate independently.
- It is useful when you need to guarantee consistency between two closely related repositories where changes are always made in tandem.
Reference
Abstract Repository Combining Two/Multiple Repositories (OrderDocumentRepo)