Operation/Method

If a change is necessary we can alter an attributes state. The process of making a change to a state is called an operation. The term 'Method' is sometimes used instead of operation. In this example an operation could be to add another carriage to the train. This would change the state of the 'Carriages' attribute to 7.

In computing an example of an object could be a line drawn in a vector graphics package.

An image of a line drawn in a vector package with the attributes and states listed underneath

If an operation was carried out to change the line colour to black then the state of the line colour attribute would change from blue to black.

Class, Sub Class, Super Class, and Instance

The term class is used to describe a group of objects that will have some common characteristics. In the example of 2-D vector graphics there would be a class called 'Shape'. Each type of shape within the class is known as a sub class.

In this example 'Shape' is a super class, meaning that there are a large number of different sub classes that could be thought of as shapes. As well as super classes and sub classes, there are also instances shown. An instance is a single member of a sub class.

In the example shown, the triangle subclass has two instances, equilateral and isosceles.

Object Oriented Class structure showing Super Class, Sub class and instances of an object

Operations/Methods are defined as part of a class and are then available to every object created within a class. There may be an operation that is created to allow the colour of a shape to be altered. In this case, the operation could be defined as part of the shape class and would then be available to each sub class and instance.

Inheritance

Inheritance is an excellent feature of object-oriented programming languages. Inheritance means that a subclass will inherit the characteristics of the superclass, similarly an instance will inherit the characteristics of a sub class.

In essence this means that we could define attributes and operations for the super class shape. Each time a sub class is created it will automatically inherit the attributes and operations of shape. The programmer only needs to add attributes and operations that make that subclass unique.

If line thickness were regarded as an attribute of a shape then each time a new sub class was created it would automatically contain an attribute for line thickness. This makes it much easier to make changes to objects as a change to the characteristics of a superclass will be reflected in the same change being made in each subclass and instance.

Inheritance allows for the re-use of the same code when creating a subclass or instance, such code can be contained within a class library, further reducing implementation time.

Move on to Test
next