|
Posted by Thomas Mlynarczyk on 11/18/05 23:58
Also sprach Dikkie Dik:
[Using a class without instantiation]
> It is good practice if the instance would have no state. You'd only
> have functions then. The standard example is the Math class in Java
> and JavaScript, which is a collection of mathematical functions.
> If the object has a state, it is better to use an instance of a class.
Why would it be bad practise with a state? I mean, data structure,
encapsulation etc. is done as well as with an instance. Where's the drawback
then? Certainly, one may argue that in the future the need for having
several instances may arise, but assuming that I can definitely exclude such
a possibility in a given situation?
> I don't like it, but if you want to _enforce_ the fact that there is
> only one instance, google for "singleton pattern".
I've read about it in the PHP manual. But if the class itself is able to
provide the same functionality that an instance would, why bother with even
one single instance?
Greetings,
Thomas
Navigation:
[Reply to this message]
|