Grokking the Object Oriented Design Interview
Vote

0% completed

Choosing the Relationship Between Two Classes

You have twelve classes. Now you have to say how each pair connects, and there are only four answers worth knowing.

A relationship is a claim about lifetime and about substitution. Getting it wrong is the fastest way to lose credit in this round. It is visible in the diagram without reading a line of code.

This lesson gives you a decision you can make in about ten seconds per pair.

The four relationships

Association. One class holds a reference to another and can call it. Nothing is owned. A ParkingTicket refers to a ParkingSpot. Destroy the ticket and the spot is still there

.....

.....

.....

Like the course? Get enrolled and start learning!