Saturday, March 20, 2010

Fundamentals of Objects and Classes

We move now from the conceptual picture of objects and classes to a discussion of
software classes and objects.4
Objects are closely related to classes. A class can contain variables and methods.
If an object is also a collection of variables and methods, how do they differ from
classes?

Objects and Classes
Objects
In object-oriented programming we create software objects that model real world objects.
Software objects are modeled after real-world objects in that they too have
state and behavior. A software object maintains its state in one or more variables. A
variable is an item of data named by an identifier. A software object implements its
behavior with methods. A method is a function associated with an object.
Definition: An object is a software bundle of variables and related methods.
An object is also known as an instance. An instance refers to a particular object.
For e.g. Karuna’s bicycle is an instance of a bicycle—It refers to a particular bicycle.
Sandile Zuma is an instance of a Student.
The variables of an object are formally known as instance variables because they
contain the state for a particular object or instance. In a running program, there
may be many instances of an object. For e.g. there may be many Student objects.
Each of these objects will have their own instance variables and each object may have
different values stored in their instance variables. For e.g. each Student object will
have a different number stored in its StudentNumber variable.

No comments:

Post a Comment