>
> <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>> Yeah that's the same way that I implement it. You're still using
>> strings
>> for referencing class names.
>
> So what? Is there an alternative method? Does it have any advantages?
Yes! Moving the singleton functionality into core php. Its an excellent
OOP feature.
>
>> Sorry my file didn't get attached when sent to the list.
>> http://hlrally.net/media/singletonabc.inc
>>
>> The advantages are:
>> - Speed improvements
>
> Where is your proof?
Think about it. You won't be calling upon php code every time you want
just to return an instance of a class. I'm sure APC (and others) could
run the usage code faster because they are given the ability to store a
class name rather than strings.
>
>> - Allows for context sensitive code hinting in IDEs
>
> How is this of benefit?
... ! ... you must use a text editor such as vi or notepad... (not that
theres anything wrong with that)
>
>> - Simplicity
>
> I disagree. My method is simpler and more intuitive than yours, and does
> not
> need any changes in core PHP.
The only difference between my method
(http://hlrally.net/media/singletonabc.inc) and yours is that
- You have a local static variable for your table of instances
- You dont inherit from the singleton class
- You dont enforce a protected constructor (so multiple instances could be
created by noobs)
- You have some lame hack to translate the names of 3 of your classes to
files
- You allow for an argument to be passed to your constructor (usually
considered bad practise with singletons anyway)
When I said simplicity, I was meaning using the native singleton method,
its easy for the programmer. They dont need to write their own singleton
management class (or research them on tutorial sites). And the usage
(accessing the singleton) can be made simpler as well.
>
>> - Encourages good coding practices for amateur programmers
>
> I disagree. What is "good" to you is "not good" to others. There is more
> than one way of implementing the singleton pattern, (or any design pattern
> for that matter) so trying to enforce one particular method is just too
> short sighted for my taste.
You can always still implement the variations using php. All Im proposing
is a simple mechanism for implementing single instance classes. I think
everyone needs to use this.
>
> --
> Tony Marston
> http://www.tonymarston.net
> http://www.radicore.org
>
>>
>> -Original Message-
>> From: Tony Marston [mailto:[EMAIL PROTECTED]
>> Sent: Saturday, 10 March 2007 9:55 PM
>> To: internals@lists.php.net
>> Subject: Re: [PHP-DEV] Native Singleton Implementation
>>
>>
>> <[EMAIL PROTECTED]> wrote in message
>> news:[EMAIL PROTECTED]
>>> Hi Tony,
>>>
>>> I do have a single singleton class to deal with singletons (as you put
>>> it).
>>> I have attached it to this email for your reference.
>>>
>>> But it's back to my original problem where you either have to:
>>> - Duplicate code for each singleton class ... or ...
>>> - Reference your classes via strings (slower, stops code hinting from
>>> working etc)
>>
>> I see no such problem with my implementation of a single class for
>> singletons.
>>
>>> I use method two as you do and it is not nice. There is no nice way of
>>> implementing singleton in php.
>>
>> I disagree. Take a look at
>> http://www.tonymarston.net/php-mysql/singleton.html#global.helper.with.loade
>> r
>>
>>> Have a full read of
>>> http://bugs.php.net/bug.php?id=39946
>>>
>>> Also, with three tiered architecture, there is even more reason to use
>>> singleton. You have yet another layer, filled with classes that need
>>> only
>>> be
>>> instantiated once. I think as a developer that uses tiered
>>> architecture,
>>> you would benefit greatly from this feature.
>>
>> I already have a more-than-adequate method of dealing with singletons
>> (see
>> http://www.tonymarston.net/php-mysql/singleton.html#global.helper.with.loade
>> r)
>> and I see absolutely no advantage in the method which you propose.
>> Putting
>> this into core PHP would be of no benefit to anyone.
>>
>> --
>> Tony Marston
>> http://www.tonymarston.net
>> http://www.radicore.org
>>
>>> Scott
>>>
>>> -Original Message-
>>> From: Tony Marston [mailto:[EMAIL PROTECTED]
>>> Sent: Friday, 9 March 2007 11:39 PM
>>> To: internals@lists.php.net
>>> Subject: Re: [PHP-DEV] Native Singleton Implementation
>>>
>>>
>>> <[EMAIL PROTECTED]> wrote in message
>>> news:[EMAIL PROTECTED]
Hi Greg,
There is no reason why you can't still use the current method to
implement
your variations to the singleton design pattern. But, yes, I am
proposing
that the strict "text book" variety is implemented.
>>>
>>> There is no strict "text book" implementation of the singleton pattern.
>>> There are different implementations in different languages, so it is
>>> not
>>> possible to decide that one implementation is "pure" while all the
>>> others
>>> are "impure". My pe