I try to use Injection Dependency as much as possible, but I have problems when it comes to things like short-lived dependencies.
For example, let's say I have a blog manager object that would like to create a list of blogs that it found in the database. Possible options (as far as I can tell):
- new blog ();
- $ this-> Loader-> blog ();
- The loader object creates various other types of objects, such as database objects, text filters, etc.
- $ this-> blogEntryFactory-> create ();
However, # 1 is bad because it creates a strong bond. # 2 still seems bad because it means the factory object must be pre-entered - expose all other objects that it can create.
The number 3 looks fine, but if I use # 3, I put the βnewβ keywords in blogEntryFactory itself, OR do I insert the loader into blogEntryFactory and use the loader?
If I have many different factories, such as blogEntryFactory (for example, I could have userFactory and commentFactory), it seems that adding the keyword βnewβ in all these different factories created dependency problems.
Hope this makes sense ...
Note
I had some answers about how this is not necessary for this particular example blog, but there are, in fact, cases where you should use the Abstract factory template, and this is the moment I get it. Are you using the βnewβ in this case, or are you doing something else?
php design-patterns dependency-injection abstract-factory
johnnietheblack
source share