April 2018
Intermediate to advanced
396 pages
11h 8m
English
In the previous section, we said that we don't want to use inheritance in order to get access to the Database methods. Why is that? If we had made Persister extend Database, this would mean that it would become a database itself (is-a relationship). However, this is not correct. It uses a database in order to achieve its functionality.
Inheritance exposes a subclass to the implementation details of its parent. This, however, is not always desired. According to the authors of Design Patterns: Elements of Reusable Object-Oriented Software, developers should favor object composition over class inheritance.
Read now
Unlock full access