In the base class for all models of our MVC system, I created the factory method BaseCLass :: getNew (), which returns an instance of the requested child class when called through SomeChildClass :: getNew ().
Now I'm looking for a way to get a programmer to use this factory. Ie, idally, I would like any class to be created directly, for example:
new SomeChildClass
throws an exception on creation, and only classes created by the factory will be used.
Any ideas how this can be achieved?
Our code is written in PHP, but a good chance your idea will be valuable even if you think in another language.
edit: I cannot make my constructor private, as the framework constructor in the class I inherit from is public, and php will not allow me this.
source
share