Is it okay to design a purely managerial class (not meant to be instantiated,) and use all static methods?
Inside a container object, I have created a class Factory
, that is responsible for assembling 2 different types of arrays: one that contains multiple foo
objects, and the other that contains multiple bar
objects.
I was planning to call them like:
$this->foos = Factory::assemble_foos()
.
$this->bars = Factory::assemble_bars()
.
The Factory
would also theoretically be called to update/delete explicitly declared objects/attributes, as such:
eg. Facto开发者_开发技巧ry::destroy_bar( $bar_id )
eg. Factory::update_foo( $foo_id, $attr, $val )
But I'm fairly new to OOP and PHP, and am curious about my approach--I realized that the Factory
class is purely managerial, and that it's never meant to be instantiated (or at least never instantiated more than once.)
Is there something 'bad practice' about this approach of having a class that's exclusively static methods, and maybe some static attributes? Should I be re-working my code so that my container object instantiates a Factory
, and make my methods instance methods?
Thanks
That is a common practice in PHP, it allows you to faux namespace functions.
One thing you may want to do is make __construct()
private so it can't ever be instantiated.
精彩评论