Re: Assigning functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux