configuration: constants vs singleton pattern

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Why would a singleton be less evil in a c# or java environment anyway?

A singleton is only 'unique' in the current virtual machine that is executing the code...
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

adiian wrote:I think singleton is evil. From the oop perspective. Can not be derived and if you want just to replace the class you have to chanage all the references in the text.
http://www.oodesign.com/oo_design_patte ... leton.html

And php is not a language with a good support for oop and design patterns. I would go for the configuration file in php. Otherwise, if using something like java or c#, I would chose singleton.
a. Not entirely sure I agree with that statement. A Singleton by itself cannot be derived from, however you could also implement getInstance as a factory method, allowing classes to derive from the singleton...

b. What crummy argument. :P Sorry, but you provide no explanations to back why you feel PHP isn't a good OOP supported language...yes it has it's short falls, but OOP (IMHO) is more about paradigm & design choices than the compiler/interpreter specifics of each language (private, protected, public, const methods, etc)

You can utilize the concepts of OOP in assembler which historically has very few OOP constructs (depending on the assembler) and not much you can't work around anyways...

I disagree :)

Cheers :)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

adiian wrote:I think singleton is evil. From the oop perspective. Can not be derived and if you want just to replace the class you have to chanage all the references in the text.
http://www.oodesign.com/oo_design_patte ... leton.html

And php is not a language with a good support for oop and design patterns. I would go for the configuration file in php. Otherwise, if using something like java or c#, I would chose singleton.
If you think using the Singleton pattern is "evil" then why would you use it in Java or C# ? I agree with your opinion, but I wouldn't use it anywhere.

As for whether PHP has "good support for oop and design patterns", perhaps you could start a new thread with this thesis. If done in an informative way, rather than a flame-fest, I think it would be interesting to PHP programmers to know how the PHP implement compares to how things are done in Java or C#.
(#10850)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

This thread is almost 6 months old ;)
Locked