An Object-Oriented Class

If we think of a real-world object, such as a television (as in Figure 1.1, “The concept of a class - television example.”), it will have several features and properties:

In many ways this compares very well to the notion of a class.

Figure 1.1. The concept of a class - television example.

The concept of a class - television example.

A class should:

With a functional programming language (like C) we would have the component parts of the television scattered everywhere and we would be responsible for making them work correctly - there would be no case surrounding the electronic components.

Humans use class based descriptions all the time - what is a duck? (Think about this, we will discuss it soon.)

Classes allow us a way to represent complex structures within a programming language. They have two components:

The notation used in Figure 1.2, “The Television class example.” on the right hand side is a Unified Modelling Language (UML) representation of the Television class for object-oriented modelling and programming.

Figure 1.2. The Television class example.

The Television class example.

An instance of a class is called an object.