next up previous
Next: Exercises Up: Unit 03 Previous: Composition (optional)

Inheritance or 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:

These aspects will be studied in later courses.


next up previous
Next: Exercises Up: Unit 03 Previous: Composition (optional)