Everywhere you look in the real world you see objects—people, animals, plants, cars, planes,
buildings, computers and so on. Humans think in terms of objects. Telephones, houses, traffic
lights, microwave ovens and water coolers are just a few more objects. Computer programs, such
as the Java programs you’ll read in this book and the ones you’ll write, are composed of lots of
interacting software objects.
We sometimes divide objects into two categories: animate and inanimate. Animate objects
are ―alive‖ in some sense—they move around and do things. Inanimate objects, on the other
hand, do not move on their own .Objects of both types, however, have some things in common.
They all have attributes (e.g., size, shape, color and weight), and they all exhibit behaviors (e.g.,
a ball rolls, bounces, inflates and deflates; a baby cries, sleep crawls, walks and blinks; a car
accelerates, brakes and turns; a towel absorbs water). We will study the kinds of attributes and
behaviors that software objects have. Humans learn about existing objects by studying their
attributes and observing their behaviors. Different objects can have similar attributes and can
exhibit similar behaviors. Comparisons can be made, for example, between babies and adults and
between humans and chimpanzees. Object-oriented design provides a natural and intuitive way
to view the software design process—namely, modeling objects by their attributes and
behaviors just as we describe real-world objects. OOD also models communication between
objects. Just as people send messages to one another (e.g., a sergeant commands a soldier to
stand at attention), objects also communicate via messages. A bank account object may receive a
message to decrease its balance by a certain amount because the customer has withdrawn that
amount of money.
Although influenced by its predecessors, Java was not designed to be source-code compatible
with any other language. This allowed the Java team the freedom to design with a blank slate.
One outcome of this was a clean, usable, pragmatic approach to objects. Borrowing liberally
from many seminal object-software environments of the last few decades, Java manages to strike
a balance between the purist’s ―everything is an object‖ paradigm and the pragmatist’s ―stay out
of my way‖ model. The object model in Java is simple and easy to extend, while simple types,
such as integers, are kept as high-performance nonobjects.
OOD encapsulates (i.e., wraps) attributes and operations (behaviors) into objects, an
object’s attributes and operations are intimately tied together. Objects have the property of
information hiding. This means that objects may know how to communicate with one another
across well-defined interfaces, but normally they are not allowed to know how other objects
are implemented ,implementation details are hidden within the objects themselves. We
can drive a car effectively, for instance, without knowing the details of how engines,
transmissions, brakes and exhaust systems work internally—as long as we know how to use the
accelerator pedal, the brake pedal, the wheel and so on. Information hiding, as we will see, is
crucial to good software engineering.