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.

11.5 Class–responsibility–collaborator cards 145<br />

We shall see how the game software can be considerably simplified by making use of<br />

inheritance.<br />

11.4 ● Using the library<br />

OOP is often called programming by extending the library because the libraries provided<br />

along with OO languages are so rich and so reusable. An organization will often<br />

also create its own library of classes that have been created in earlier projects. There are<br />

two distinct ways of using classes in a library:<br />

1. creating objects from classes in the library<br />

2. defining new classes by extending (inheriting from) classes in the library.<br />

For example, in designing the game program, we expect the library to provide<br />

classes that implement buttons and a panel – along with classes that support the event<br />

handling associated with these widgets. For example in the Java library we can use the<br />

Button class directly, by creating button objects as instances of the Button class:<br />

Button button = new Button("start");<br />

The Java library also provides classes and methods that display the graphical images that<br />

the program uses.<br />

Another way in which the library is commonly used is to <strong>for</strong>m new classes by<br />

inheritance.<br />

It is worthwhile looking in the library at the outset of design and then again at<br />

every stage of design, in case something useful can be incorporated into the design.<br />

This takes some self-discipline because it is tempting to write a method again, rather<br />

than develop an understanding of someone else’s code.<br />

11.5 ● Class–responsibility–collaborator cards<br />

Class–responsibility–collaborator (CRC) cards are a way of helping to carry out OOD.<br />

The technique uses ordinary index cards, made out of cardboard and widely available.<br />

Each card describes an individual class as shown by the example of the Alien class in<br />

Figure 11.3. The designer begins by writing the class name at the head of the card.<br />

Then one area lists the methods provided by the class (its responsibilities). For the class<br />

Alien, these are move, display, etc. A second area lists the classes that use this class<br />

and the classes that are used by this class (the collaborators). For the class Alien, there<br />

is only one, the library class Graphics that supports displaying graphical images.<br />

The cards representing the constituent classes are placed on a table. This way the<br />

cards can be moved around easily; their interrelationships can be visualized and adjusted<br />

as necessary.<br />

CRC cards offer advantages as compared with a software tool. They are cheap, readily<br />

available and portable. Several people can easily collaborate, standing round the

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

Saved successfully!

Ooh no, something went wrong!