I am working on a project implemented in DDD style, and I use Repository
architecture pattern to persist domain changes. I have multiple roles in domain layer, and that's what raises my question - how should my Repository
handle this? Three solutions come to my mind:
Separate
Repositories
for separate objects - (probably) the easiest one, but code might quickly turn into a mess;Improvement over (1) - use
Factory
pattern to create specific type ofRepository
;Keep a single
Repository
, but make it behave differently for different types of input (e.g. utilizeStrategy
pattern).
Is there any better way to handle this problem?
Some project information that might be useful:
- Project is made with mostly Python;
- There are not that many entities in domain - approx. 10;
- Service layer is decoupled from database layer through Unit of Work pattern