Reply to Re: PHP, OOP, and Constants

Your name:

Reply:


Posted by Willem Bogaerts on 12/18/07 15:55

> Hi. If somebody can help out with this design question, thank you very
> much. Suppose I have a global constant, like an images directory. This
> constant will be referenced from multiple classes. How do I define
> this constant only once while using OOP? I could define the constant
> on one of the classes and then reference it with ClassName::const from
> the other classes, but this ties the constants to one class
> arbitrarily. In Java you can define constants in an interface, and any
> class implementing the interface automatically inherits the constants.

So let's face it, your classes will be tied to the environment of the
constants anyway, just as in java. If you have any "central" ojbect that
is visible throughout your code (an Application object, for instance),
you could consider putting them there.

It is not nice OO-programming, but personally I have some classes that
"magically" incorporate some settings (from the $GLOBALS array), such as
a ConfiguredMailer which is just a PHPMailer that sets its own from
address, encoding, mailer type, etc.

In other languages, I used to have a Settings object that was a wrapper
around INI files, registry settings, command-line parameters, etc.

Regards,
--
Willem Bogaerts

Application smith
Kratz B.V.
http://www.kratz.nl/

[Back to original 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

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