29.11.2014 Views

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

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.

people considered it suitable for constructing industrial strength systems in. The reasons for this have<br />

already been considered in the introductory chapters of this book.<br />

As t he types of systems being constructed were experimental, the tools available made code<br />

debugging easy <strong><strong>an</strong>d</strong> could be done even when the implemented system was executing. This led m<strong>an</strong>y<br />

people to design the overall system, roughly specify the components, imple ment them <strong><strong>an</strong>d</strong> test the<br />

resulting system (not the components) using the user interface. If the system failed (at <strong>an</strong>y time<br />

including once development was complete) then a quick fix could sort out the problem. This approach<br />

c<strong>an</strong> work well for a single develope r-user, non critical, application where the majority of the system is<br />

the user interface. However, for serious development this approach is inappropriate.<br />

<strong>Smalltalk</strong> applications require testing just as <strong>an</strong>y other software requires testing. Indeed the type o f<br />

testing normally applied to traditional programming l<strong>an</strong>guages is also required by object oriented<br />

systems. However, object orientation imposes unique requirements on the testing process. Why these<br />

requirements exist <strong><strong>an</strong>d</strong> how they c<strong>an</strong> be h<strong><strong>an</strong>d</strong>led is the subject of the remainder of this chapter.<br />

22.3 Inherit<strong>an</strong>ce<br />

Inherit<strong>an</strong>ce is a fundamental feature of object oriented programming l<strong>an</strong>guages. However, it is both a<br />

blessing <strong><strong>an</strong>d</strong> a curse. For example, m<strong>an</strong>y programmers believe that they c<strong>an</strong> inherit m<strong>an</strong>y of the features<br />

they require in their new classes from existing classes (<strong><strong>an</strong>d</strong> often they c<strong>an</strong>). However, they also tend to<br />

feel that it is not necessary to test those features they have inherited because they have been tested very<br />

m<strong>an</strong>y times before (both by the system develo pers <strong><strong>an</strong>d</strong> by the m<strong>an</strong>y thous<strong><strong>an</strong>d</strong>s of users). However, this<br />

is misleading because in defining a new subclass they have ch<strong>an</strong>ged the context within which the<br />

methods will execute at least in the subclass. The problem is that each new subclass may not require <strong>an</strong>y<br />

re-testing <strong><strong>an</strong>d</strong> may very well function acceptably, but you are relying on a continuing hypothesis. Of<br />

course this hypothesis may have held m<strong>an</strong>y times before, but there is no guar<strong>an</strong>tee that it will hold this<br />

time. Interestingly, the same problem also occurs with Ada generics. In this case each inst<strong>an</strong>tiation of<br />

the generic package may work as intended but equally this time it may fail.<br />

22.3.1 The effects of inherit<strong>an</strong>ce<br />

There are a number of ways in which inherit<strong>an</strong>ce c<strong>an</strong> affect the testin g required in a subclass. The<br />

following list summarizes these <strong><strong>an</strong>d</strong> lists the type of testing required:<br />

Adding functionality . For example, by adding new methods. In these situations, the tests should<br />

concentrate first on the new functionality, to ensure tha t the class works correctly (relative to its<br />

specification). If the new functionality calls on existing methods, then tests should be performed<br />

to ensure that these methods continue to function correctly. If <strong>an</strong>y existing inst<strong>an</strong>ce variables are<br />

modified by the new methods, or the methods they call, then the effects of these ch<strong>an</strong>ges should<br />

be determined. This may result in re-testing the whole class.<br />

Over-riding methods. In these situations, the newly defined methods must of course be tested. This<br />

should test the new definition to ensure that it h<strong><strong>an</strong>d</strong>les the same r<strong>an</strong>ge of values as the original<br />

<strong><strong>an</strong>d</strong> produces the same results. If this is not what was desired, then over -riding was not the<br />

correct approach.<br />

Next all the methods which invoke the overridden operatio n must be re -tested. This c<strong>an</strong> be<br />

done by using the tools provided with the <strong>Smalltalk</strong> system to identify all the senders of the<br />

messages associated with the ch<strong>an</strong>ged methods. This will provide the initial test list. If the<br />

behavior of inherited methods is ch <strong>an</strong>ged in <strong>an</strong>y way then this should be treated as adding<br />

functionality <strong><strong>an</strong>d</strong> tested as above.<br />

Super Class references . If the subclass ch<strong>an</strong>ges <strong>an</strong>ything used by the super class, for example by<br />

referencing a pool variable, then the super class must also be subje cted to incremental testing.<br />

Again, the process needs to identify the elements of the class which have been affected <strong><strong>an</strong>d</strong> to<br />

test those elements. In the case of a pool variable, it may also involve testing other classes which<br />

reference the pool variable.<br />

184

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

Saved successfully!

Ooh no, something went wrong!