The Java Course provides a general introduction to programming in Java. It is based on A.B. Downey's book, How to Think Like a Computer Scientist. Click here for details. |
Home Object-Oriented Programming Object-Oriented Design | ||
Search the VIAS Library | Index | ||
Object-Oriented Design
Inheritance is a powerful feature. Some programs that would be complicated without inheritance can be written concisely and simply with it. Also, inheritance can facilitate code reuse, since you can customize the behavior of build-in classes without having to modify them. On the other hand, inheritance can make programs difficult to read, since it is sometimes not clear, when a method is invoked, where to find the definition. For example, one of the methods you can invoke on a Slate is getBounds. Can you find the documentation for getBounds? It turns out that getBounds is defined in the parent of the parent of the parent of the parent of Slate. Also, many of the things that can be done using inheritance can be done almost as elegantly (or more so) without it.
|
||
Home Object-Oriented Programming Object-Oriented Design |