O'Reilly logo

Visual Modeling with Rational Rose 2002 and UML by Terry Quatrani

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Inheritance Versus Aggregation

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required