Java Reference
In-Depth Information
In object-oriented programming, a computer program is conceptualized as a set of
objects that work together to accomplish a task. Each object is a separate part of the pro-
gram, interacting with the other parts in specific, highly controlled ways.
For a real-life example of object-oriented design, consider a stereo system. Most systems
are built by hooking together a bunch of different objects, which are more commonly
called components, such as the following:
Speaker components play midrange and high-frequency sounds.
n
Subwoofer components play low bass frequency sounds.
n
Tuner components receive radio broadcast signals.
n
CD player components read audio data from CDs.
n
These components are designed to interact with each other using standard input and out-
put connectors. Even if you bought the speakers, subwoofer, tuner, and CD player from
different companies, you can combine them to form a stereo system as long as they have
standard connectors.
Object-oriented programming works under the same principle: You put together a pro-
gram by combining newly created objects and existing objects in standard ways. Each
object serves a specific role in the overall program.
An object is a self-contained element of a computer program that represents a related
group of features and is designed to accomplish specific tasks.
Objects and Classes
Object-oriented programming is modeled on the observation that in the physical world,
objects are made up of many kinds of smaller objects.
However, the capability to combine objects is only one aspect of object-oriented pro-
gramming. Another important feature is the use of classes.
A class is a template used to create an object. Every object created from the same class
has similar features.
Classes embody all features of a particular set of objects. When you write a program in
an object-oriented language, you don't define individual objects. Instead, you define
classes used to create those objects.
For example, you could create a Modem class that describes the features of all computer
modems. Most modems have the following common features:
 
Search WWH ::




Custom Search