Lecture Notes on Object-Oriented Programming

OO Class Relationships

This collection of notes on OOP was never meant to stand alone. It also represents a view of OO circa early to mid 1990s. Some people still find them useful, so here they are, caveat emptor. Special thanks to Gilbert Benabou for taking to time to compile the first printable version of this document and inspiring us to provide it.

[ PDF ] Printable Version

Table of Contents
  1. Introduction: Motivation for OO
  2. The OO Paradigm
  3. Visualizing Program Execution
  4. Naming Conventions
  5. The Object Model
  6. Abstraction and Identity
  7. Messaging
  8. Encapsulation & Modularity
  9. Hierarchy
  10. Object-Oriented Typing
  11. OO Concurrency & Persistence
  12. OO Development Process
  13. OO Analysis Techniques
  14. Pitfalls in OO Analysis
  15. UML Notation
  16. CRC Cards
  17. OO Class Relationships
  18. Object Oriented Aggregation
  19. Object Oriented Interitance
  20. Other Object Oriented Class Relationships
  21. Object Oriented Instantiation
  22. Object Oriented Polymorphism
  23. Review of OO Programming
  24. The Quality of Classes and OO Design

We're going to look at the way we define the relationships between classes so we know how objects can relate to each other.

Consider the differences and similarities between the classes of the following objects: pets, cats, siberian huskies, poodles, tails, owners.

We see the following relationships:

  • a cat is a kind of pet
  • a dog is a (different) kind of pet
  • Siberian huskies and poodles are both kinds of dogs
  • a tail is a part of both dogs and cats
  • owners feed pets, pets please owners
  • owners use money to register pets

Depending on which book you read, or which tool you use, there are at least the following sorts of relationships between classes:

  • aggregation
  • inheritance
  • using
  • association
  • instantiation

The first two are the most essential to OO design. Interestingly they are also sometimes equally valid design alternatives to solve a given problem.

Inheritance is the most distinctively OO form of relationship, but not necessarily the most important, and certainly not always the right choice.

Class relationships are of course visible in source code, but can also be defined graphically with a modeling language such as UML.