18.10.2014 Views

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Software</strong> design 21<br />

2.4 The class<br />

In object-<strong>oriented</strong> term<strong>in</strong>ology a class is used to describe all objects that share the same responsibilities and<br />

<strong>in</strong>ternal structure. A class is essentially the collective name for a group of like objects. For example, the follow<strong>in</strong>g<br />

objects all belong to the class car:<br />

Cor<strong>in</strong>na’s red car Mike’s silver car Paul’s blue car<br />

Although the objects differ <strong>in</strong> detail, they all have the same <strong>in</strong>ternal structure and responsibilities. Each object<br />

is an <strong>in</strong>stance of the class Car. The notation for a class is slightly different from that of an object. The UML<br />

notation for a class and an object are illustrated below:<br />

A class<br />

An object (an <strong>in</strong>stance of a class)<br />

Car<br />

Cor<strong>in</strong>na’s car<br />

Note:<br />

The name of the object is underl<strong>in</strong>ed.<br />

It is important to dist<strong>in</strong>guish between a class and an object. A very simple rule is that objects usually have a<br />

physical representation, whereas classes are an abstract concept.<br />

2.5 Methods and messages<br />

A method implements a responsibility for a class. For example, some of the responsibilities for the class Car are<br />

as follows.<br />

Responsibilities of the class Car<br />

• Start/stop eng<strong>in</strong>e<br />

• Go faster/slower<br />

• Turn left/right<br />

• Stop.<br />

An <strong>in</strong>stance of the class Car is an object. By send<strong>in</strong>g a message to the object a hidden method <strong>in</strong>side the<br />

object (a responsibility of the class Car) is <strong>in</strong>voked to process the message. For example, the driver of the car by<br />

press<strong>in</strong>g down on the accelerator, sends the message ‘go faster’. The implementation of this is for the eng<strong>in</strong>e<br />

control system to feed more petrol to the eng<strong>in</strong>e. Normally however, the details of this operation are not of<br />

concern to the driver of the car.<br />

2.6 Class objects<br />

We have looked at a car's shell as a conta<strong>in</strong>er for objects and can look at a laptop computer as a conta<strong>in</strong>er for<br />

several comput<strong>in</strong>g devices or objects. A laptop computer is composed of:<br />

• The shell of the laptop, that has external <strong>in</strong>terfaces of a keyboard, touch pad and display<br />

screen.<br />

• The local disk drive.<br />

• The network file system.<br />

• The CPU.<br />

• The sound and graphics chipset.<br />

© M A Smith - May not be reproduced without permission

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!