State Identity and Behaviour of Objects
State Identity and Behaviour of Objects
objects
Sem III
K.I.R.A.S
What is an Object?
“An object has state, behavior, and
identity; the structure and behavior of
similar objects are defined in their
common class.”
Some things are not objects, but are
attributes; e.g. age, color.
Attributes may be properties of some object.
What is an Object
State
The state of an object consists of a set of
data fields (its properties) with their current
values.
The state represents the cumulative results of
an object’s behavior.
A property is an inherent characteristic,
trait, or quality that distinguishes one kind
of object from another (i.e. its class).
The properties in a class are usually static.
State
All properties have some value.
May be a simple quantity.
E.g. a person’s net worth is Rs 25000.
Values are usually dynamic.
E.g. a person’s net worth may go up or down.
Occasionally a value is static.
E.g. a car’s serial number.
The state of an object changes in
response to events (i.e. a message sent to
it), or by acting autonomously.
Behavior
“Behavior is how an object acts and reacts in terms
of its state changes and message passing.”
When you send a message to an object, you
actually invoke a method (i.e. execute some code).
Invoking a method will cause certain well-defined
behavior, and may change the object’s state.
The behavior may depend on the object’s current state
Behavior