I have a "conceptual" question about front controller implementation in php.
Most of the front controllers that I have seen are implemented using Singleton, I'm not a big fan of the singleton template, and I created a container that has a static property that will store a single instance of Front Controller.
In singleton, I had to put the initialization code inside the constructor (or the method called by the constructor):
$fc = FrontController::getInstance();
With the container, I could set the configuration outside of FrontController, that was my goal, and I still have an easy way to get FrontController.
$fc = Container->getFrontController();
This code looks a lot cleaner to me, and I can get a pure subclassing without worrying about parent constructors.
This is exactly the same when loading, but in practice the difference in my previous implementation is that now I can create FrontControllers anywhere in the application (inside the DAO or inside the Action), because the constructor is no longer private / protected.
My question is, βBad practiceβ gives the user of my classes the ability to instantiate FrontController anywhere in the application? I would write documentation and deliver the container to other classes, but I'm still wondering if I should prohibit strange use.
source share