Object-oriented Programming

Class

A class is a blueprint of an object, used to create the real versions (instances) of the object.

Property

A property is a piece of data which is defined in the class, which is used to create or instantiate actual objects. The properties or data items in a class definition are known as instance variables.

Method

A method defines the processing (functions) that will be applied to objects (instances of classes) that are created or instantiated from a class. Methods can be procedures or functions.

All properties in a class will usually have a getter and a setter method, these are methods which assign a value to the property and which read the current value of the property.

Constructor

There is also a constructor method which is automatically called when an object is instantiated based on the class. This constructor method is used to set up the initial values for properties and to carry out any processing required when the object is created.

The constructor only runs once when an object based on the class is created (instantiated).

A constructor method is usually the first method defined in a class and it has a special declaration.

Referring to properties within a method is done using the THIS. prefix. This will reference the properties defined within the class definition.

Instantiation

The process of creating an object from a class is called instantiation. An object is a real item rather than an abstract definition (a class).

When the object is instantiated from the class, it is given a unique name, declared with a set of properties (instance variables) and defined methods from the class. The constructor method is also executed.

Objects

An object is created when a class is instantiated. This process sets up the properties (instance variables) for the object, against the name used to create it, and runs the constructor method.