Objects from Classes

A very important concept in Object Analysis and Design (OOAD) and OO programming is the relationship between a class and an object.  One can be defined in terms of the other.

Object

An object represents an entity.  An entity is a ‘thing’ from the real world such, as a Car or a Person, or a Theatre seat booking.

An object is an instance of a class.  Several different objects of the same type (e.g. several Car objects) can be created (instantiated) from the same class.

An object has attributes.  Attributes are characteristics of an object, in other words they describe an object.  For example a Car object has the attributes Make, Model, Colour and Price.  Attributes are also known as properties or fields.

An objects has methods.  Methods are actions that can be performed on (or by) an object.  For example a Car object may have an Update Price method.  Methods are also known as operations or behaviours.

The public methods and properties of an object are collectively known as its public interface.

Class

A class is the source code that defines an object.  Specifically, a class defines the properties (fields) and methods (behaviours) of an object.

A class can be thought of as a template for creating objects.  You may hear a class described as a ‘cookie cutter’.

cookie_cutter2

A class is an abstract data type.  A class definition is a kind of data type definition.  For example, if you have written a Car class, you can declare multiple variables of type Car as follows:

Dim car1 As Car
Dim car2 As Car
Dim car3 As Car

You can then create multiple Car objects (multiple instances of the Car class) as follows:

car1 = New Car
car2 = New Car
car3 = New Car

Object state

Each object created from the same class can store its own set of property values (field values).

The property values of an object are collectively know as the state of the object.