21.08.2013 Views

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

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.

C.2 ● Class diagrams<br />

C.2 Class diagrams 413<br />

These describe classes and their interrelationships. Classes are shown as rectangles containing<br />

the class name. The simplest relationship is where a class uses another. For<br />

example, in Figure C.2, class Game uses classes Defender, Alien, Laser and Bomb.<br />

This means that Game creates objects from these classes and/or calls methods in objects<br />

created from these classes.<br />

A class diagram can also show the inheritance relationships between classes – the subclasses<br />

and superclasses. As illustrated in Figure C.3, to show that a class extends another,<br />

a line is drawn from the subclass to the superclass, with the arrowhead pointing to the<br />

superclass. Thus Sprite is the superclass of both Alien and Bomb.<br />

If a class is an abstract class, the name of the class is written in italics. This can be difficult<br />

to see, particularly when hand-written. So the name of an abstract class can be followed<br />

by the text {abstract} to clarify the meaning.<br />

An interface is described in the same way as a class – as a box. The difference is that<br />

the text precedes the name. A class that implements an interface has<br />

a dashed line with an arrow leading to the interface box (see Figure C.4).<br />

A class can be described in more detail, as illustrated in Figure C.5. There are three<br />

compartments in this type of class diagram. The first compartment holds the class<br />

Figure C.2 Class diagram<br />

Game<br />

Figure C.3 Class diagram showing inheritance<br />

Sprite<br />

Defender<br />

Alien<br />

Laser<br />

Bomb<br />

Alien Bomb

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

Saved successfully!

Ooh no, something went wrong!