On Fri, May 2, 2008 at 2:03 PM, Craige Leeder <[EMAIL PROTECTED]> wrote:
> ons here) as a simple example something like this
> >
> > class B {
> > //...
> > function doSomething() {
> > return $this->c->doSomething();
> > }
> > }
> >
> > which allows you this in A instances
> >
> > $this->b->doSomething();
> >
> > this is the preferred approach, since A and C instances are loosely
> coupled.
> >
> > of course, if you wanted a to 'know' about c then you could do something
> > like this,
> >
> > class B {
> > // ..
> > function getC() {
> > return $this->c;
> > }
> > }
> >
> > giving you the ability to do this in A instances
> >
> > $this->b->getC()->doSomething();
> >
> > of course now A's knows about C's and your system is more tightly
> coupled.
> >
> > -nathan
> >
>
> Why don't you just do a registry pattern instance then? IE:
>
> class Registry
> {
> private satic objs;
>
> public function __construct()
> {
>
> self::$objs = function_get_args();
> }
>
> public static function __get($obj)
> {
> return self::$objs[$obj];
> }
> }
>
> class A
> {
> ...
> }
>
> class B
> {
> ...
> }
>
> $reg = new Registry( new A(), new B());
>
> Now A and B can access each other through Registry::A and Registry::B
>
> (that code may not function. It's just a general example)
that seems like overkill to me, and anyway, A instances need to get at C
instances.. the Registry would need to be globally available and even then,
if C's and A's could talk to each other through it, it still presents the
issue where A instances know about C instances. its a design decision to be
sure, but likely the cleanest solution will have A instances not knowing
about C instances.
-nathan