I l @ ve RuBoard |
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:
Inheritance should be used to separate commonality from specifics. Aggregation should be used to show composite relationships. Often the two types of relationships are used together. The Student class has a classification (aggregation) that is either Fulltime or Parttime (inheritance). This is shown in Figure 8-5. Figure 8-5. Inheritance versus Aggregation
|
I l @ ve RuBoard |