OOP: Class Relationships

Please see my other Object-Oriented Programming (OOP) articles.

Modeling Real-World Objects through Relationship

As demonstrated by my Object-Oriented Programming (OOP) articles, OOP provide several mechanisms for code reuse, such as class inheritance.

These mechanisms work by relationships which may exist between classes.

Is-A Relationship (Inheritance)

Inheritance demonstrates the first type of relationship – is-a, where one class (Supervisor) “is-a” type of another class (Employee), and therefore inherits from that class.

Has-A Relationship

Composition demonstrates another type of inheritance with a different type of relationship.
For example, each employee has a family.
Since the relationship between family and employee does not constitute an “is-a” type of relationship – a family is not a type of an employee, but an employee “has-a” family (optionally), the Employee class “has-a” Family class.

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 )

Connecting to %s