Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach Software Engineering for Students A Programming Approach

web.firat.edu.tr
from web.firat.edu.tr More from this publisher
21.08.2013 Views

C.2 ● Class diagrams C.2 Class diagrams 413 These describe classes and their interrelationships. Classes are shown as rectangles containing the class name. The simplest relationship is where a class uses another. For example, in Figure C.2, class Game uses classes Defender, Alien, Laser and Bomb. This means that Game creates objects from these classes and/or calls methods in objects created from these classes. A class diagram can also show the inheritance relationships between classes – the subclasses and superclasses. As illustrated in Figure C.3, to show that a class extends another, a line is drawn from the subclass to the superclass, with the arrowhead pointing to the superclass. Thus Sprite is the superclass of both Alien and Bomb. If a class is an abstract class, the name of the class is written in italics. This can be difficult to see, particularly when hand-written. So the name of an abstract class can be followed by the text {abstract} to clarify the meaning. An interface is described in the same way as a class – as a box. The difference is that the text precedes the name. A class that implements an interface has a dashed line with an arrow leading to the interface box (see Figure C.4). A class can be described in more detail, as illustrated in Figure C.5. There are three compartments in this type of class diagram. The first compartment holds the class Figure C.2 Class diagram Game Figure C.3 Class diagram showing inheritance Sprite Defender Alien Laser Bomb Alien Bomb

414 Appendix C ■ UML summary name, the second describes variables and the third describes methods. Any class (static) variables or methods are shown underlined. The visibility of an element can, optionally, be described in a prefix as in Java – public, private, protected or default. In keeping with information hiding, the diagram is often drawn with the second compartment (the variables) omitted. C.3 ● Package diagrams A package can be diagrammed as shown in Figure C.6. It is a rectangle with a tab at the top that holds the package name. Optionally, the classes within a package can be shown within the rectangle. This shows a class util that consists of classes Random, ArrayList and Stack. C.4 ● Activity diagrams StackInterface Stack Figure C.4 A class and its interface. The arrow should be hollow Game panel timer mouseMoved mouseClicked actionPerformed Figure C.5 Class diagram showing the detail of a class An activity diagram describes a sequence of activities. Thus an activity diagram can be used to show the flow of control through software. An activity diagram can show: ■ conditions (corresponding to if statements) ■ loops (corresponding to for and while statements) ■ concurrent activity (corresponding to threads).

414 Appendix C ■ UML summary<br />

name, the second describes variables and the third describes methods. Any class (static)<br />

variables or methods are shown underlined. The visibility of an element can, optionally,<br />

be described in a prefix as in Java – public, private, protected or default.<br />

In keeping with in<strong>for</strong>mation hiding, the diagram is often drawn with the second<br />

compartment (the variables) omitted.<br />

C.3 ● Package diagrams<br />

A package can be diagrammed as shown in Figure C.6. It is a rectangle with a tab at<br />

the top that holds the package name. Optionally, the classes within a package can be<br />

shown within the rectangle. This shows a class util that consists of classes Random,<br />

ArrayList and Stack.<br />

C.4 ● Activity diagrams<br />

<br />

StackInterface<br />

Stack<br />

Figure C.4 A class and its interface. The arrow should be hollow<br />

Game<br />

panel<br />

timer<br />

mouseMoved<br />

mouseClicked<br />

actionPer<strong>for</strong>med<br />

Figure C.5 Class diagram showing the detail of a class<br />

An activity diagram describes a sequence of activities. Thus an activity diagram can be<br />

used to show the flow of control through software. An activity diagram can show:<br />

■ conditions (corresponding to if statements)<br />

■ loops (corresponding to <strong>for</strong> and while statements)<br />

■ concurrent activity (corresponding to threads).

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

Saved successfully!

Ooh no, something went wrong!