October 2002
Intermediate to advanced
288 pages
5h 4m
English
Inheritance is often misused—the “inheritance is good, therefore, the more I use the better my code will be” syndrome. This is not true—in fact, the misuse of inheritance can lead to problems. For example, a student may be full time or part time. A Student superclass with two subclasses—FulltimeStudent and ParttimeStudent—could be created. Multiple problems can arise with this structure. What happens if:
A full-time student decides to go to school only part time? This implies that an object would have to change its class.
Another dimension is added (e.g., on scholarship or not on scholarship)? Here you would have to add additional subclasses to model the scholarship information along with multiple inheritance to ...