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
- Motivation for OO
- The OO Paradigm
- Visualizing Program Execution
- OO Naming Conventions
- The Object Model
- Abstraction and Identity
- Object-Oriented Messaging
- Encapsulation & Modularity
- Object-Oriented Hierarchy
- Object-Oriented Typing
- OO Concurrency & Persistence
- The OO Development Process
- OO Analysis Techniques
- Pitfalls in OO Analysis
- UML Notation
- CRC Cards
- OO Class Relationships
- Object Oriented Aggregation
- Object Oriented Interitance
- Other Object Oriented Class Relationships
- Object Oriented Instantiation
- Object Oriented Polymorphism
- Review of OO Programming
- 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:
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.