Object is a component of the program which knows how to carry out
some actions and interact with other pieces of a code.
A D V E R T I S E M E N T
Functions which
previously have been described as the "black boxes" takes the input and spit out the output.
An objects can be thought as a "smart" black boxes. which know how to do
more than one specific action, and also they can store own set of data. Designing the
program with an object allows the programmer to model a program after a real world.
Player Object:
data:
health
strength
ability
actions:
move
attack monster
get treasure
END;
Here is a "Player" object. This object have attributes healthh, strength and ability.
These attributes in terms of Programming language are called as data members.
The various actions that a player oject can perform are move, attakMonster and getTreasure,
These actions are called memeber Functions.
Objects and the Instances
There is a distinction between object and the instance of an object.
Object is the definition or a template for its instances. And
instance is the actual thing which can be manipulated. For example we have one
instance of the player object with certain values:
Player Instance #1:
data:
health = 16
strength = 12
ability = 14
END;
Here is one instace of the object "Player" with the values for health, strength and
ability as 16, 12 and 14 respectively.