C++

Thursday, 15 March 2012

Difference b/w Class & Object:

What Is the Difference Between a  Class and Object?

Edward Yourdan defines a class as, “A collection of one or more objects with a uniform set of attributes and services, including a description of how to create new objects in the class.

Grady Booch defines an object as, “An object has state, behavior, and identity; The structure and behavior of similar objects are defined in their common class; The terms instance and object are interchangeable.

From these two definitions we can see that there is a difference between a class and an object.  A class is the definition, or blueprint, for an object.  Classes don’t real ever exist, they are plans.  We use the class to create an object which has identity.  That is, an object exists, has values in its properties and can execute behaviors.

This difference between a class and an object is a subtle but very important one. It is analogous to visiting an architect to have a new house built.  The architect will draw up plans for the house that show all the rooms and elevations etc. However, you cannot move into the plans and live there.  The plans must be used to build a house.  The house is an object while the plans are a class.

No comments:

Post a Comment