Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DDD - How to implement factories [closed]

I would like to know how to implement factories in domain driven design. (examples)

Where should be placed interfaces and implementations of factories ? Do I need to create interfaces for Domain objects which factories creating ? Do I need to create factories for repositories, services, ...

I am using Dependency Injection Containers how can I put them together with factories ?

Thanks.

like image 579
user2149358 Avatar asked Mar 08 '13 17:03

user2149358


1 Answers

Factories should be simple classes, usually static. They can also be implemented as static methods on the entity or value object they create. Factories should create domain objects directly and only domain objects. Moreover, factories should not be tied with dependency injection because domain objects shouldn't have dependencies injected into them.

Domain objects should not implement interfaces - that is a needless abstraction.

Services and repository implementations on the other hand do have dependencies and should be created by the DI container.

like image 148
eulerfx Avatar answered Oct 05 '22 14:10

eulerfx