communication between classes ???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

communication between classes ???

Post 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.
User avatar
vargadanis
Forum Contributor
Posts: 158
Joined: Sun Jun 01, 2008 3:48 am
Contact:

Re: communication between classes ???

Post 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
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

Re: communication between classes ???

Post by PHPycho »

What about registry pattern for holding and using objects in this case ?
User avatar
vargadanis
Forum Contributor
Posts: 158
Joined: Sun Jun 01, 2008 3:48 am
Contact:

Re: communication between classes ???

Post by vargadanis »

It might be only me but I do not quite understand what u mean by registry patter... Whats that?
Post Reply