Java Objects

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值