You are here: Re: Classes without instances « PHP Programming Language « IT news, forums, messages
Re: Classes without instances

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация