Re: Messaging between objects



On Jan 24, 8:07 am, ZeldorBlat <zeldorb...@xxxxxxxxx> wrote:
On Jan 23, 6:42 pm, Jerry Stuckle <jstuck...@xxxxxxxxxxxxx> wrote:



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).

--

I think singletons are the way to go here. I use them for the
database and session (and the session object has the user object) as
well as a few other things. For instance, whenever I need the
database I just do something like this:

$db = DB::get();

That can be called from anywhere so there's no need to pass it around
as a parameter or use a global.

This is what I went with: http://www.patternsforphp.com/wiki/Registry
.



Relevant Pages

  • Re: Messaging between objects
    ... We're obviously going to have a few common objects used throughout the ... framework, such as User and DB. ... I also don't use globals. ... database and session as ...
    (alt.php)
  • Re: limit of lines?
    ... > Agreed, but don't let database design influence OO design, the two are not ... My framework has several rules ... > Customer ID ...
    (borland.public.delphi.non-technical)
  • Re: Dabo in 30 seconds?
    ... >> You might want to look at Dabo, which is a database application ... >> framework for Python. ... The wizard isn't the only way to create Dabo apps, ... The framework then takes care of populating the controls with the ...
    (comp.lang.python)
  • hbm2delphi - database reverse engineering for the G framework
    ... hbm2delphi uses the "Hibernate tools" code generator to generate business domain class source code for the G framework. ... It also includes reverse database engineering support: hbm2delphi will generate the neccessary property datatypes and implementation code for one-to-many and many-to-one relationships if they are declared in the database metadata. ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: [PHP] Creating new site
    ... porting my stuff to the Zend Framework which makes MVC optional, ... with creating one bigger site which should be OOP. ... And users profile should show ads posted by himself. ... create database class which handles database connection ...
    (php.general)