Dive Deep into CPP: Types of collaboration between classes

Auto
Message to self.Calling m1 from m2 where they are the methods of the same class. Preferred relationship is “has-a “.We will be using “this” keyword for invocation. Which means compiler already created an object of the same class within itself.

Base derived
We can call the method of base class from derived using “super” or “base” keywords which are the objects of base and it is created within the derived class. So we use “is-a” relation but it is implemented through “has-a” relation. But if there is no “is-a” relation between the base and derived class, then those objects won’t be created. So its an equalizer

Sibling
Accessing from sibling class. Preferred relation  is “has-a”.

Peer to peer
Preferred relationship is “has-a ”

So,
Generalization is having both the interface(type contracts etc) and the implementation of the base class.
Realization is having only the interface of the base class and creating their own implementation for the methods in the base class.
In “has-a” relationship, we can use only the  implementation of the class, but not its interface.
Finally, we can say  generalization =realization +has a
So generalization which is tightly coupled can be replaced with realization and association relationships which will make the classes loosely coupled.This will give the flexibility we need and will give us a good clean design .

Advertisements

One thought on “Dive Deep into CPP: Types of collaboration between classes

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s