ptg7068951
WHAT YOU’LL LEARN IN
THIS HOUR:
.Creating an object
.Describing an object with
attributes
.Determining how objects
behave
.Combining objects
.Inheriting from other
objects
.Converting objects and
other types of information
One of the more fearsome examples of jargon that you encounter during
these 24 hours is object-oriented programming(OOP).This complicated term
describes, in an elegant way, what a computer program is and how it
works.
Before OOP, a computer program was usually described under the sim-
plest definition you’ve learned in this book: a set of instructions listed in a
file and handled in some kind of reliable order.
By thinking of a program as a collection of objects, you can figure out the
tasks a program must accomplish and assign the tasks to the objects where
they best belong.
How Object-Oriented Programming
Works
You can think of the Java programs you create as objects, just like physical
objects that exist in the real world. Objects exist independently of other
objects, interact in specific ways, and can be combined with other objects to
form something bigger. If you think of a computer program as a group of
objects that interact with each other, you can design a program that’s more
reliable, easier to understand, and reusable in other projects.
In Hour 23, “Creating Java2D Graphics,” you create a Java program that
displays pie graphs—circles with different-colored pie slices to represent
data (see Figure 10.1). Apie chartis an object that is made up of smaller
objects—individual slices of different colors, a legend identifying what
each slice represents, and a title.
HOUR 10
Creating Your First Object