Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

should a factory utilize another factory if the object to create needs another object?

If I have a factory that creates an object that needs an instance of another object should i use another factory responsible for this second's object creation or should the original factory handle this?

like image 224
tyrondis Avatar asked Sep 10 '25 23:09

tyrondis


1 Answers

As is the answer to most design question, it depends. If virtually any instance of the other object can be used to initialize the first object then probably yes. That will make them more independent, but your code will grow (usual tradeoff). On the other hand, if specific objects require specific other objects then this should be one factory (or an abstract factory)

like image 124
Armen Tsirunyan Avatar answered Sep 13 '25 00:09

Armen Tsirunyan