Object Oriented Programming Concepts #1: Classes/Types and Objects/Instances

Posted on December 29, 2011 in Object Oriented Programming Concepts by Michael

In object oriented programming, we deal with classes (sometimes called types) and objects.

A type/class can be thought of as a blueprint for a building.  It contains all the information needed to create an actual building and defines what will be in the building (windows, bedrooms, etc) and what operations can take place in the building (opening a door, turning on a heater, etc).

If a type is like a blueprint, then an object is an actual building created from the specifications of the blueprint.  In most cases, we can think of types and objects as having a one-to-many relationship, where one type can be used to generate multiple objects.  Each time an object is created from a type, it is called an instance of the type/class from which it was created.

Every created object contains the properties (also called attributes) and methods (also called operations) that are defined in the type.  Going back to our blueprint/building analogy, attributes are what is the house is made from (doors, windows, walls) whereas methods are what things can be done in the house (opening a door, turning on a heater, etc).