Java Reference
In-Depth Information
Improving structure with inheritance
Main concepts discussed in this chapter:
polymorphic variables
Java constructs discussed in this chapter:
extends , super (in constructor), cast, Object , autoboxing, wrapper classes
In this chapter, we introduce some additional object-oriented constructs to improve the general
structure of our applications. The main concepts we shall use to design better program struc-
tures are inheritance and polymorphism .
Both of these concepts are central to the idea of object orientation, and you will discover later
how they appear in various forms in everything we discuss from now on. However, it is not
only the following chapters that rely heavily on these concepts. Many of the constructs and
techniques discussed in earlier chapters are influenced by aspects of inheritance and polymor-
phism, and we shall revisit some issues introduced earlier and gain a fuller understanding of the
interconnections between different parts of the Java language.
Inheritance is a powerful construct that can be used to create solutions to a variety of different
problems. As always, we will discuss the important aspects using an example. In this example,
we will first introduce only some of the problems that are addressed by using inheritance struc-
tures and discuss further uses and advantages of inheritance and polymorphism as we progress
through this chapter.
The example we discuss to introduce these new structures is called network .
The network example
The network project implements a prototype of a small part of a social-network application like
Facebook or Google+. The part we are concentrating on is the news feed —the list of messages
that should appear on screen when a user opens the network's main page.
Search WWH ::

Custom Search