DEV Community

Discussion on: Domain-Driven Design - The Factory in PHP

Collapse
 
coajaxial profile image
Fluttershy

You are absolutely right! It actually depends what you are constructing. Sometimes it's not that simple like in this example, sometimes you may have multiple dependencies that you need to create a class, that's where a own dedicated factory may be more maintainable than passing multiple dependencies to your constructor/factory method. Also, dependency injection is way easier if you have a dedicated factory class :)