You are here: Re: Messaging between objects « All PHP « IT news, forums, messages
Re: Messaging between objects

Posted by Jerry Stuckle on 01/23/08 23:42

Chad Johnson wrote:
> Suppose we're using an object-oriented framework for our web site.
> We're obviously going to have a few common objects used throughout the
> framework, such as User and DB (or just a DB connection link). How
> would you go about making these objects available inside of the member
> functions of your classes? Would you encapsulate them some common
> object, like "Settings" or "Context"? Would you make these objects
> available inside member functions via "global $VARIABLE_NAME;"? Pass
> them individually or the Settings/Context object as a whole as a
> constructor parameter for every object in your framework?
>
> Surely someone else has faced this problem before...
>

Chad,

It all depends on what I need.

First of all, I don't encapsulate them in a pseudo-object. You
generally don't need all objects in all cases, so putting them all in a
single object just adds overhead.

I also don't use globals. It makes maintenance and troubleshooting harder.

Generally I will pass the objects in the constructor, a member function
or a setter function. For objects which are more global (i.e. a
database object which may be used by several classes) I might create a
singleton (google for it).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

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

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