Next: Exercises
Up: Unit 08
Previous: Composition (optional)
Referring to the previous example, it is clear that realizing the class
Student2 instead of Student is a questionable choice. So,
when is it reasonable to use composition?
In general, we can adopt the following criteria:
- If each object of X is an object of Y
(X IS-A Y), then we use inheritance.
- If each object of Y has an object of X
(Y HAS-A X), then we use composition.
These aspects will be studied in later courses.
Next: Exercises
Up: Unit 08
Previous: Composition (optional)