Appearance
State & Behavior
An object has a state and behavior**.
INFO
The state of an object (a.k.a. its properties or attributes) are its essential and distinctive characteristics.
A class declares attributes of its objects through its data fields (instance variables). The state of an object is the value of those data fields at any point in time.
A Circle
class, for example, has a data field radius
, which is the property that characterizes a circle. A circle
object with a radius of 1
cm is an instance of the Circle
class. If we update the radius of this circle to a new value, we have changed its state.
INFO
The behavior of an object is the set of operations or responsibilities**, it must fulfill.
This includes the responsibility to provide and modify state information when asked by clients (other objects or services).
The behavior of an object is defined by the instance method that implements that behavior. To invoke a method on an object is to ask the object to fulfill a behavior (to act).
For example, you may ask a circle
object to provide you with its state by invoking the method getRadius()
which is declared and implemented in the Circle
class.