Page 1 of 1

communication between classes ???

Posted: Sun Jun 01, 2008 12:55 am
by PHPycho
Hello forums!!
One thing always comes on my mind while coding in OOP is that 'communication between classes'
I am searching for a effective communication mechanism between different classes in a OOP sytem.

Cases:

Code: Select all

class A{
    //what should be the rule when it requires to communicate with B, C & D classes
 }
 
 class B{
    //what should be the rule when it requires to communicate with D classes
 }
 
 class C{
    // any other...
 }
 
 class D{
    // what should be the rule if it requires to communicate with C class
 }
Above is just the case of communication between different classes.

Can anybody point the good communication mechanism between different classes.

Thanks in advance for the valueable help.

Re: communication between classes ???

Posted: Sun Jun 01, 2008 4:07 am
by vargadanis
Hi!

What you a ask is not the simple. You could use global variables which are defined ourside the scope the the classes, cookies or sessions. These are quite easy to use.
You do have other options though. The extends is a good example for that.

Code: Select all

 
class A
{
  protected $var = 1;
  protected function fncA(){}
}
class be extends A
{
  $this->fncA(); // should work
}
This way u can access oll of your functions and variables from other classes but only from other classes. If you want to reach them from outside the class and subclass you need to set it public.
http://us.php.net/manual/en/language.oop5.abstract.php

Re: communication between classes ???

Posted: Sun Jun 01, 2008 5:06 am
by PHPycho
What about registry pattern for holding and using objects in this case ?

Re: communication between classes ???

Posted: Sun Jun 01, 2008 6:08 am
by vargadanis
It might be only me but I do not quite understand what u mean by registry patter... Whats that?