Objects
To work with OOP, you should be able to identify three key characteristics of objects:
• The object’s behavior—What can you do with this object, or what methods can you
apply to it?
• The object’s state—How does the object react when you apply those methods?
• The object’s identity—How is the object distinguished from others that may have the
same behavior and state?
All objects that are instances of the same class share a family resemblance by supporting
the same behavior. The behavior of an object is defined by the methods that you can call.
Next, each object stores information about what it currently looks like. This is the
object’s state. An object’s state may change over time, but not spontaneously. A change
in the state of an object must be a consequence of method calls. (If the object state
changed without a method call on that object, someone broke encapsulation.)
However, the state of an object does not completely describe it, because each object has a
distinct identity. For example, in an order-processing system, two orders are distinct
even if they request identical items. Notice that the individual objects that are instances
of a class always differ in their identity and usually differ in their state.
These key characteristics can influence each other. For example, the state of an object can
influence its behavior. (If an order is “shipped” or “paid,” it may reject a method call
that asks it to add or remove items. Conversely, if an order is “empty,” that is, no items
have yet been ordered, it should not allow itself to be shipped.)
------Core Java. Volume I, Fundamentals/ Cay S. Horstmann, Gary Cornell. —8th ed.
page 108