Three Purposes Of Inheritance


Introduction

Inheritance is a powerful object-oriented programming feature provided by the Java programming language. The behavior provided by or specified by one class (base class) can be adopted or extended by another class (derived or subclass). Up to this point you have been using inheritance in every Java program you have written although mostly this has been done for you by the Java compiler and platform behind the scenes. For example, every user-defined class you create automatically inherits from the java.lang.Object class. (See chapter 8, figure 8-3 or chapter 9, figure 9-2)

In this chapter you will learn how to create new derived classes from existing classes and interfaces. There are three ways of doing this: 1) by extending the functionality of an existing class, 2) by implementing one or more interfaces, or 3) you can combine these two methods to create derived classes that both extend the functionality of a base class and implement the operations declared in one or more interfaces.

Along the way I will show you how to create and use abstract methods to create abstract classes. You will learn how to create and utilize interfaces in your program designs as well as how to employ the final keyword to inhibit the inheritance mechanism. You will also learn how to use a UML class diagram to show inheritance hierarchies.

By the time you complete this chapter you will fully understand how to create an object-oriented Java program that exhibits dynamic polymorphic behavior. Most importantly, however, you will understand why dynamic polymorphic behavior is the desired end-state of an object-oriented program.

This chapter also builds on the material presented in chapter 10 - Compositional Design. The primary chapter example demonstrates the design possibilities you can achieve when you combine inheritance with compositional design.




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net