|
Posted by FluffyCat on 01/15/06 06:06
On Sat, 14 Jan 2006 04:36:34 +0000 (UTC), Tim Van Wassenhove
<timvw@users.sourceforge.net> wrote:
>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 :)
That's an excellent point thanks!
I will add a note about that.
Navigation:
[Reply to this message]
|