This is a blog for me to keep my scripting notes in, if you like the code go ahead and copy it.
Saturday, August 17, 2013
Singleton vrs Dependency Injection.
I have been starting to nail down the framework for my game. I have been reviewing my php knowledge base, on how to solve global variable, and object issues. I have friends that have been using singleton classes, and I defiantly see where they are going with it. It is handy for making sure you only have one instance of the thing running around, especially if you are dealing with a single object such as a web user.
But I just don't feel it is the right solution for me. I think I am going to go more toward dependency injection at the bootstrap. My controller structure extends each other based on the page. So the sub page of a sub page will have been extended with each page all the way back to the main site controller. And any additional needed dependencies can be loaded for a new sub page controller. I can see going singleton if you have more then 1 controller object, which I have seen that approach before but it seemed cumbersome. I don't like cumbersome. I think it will be one controller that has been extended from the root, with dependency injection. Seems like it would be cleaner.
Subscribe to:
Comments (Atom)