You are here: Re: The Singleton Pattern in PHP 5 « PHP Programming Language « IT news, forums, messages
Re: The Singleton Pattern in PHP 5

Posted by Tim Van Wassenhove on 01/14/06 06:36

On 2006-01-14, Oli Filth <catch@olifilth.co.uk> wrote:
> FluffyCat said the following on 14/01/2006 00:20:
>> To add to my growing library of Design Patterns in PHP 5 I have
>> written what I think is a good example of the Singleton Pattern.
>>
>> http://www.fluffycat.com/PHP-Design-Patterns/Singleton/
>>
>
> Unfortunately, this is not a good example of a singleton system.
>
> You have a class (BookSingleton) with a public constructor, so there's
> nothing to stop someone creating multiple BookSingleton objects with
> multiple "new BookSingleton()" calls.
>
> To solve this problem, you need to make the constructor private, and the
> borrowBook() method static.

And make sure to throw an error when clone is called.. Because a singleton
shouldn't be cloned :)

--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be>

 

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

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