1. Trang chủ
  2. » Công Nghệ Thông Tin

Software Engineering (phần 6) docx

40 685 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Nội dung

. : : ! ' . 'j ' $ ' j 'E i ' : . * C j Q@2 t H A p T : R y * From M odules Io Obletls ' E 1 1 . . ! . l I . ( . : i ' I function open - disk-file function open-tape-file function open-diskette-file1 l ;! y . . ( él)j ' ;l i I I 1 . Ii I Fileclass .l , 2 I ! ( t li : 1 abstract method open ;I j p . jI I ' ! 1 ' l 1 ' l '! l 1 . 1 . . 1l l . ; ! I j ! I .I p I I , ! ' . ! ( . : 11 ; p ; . I '' ! DiskFileclass TapeFileclass DisketteFileclassI l E I .1 Implementation of lmplementation of lmplementation of 'I q ' ;! ; . method open method open method open k I ' . for a disk file for a tape file for a diskette file j ' ' ! ! ' . (b): ! ' j ' .: . Flguee Kaa Actions need to open file . (a) Structured implementctions. (b) Obiect-oriented :l ! . ' file class hierarchy using Javc notation.4 ! . : : ! i : : .i . ' 1 1 j i ; J ! , now determines whether myFile is a disk file, a tape file, or a diskette file and in- ' j l ! t vokes the appropriate version of open. That is, the system determines at run time '.i l hether object myFise is an instanee of class DiskFilecloss, class TopeFilecloss, or ' , 1 1 l l ) l w i i ! lass Diske/eFilecloss and automatically invokes the correct method . Because thisI I C I i has to be done at run time (dynamically) and not at compile time (statically) , theI : l : I act of connecting an object to the appropriate method is termed dynamic binding.I l d ! .' 1 j Furthermore, because the method open can be applied to objects of different classes,I j l i it is termed polymorphic. The term means 'tof many shapesa'' Just as carbon crystals! E l in many different shapess including hard diamonds and soft graphite. so theI come1 t l I @ E l method open comes in three different versions. ln Java, these versions are denoted ' @ ! : I kFilecloss .open, TcpeFileclass.open, and DisketteFilecloss.open. (In C++, theI r, I Disi 1 j i period is replaced by two colons , and the hles are denoted DiskFileclass::open,l k : il j : . TapeFileclass::open, and DisketteFileclass::open.) However, because of dynamic I ! . I binding, it is not necessary to determine which method to invoke to open a spe- , 1 j 7 ific lile . Instead, at run time, it is necessary to send only the message myFile.openI , , , c ! ë F (), and the system will determine the type (class) of myFile and invoke the correct I j h d 1 m et o . : j ! t These ideas are applicable to more thanjust obslrod (virlual) methods. Considerj I : ' a hierarchy of classes. as show n in Figure 7 . 34. Al1 classes are derived by inheritance .1 ' : from the Bose class . Suppose method checkorder (b : Bose) takes as argument an!I - !j . . instance of class Bcse. Then, as a consequence of inheritance, polymorphism, and , ' i t d nam ic binding , it is valid to invoke checkorder with an argument notjust of classI 1 i y ' I 1 ! ; ; Bcse but also of any subclass of class Bose , that is, any class derived from Base. All ' j j ', '1 ! 1 1 : F . r i I i! ' r 1 ' i ;I . . 1 ! 1 ' . Please purchase Image To PDF Converter on http://www.verypdf.com/ to remove this message, thank you. 1 . l I . I 2 xp coHEsloN AND coupuNo oF oYlcTs 2oa ; l sa ?,! ' jIi l -I I ! E ' ' ji Ir . r.; t 1 .( ' r j ' )I . l 1. I !1 : ' . I l ' . l 1 $; 4 j ' Flsure Ka* Hierarchy of classes. p q . ! ' . ' ' ' . ji j that is needed is to invoke thetkorder and everything will be taken care of at run j time. This technique is extremely powerful, in that the software professional need not ! i t ' 1be concerned about the precise type of an argument at the time that a message s sen . lH owever, polymorphism and dynamic binding also have major disadvantages. I : . ' . jFirst , it generally is not possible to determine at compilation time which version of a . specific polymorphic method will be invoked at run time. Accordingly, the cause of j a failure can be extremely difficult to determine. ' ' Second, polymorphism and dynamic binding can have anegative im pact on m ain- : $ . i - tenance. The first task of a maintenance programm er usually is to try to understand j e the product (as explained in Chapter 16, the maintainer rarely is the person who de- t 'r veloped that code). However, this can be laborious if there are multiple possibilities ( p S for a specific method. The programmer has to consider all the possible methods that l 1: j ime-consuming task. ! !C could be invoked dynamically at a specific place in the code , a t ic binding add both strengths and weaknesses to the 1 lr . Thus, polymorphism and dynam j ;, object-oriented paradigm. ; ii j 'S Th e reasons for the superiority of the object-oriented paradigm given in Sec- t ) : e tion l .6 included conceptual and physical independence. To measure this indepen- l I ;l I71 dence . the concepts of cohesion and coupling must be reexamined within the context j ki je of objects . l j j ' I j1 , i! c j 'j - . I l3 - - : t y.@ ZOHESIO N ANp toupklNl @F @ BJEW S 1 r An object is a kind of module. Consequently, the material of Sections 7.2 and 7.3 5 l 1z ; concerning modules with high cohesion and low coupling applies equally to objects. r ' h ther special types of cohesion and coupling occur within i3 The question arises as to w e i i1 th e object-oriented paradigm. : jl I S First consider cohesion. (Recall that, as explained in Section 7.2, the cohesion of 1 : i l a module is the extent to which the actions performed by that module are functionally ( 1 'j I : ! ' ' j j . . I ' ' ' I Please purchase Image To PDF Converter on http://www.verypdf.com/ to remove this message, thank you. 7 ' y ' g ' i ( 'i . t ( ' : j ' 1 x@* t u a p T z . y . From Modules 'o obietls: ' !I i l ! ' : ' ! j ' related). A class can include actions of two kinds, inherited methods and methods k ! 1 specific to that class. The cohesion of a class is determined from its functionality,I $ ' : . l ; : irrespective of the source of that functionality. To see this, suppose that two classes i l E' : ' ; 1 have identical functionality. However, one class inherits a11 its functionality from ' ' . j I its superclasses (its aneestors in the inheritance hierarchyl; tbe other class inherits ' I i thing . Because both classes have identical functionality, they have identical levels :l ë I F10 j ' i - r yi , of cohesion. In other words, no types of cohesion are specific to classes', cohesion 1 applies equally to a1l types of modules , including classes (Schach, 19961.l 1 E i with regard to coupling, lirst ignore inheritance. In the absence of inheritance, the '! Il ! : I $I . ; I coupling betw een two classes clearly can be determ ined as in the classical paradigm. . l ' ! y' le if an attribute of a class is delined to be publk (accessible to all otheri or examp ,1 t i l units within the product), then this can induce common coupling. what is somewhati ! : l ising however, is that inheritance does not induce new forms of coupling. ThatI j surpr , l 1 i is the forms of co upling that arise as aconsequence of coupling can be shown to occurj : ! ,i : ; 1I j q in the classical paradigm as well gBinkley and Schach, 19971. So, despite the major 'l ( differences between the classical and object-oriented paradigms, the object-oriented .t ' i ë . 1 k ? paradigm does not induce new forms of either cohesion or coupling. 4 lj However, a number of metrics specilic to the object-oriented paradigm have J i :1 $ , ) been put forward', for example, the height of the inheritance tree kchidamber and z 1 17 ' Kem erer , 19941. Some of these metrics have been questioned on both theoretical and . (k . ; l ; . experimental grounds EBinkley and Schach, 1996, 19971. ln these cases, it remains to j 1 k : ' be shown that there is a need for speciticall y object-oriented metrics, as opposed to I( 'E : :( ; classical metrics (like cohesion and coupling) that can be applied equally to object- h ' ' oriented software. t1 i ' i j : k We conclude this chapter with a discussion of the object-oriented paradigm. Il l t i (E1 ' l I . . : ' j l '1 ' t I 1 i I . 1 t 4t Kl@ THE @ BJEW -@ RIKNTKP PARAPI*M tl l i fl I ' -I y ! There are two ways of looking at every software product. One way is to considerjust f)l l ': i the data, including local and global variables, arguments. dynamic data stnletures, iql : i files , and so on. Another way of viewing a product is to consider just the actions s -1 1 l ' 1 ' 1 '; . performed on the data, that is, the procedures and the functions. ln terms of this . al . l ' ! 1 division of software into data and actions . the structured techniques essentially fall r t,; . : . I 1 , ' l into two groups. Action-oriented techniques primarily consider the actions of the p' ( k . è I j ' product. The data then are of secondary importance, considered only after the actions y s' j l j ' ! of the product have been analyzed in depth. Conversely, data-oriented techniques sdi .i stress the data of the product', the actions are examined only within the framework of . c j. i ! 2 ! j the data. p . ' j .A fundamental weakness of both the data- and action-oriented approaches is thatl i : . . . , 1 data and action are two sides of the same coin; a data item cannot change unless an o1 - l 1 .j . r action is performed on it, and actions without associated data are equally meaningless. a ) ' ' j i Therefore, techniques that give equal weight to data and actions are needed. It should t) F i I 1 ' II 2 l : j not come as a surprise that the object-oriented techniques do this. After all, an object s1i i (I !! l , @ ' . I .j ' 1J t : ': i ) ' p :: ' ! , Please purchase Image To PDF Converter on http://www.verypdf.com/ to remove this message, thank you. ! i j 1 . l I yx TH: OBJECT-ORIENTED PARADIOM 2@s ( ; . ! .ls comprises both data and actions. Recall that an object is an instance of an abstract l I 2 jy, data type (or , more precisely, of a class). lt therefore incorporates both data and the I . - - - - - i : ' ls actions performed on those data. The data of an object are variously called attributes, ! ! : .! ' j .m state variables , instance variables, jields, or data members. The actions are called j ts methods or memberfunctions. But irrespective of the terminology used for data and I l iI q ,ls actions , both are present in objects as equal partners. Similarly, in all the object- ! j ln oriented techniques, data and actions are considered to be of the same importance, j j j and neither takes precedence over the other. 1 1; !i Ile lt is inaccurate to claim that data and actions are considered simultaneously in the j t j n. techniques of the object-oriented paradigm. From the material on stepwise refinement 'j '! Ij e,r (Section 5. l ), it is clear that there are times when data have to be stressed and times 'p : ;: I at when actions are m ore critical. Overall, however, data and actions are given equal i I I l ! Iat importance during the phases of the object-oriented paradigm . I j! ur Many reasons are given in Chapter 1 and this chapter as to why the object-oriented I ! ing al1 these reasons is that i 1 , !or paradigm is superior to the structured paradigm. Underly ld a well-designed object, that is, an object with high cohesion and 1ow coupling, mod- :1 els al1 the aspects of one physical entity. The details of how this is implemented are I ze ' hidden', the only communication with an object is via messages sent to that object. : l 1ld I As a result, objects essentially are independent units with a well-dehned interface. ; 1 ld ' Consequently, they are easily and safely maintainable', the chance of a regression l' ) . to : fault is reduced. Furthermore, as will be explained in Chapter 8, obiects are reusable, , I j . ' '''' - ''''' j ' ito and this reusability is enhanced by the property of inheritance. Turning now to de- j j rt- velopment using objects, it is safer to construct a large-scale product by combining j 'r these fundamental building blocks of software than to use the structured paradigm. I I Because objects essentially are independent components of a product, development j j of the product, as well as management of that development, is easier, and hence less r J likely to induce faults. I ! 2: $ tA1l th ese aspects of the superiority of the object-oriented paradigm raise a ques- j r f - tion: If the structured paradigm is so inferior to the object-oriented paradigm, why has ' j the structured paradigm had so many successes? This can be explained by realizing j ' hat the stnlctured paradigm was adopted at a time when software engineering was l i ' t y 5 st not widely practised. Instead, software was simply t'written.'' For managers, the most j ; .l - :s, important thing was for programmers to churn out lines of code. Little more than lip ! jk ' ; 3s service was paid to the requirements and specihcation (systems analysis) of a product, 1 I I ' I jis and design was almost never performed . The build-and-fix model (Section 3. l ) was , l ; ' i ! ' !tll typical of the techniques of the l970s . Therefore, use of the structured paradigm ex- ' posed the majority of software developers to methodical techniques for the first time. l j lle 'S Small wonder, then, that the structured techniques led to major improvements in the 1 ZS software industry worldwide. However. as software products grew in size. inadequa- t Rf ies of the stnlctured techniques started to becom e apparent , and the object-oriented iC ; paradigm was proposed as a better alternative. l at This, in turn, leads to another question: How do we know for certain that the ' I J tn object-oriented paradigm is superior to all other present-day techniques? No data t J ) S. are available that prove beyond a1l doubt that object-oriented technology is better I 'j I Ed ' than anything else currently available, and it is hard to imagine how such data could : ; : ! 1 !j '.2t be obtained . The best we can do is to rely on the experiences of organizations that :ê ' t , . j l 'I i 1 l i . l 1 Please purchase Image To PDF Converter on http://www.verypdf.com/ to remove this message, thank you. '1 E . j ' ! ' ! :. kl . 1 i aol t u A p v : . y . From Modules 'o obiet's1 4! ; @ ë . j ; !. ! 'j 1 have adopted the object-oriented paradigm. Although not all reports are favorable,: i l L ( the majority (if not the overwhelming majority) attest that using the object-oriented ! ; E ;l ; : : paradigm is a w ise decision. ' I h 1 For example . IBM has reported on three totally different projects that were devel-! il 1 ! oped using object-oriented technology gcapper, Colgate, Hunter, and James, 19941.l 1 ;l ! : ln almost every respect . the object-oriented paradigm greatly outperformed the struc-j . . ' ! tured paradigm. Specifically, there were major decreases in the number of faults ;1 ! 1 s , 1 ( t j j detected, far fewer change requests during both development and maintenance that ; l ! i 1 were not the result of unforeseeable business changes, and signihcant increases in $ : 1 ; ! ', . ' , . both adaptive and nerfective maintainabilitv. There also was an improvem ent in us- I l I * '- ''' - l i j ability, although not as large as the previous four improvements, and no meaningful . ; ' I difference in perform ance . .1 I I :1 ' ; A survey of l50 experienced U . S. software developers was undertaken to deten -1 ! mine their attitudes toward the object-oriented paradigm ëlohnson, 20001. The sampleI ' ,l ' 1 isted of 96 developers who have used the object-oliented paradigm and 54 whoI i i COnSI I ;l i S p still use the classical paradigm to develop software . Both groups felt that the object- g j ' Ei ' : ; oriented paradigm is superior, although the positive attitude of the object-oriented (l 1 -I i , group was signihcantly stronger. Both groups essentially discounted the various dis- ' '' 11 '',j'. ' I : advantages of the object-oriented paradigm. ! . Notwithstanding the many advantages of the object-oriented paradigm, some . t ' , difhculties and problems indeed have been reported. A frequently reported problemi j! ! concerns development effort and size . The first time anything new is done. it takesi .! ! ' ' ions; this initial period is sometimes referred to as the .1 j : Iongerthan on subsequent occas) - . j j i learning curvc. But when the object-oriented paradigm is used for the first time byi ! !)l : an organization , it often takes longer than anticipated, even allowing for the learning ,1 1 i j . i curve. This is because the size of the product is larger than when structured techniquesI l - , :'' : l are used. This is particularly noticeable when the product has a graphical userinterface ' j ) g (GUI) (see Section l 0.3). Thereafter, things improve greatly. First, maintenance costs C,l 1 are lower, reducing the overall lifetime cost of the product. Second, the next time l1 ( s l l 1 I that a new product is developed, some of the classes from the previous proiect can be . 1 ' : ''''' ''- ''''' ''' ''''' - 1 . reused, further reducing software costs. n is has been especially signihcant when a l I GUI has been used for the first time; much of the effort that went into th e GUl can l' I i 1 . l 1 '1 be recouped in subsequent products. '! h i -1 1 : 1 Problems of inheritance are harder to solve. A major reason for using inheritance ( ' l'' t : ' r' is that a new subclass that differs slightly from its parent class can be created without l I C ' i ' ffecting the parent class or any other ance stor class in the inheritance hierarchy. t! E ! aI l , : 1 conversely, however, once a producthas been implemented, any change to an existing ' . ' ' l i ! class directly affects all its descendants in the inheritance hierarchy', this often is 'ë' p 1 : ' t .I ' f d to as thefragile base classproblem. Atthe very least, the affected units have to :. j re erre . l i . j 1 be recompiled. ln some cases. the methods of the relevant objects (instantiations of the 1.l i . 1 @ E affected subclasses) have to be recoded', this can be a nontrivial task. To minimize this ,, ' ' ' i I C roblem , it is important that alI classes be carefully designed during the development t; P1 i This will reduce the ripple effect induced by a change to an existing class . )1 PVOCCSS , i () 1 1 I A second problem can result from a cavalier use of inheritance. Unless explic- )1 j i.' 1 itly prevented , a subclass inherits all the attributes of its parent classtes). Usually,) j I j ' ! t j subclasses have additional attributes of their own. As a consequence, objects lower :, . j ! I 2 y' r ;. )p ' It ; 1 ' j ! j . Please purchase Image To PDF Converter on http://www.verypdf.com/ to remove this message, thank you. I ' i ,' . jjIl !FoR FURTHER READING Q@F l i - lnle , , in the inheritance hierarchy quickly can get large, with resulting storage problems j ! Lted ! (Bruegge, Blythe, Jackson, and Shufelt, 19921. One way to prevent this is to change I 1, ' ' the dictum <'use inheritance wherever possible'' to d'use knhelitance wherever appro- jL Fel- priate.'' In addition, if a descendent class does not need an attribute of an ancestor, I j j )41. then that attribute should be explicitly excluded. ! 1, i ' luc - . A third group of problems stem from polymorphism and dynamic binding. These I r - I :.ults . were described in Section 7.8. hat ' One final question: Someday might there be something better than the object- I 4 in ( oriented paradigm? Even its strongest proponents do not claim that the object-oriented l us- . paradigm is the ultim ate answer to all software engineering problems. Furthermore, ; I ! i ' ftware engineers are looking beyond objects to the next majorbreakthrough . ! ; 7) ijjful today s so ' I !After all , in few selds of human endeavor are the discoveries of the past superior t ; 'j1 i ; ter- j to anything being put forward today. The object-oriented paradigm is sure to be , j . le superseded by the methodologies of the future. The important lesson is that, based i l 1IP q vho on today's knowledge, the object-oriented paradigm appears to be better than the j j zct- alternatives. l . ikted ; dis - i lI 1 )111 () p lem QHAPTER RzvlKw 11l j Xes ! j j the The chapter begins with a description of a module (Section 7. 1). The next two sec- j 1 . by tions analyze what constitutes a well-designed module in terms of module cohesion l k ' and module coupling (Sections 7.2 and 7.3). Specifically, a module should have high l lïing hesion and low coupling. Various types of abstraction are presented in Sections 7.4 Jgues co 'ace through 7.7, including data abstraction and procedural abstraction. In data encapsula- ! I làsts tion (Section 7 . 4), a module comprises a data structure and the actions performed on I j i ime that data structure. An abstract data type (Section 7.5) is a data type, together with the . ; . - - - - . J ' ! 1 be actions performed on instances ot that type. lnformation hiding (Section 7.6) consists j - 1 i Im a of designing a module in such a way that implementation details are hidden from other , ; . ! dcan m odules . The progression of increasing abstraction culminates in the description of j : a class, an abstract data type that supports inheritance (Section 7.7). An object is an ! I 'i ! jnce instance of a class. Polymorphism and dynamic binding are the subject of Section ( ; t kout 7.8, and cohesion and coupling of objects are described in Section 7.9. The chapter I I i! zhy. concludes with a discussion of the object-oriented paradigm (Section 7. 10). . 'l ling rl is I e to ; ' the ' 1 FoR FupTuzp Ru plxo ,jthis kent g j Is. Objects were first described in ëDahl and Nygaard, l 9661. Many of the ideas in this l lic- chapter originally were put forward by Parnas (Parnas, l 97 1, l 972a, 1972b1. The use jp t .Llly , of abstract data types in software development was put forward in (Liskov and Zilles, ' ' g1 i kver 19741,. another important early paper is ëGuttag, 19771. l I 1 ë @ (' j l ; ' 4 2 - ! i i Please purchase Image To PDF Converter on http://www.verypdf.com/ to remove this message, thank you. I q . j 'l . . 1 . 1 i ' . i aoa t u A e T : . y . From Modules 'o obieds I ! ' j ' ' ;l i ! The primary source on cohesion and coupling is gstevens, Myers, and Constan- y 4l1 ! 7 .! $ ' ti ne, 19741. The ideas of composite/structured design have been extended to objectsj I : ' : ' ' I 2 (Binkley and Schach, 19971. : l j ' ' t k Introductory material on objects ean be found in kMeyer, 19971. Ways in which ê :. ' i , $ object-oriented programming promotes reuse are put forward in (Meyer, 1987, 19901.; r s q ! k Different types of inheritance are described in (Meyer, t996b1. A number of short ' ! 1 articles on the object-oriented paradigm can be found in rEl-Rewini et al ., 19951. . V** . l I ! ! t ; The proceedings of the annual Conference on Object-oriented Programming Sys- V*7l 1 I 1 tems , Languages, and Applications (OOPSLA) include a wide selection of research V.'. j g j j t papers; the addendum to the proceedings (published annually in ACM SIGPLANNO- y.@l ! ' - ! I tices) contains informal reports describing successful obiect-oriented proiects. The j: j j = '- H - v *successful use of the object-oriented paradigm in three IBM projects is desclibed in l . !l j j ' g j jcapper, Colgate, Hunter, and James, 19941. Other experiences with the paradigm j !l 1 I ted in the October 1995 issue of the Communications ofthe ACM. A survey *l . j are repor1 ' ' ' f attitudes toward the object-oriented paradigm appears in (Johnson, 20001. gFayad,! r ! 1 O .12 , 1 i Tsai, and Fulghum, 19961 describe how to make the transition to object-oriented tech- I ( ' ' nology: a number of recommendations for managers are included. A detailed accountI r ; ' f object-oriented metrics is given in gllenderson-sellers, 19961.I o . I 1 h ' t ' l The October 1992 issue of IEEE Computer contains a number of important( ! . (q ,, . ! $,! ! articles on objects, including (Meyer, 1992a1, which describes design by contract. ) t ' i ' A variety of articles on objects ean be found in the January 1993 issue of IEEE i 1 ' ' y ' , : ! i ; Software; Snyder s paper carefully defining key terms in the field (Snyder, 19931 is . p : i ! i q ï . particularly useful. Possible drawbacks of polymorphism are described in (Ponder and .14 j ! j Bush, 19941. The October 1995 issue of the Communications of the ACM contains1 ' t j 1 articles on object technology, as does Issue No. 2, 1 996, of the 1BM Systems Journal. d I I .15 4I I : l : u I t i.'' . j ! . i pposu - s ' , 1 : j 'l 1 1 1 * 1 * d l 1 i 7 1 Choose any programming language with which you are familiar. Consider the two ' '* a1 , l definitions of modularity siven in section 7.1. oetermine which of the two definitions ' 4'1 l '' : ineludes what you intuiti-tely understand to constitute a module in the language you1 1 ) t l t i t have chosen.l p i ( ' ! ! - ( ! j 7.2 Determine the cohesion of the following modules: . ( , ! : ' @ ' i dit rofit and @ox record - ! T ù e p' - 11 i 1 edit profit record and tax record ! I ' i ' read delivery record and check solary pcyments ' . . ! : : ' v. jj : compute the op@imal cost using Aksen s algorithm I ' ! : !1 E measure vapor pressure and sound olarm if necessoryl l k i- . -1 .; ' j ' I . l 1 j 7.3 You are a software engineer involved in product development. Your manager asks ( i i i . I 1 jr j you to investigate ways of ensuring that modules designed by your group will be as 1 1 1 reusable as possible . W hat do you tell her?l I . ! ! r, - (1 l ; 1 ( ' i 1 ' , ! : . 1 ' 1 t t .1 j , 1 ' 1 t 1 ' Please purchase Image To PDF Converter on http://www.verypdf.com/ to remove this message, thank you. I ! l ; ' I I IREFERENtES ao@ l l I tn- ;.4 Your manager now asks you to determine how existing modules can be reused. Your j 2tS first suggestion is to break each module with coincidental cohesion into separate l ly points out that the separate i l ' 'modules with functional cohesion. Your managercorrect Ch dules have not been tested nor have they been docum ented . What do you say now? 1 imo j !I ;01. z s w hat is the innuence of cohesion on maintenance? 2 , ol't ! (T . 6 W hat is the insuence of coupling on maintenance? j ,51 . 1 . F.7 Carefully distinguish between data encapsulation and abstract data types.4s - vh : 7.8 Carefully distinguish between abstraction and intbrmation hiding. t ' ! ' Io- 7.# Carefully distinguish between polymomhism and dynamic binding. j I I $ ' 'he ' z 1: convert the comments in Figure 7 .23 to C++ orlava, as specified by your instructor. ( ; I ill Make sure that the resulting m odule executes correctly . i i jl ' . i I lm ;.1 1 It has been suggested that C++ and Java support implementation of abstract data ' i i 'CY but only at the cost of giving up information hiding . Discuss this claim . 1 8 ltypes q Xd' ' '' i C ase You W anted to Know'' box at the beginning 7; .1Q As pointed out in the Just n 2h- of this chapter, objects first were put forward in 1966. Only after essentially being ant 1 reinvented nearly 20 years later did objects begin to receive widespread acceptance. j Can you explain this phenomenon? l ànt è S ,, 7.13 Your instructor will distribute a structured software product. Analyze the modules I) 1! . j ' from the viewpoints of information hiding, levels of abstraction, coupling, and j !EE . cohesion. iI is . j krld 7.14 Your instructor will distribute an object-oriented software product. Analyze the mod- : q ins ules from the viewpoints of information hiding, levels of abstraction, coupling, and l ; fal. cohesion. Compare your answer with that of Problem 7. 13. 7.15 (Term Project) Suppose that the Broadlands Area Children's Hospital product of ing the structured paradigm. Give examples of modules ( 1 , Appendix A was developed us I ; ' of functional cohesion that you would expect to lind. Now suppose that the product j I developed using the object-oriented paradigm. Give examples of classes that you ' l twas p! ! would expect to find. ë i i t i 7.1: (Readings in SoftwareEngineering) Yourinstructorwill distribute copies of rlohnson, j ! ! wo 20001. Why do you think that the respondents viewed the drawbacks to the object- '@ 't ) ially irrelevant? jl l)ns oriented paradigm as essent j 'ou l 1 !I - . l' j IRZFKRKNtKS , ' j I (Berry, 19781 D. M. BERRY, personal communication. 1978. l 'A Comparison of Sixteen ' 1gBinkley and Schach , 1 9961 A. B. BINKLEY AND S. R. SCHACH, j Quality Metrics for Object-oriented Design,'' Information J'mccy-îïrw Letters 57 (No. 6. 'l June 1996), pp. 27 1-75. j j ;kS (Binkley and Schach . 1 9971 A. B. BINKLEY AND S. R. SCHACH, t'Toward a Unified Approach l ' ; ' yRS t o Object-oriented Coupling.'' Proceedings ofthe 35th Annual ACM Southeast i 1 ; Conference, Murtreesboro, TN. April 2 4, 1 997, pp. 9 1-97. r t l . ' : ) ' . l l , Please purchase Image To PDF Converter on http://www.verypdf.com/ to remove this message, thank you. g ' J : ' : ' l! ! : ' I . . 1 E ' ! .l i !' : j) . ; ; ' : ; . l ij t l ex p- . ; ' 1 . 4 ( y ' y -1 j i 1 i i 2 l ! ë - 1 ,I . :1 ) ! +++I ! . +1 l : : 1 E IkI y T IkI y . . : l i ' 11 i, I T: : IkI .r I : . 1 I 1 l :' I ! l 1 i 1 , !! ' l : ! t ' I E ' . ' ! : : 'ï , t :I t ; i . ' j . ( : I 1 -I j -E l ) i If reinventing the wheel were a criminal offense , many software professionals would be languishing in jail.I ' 'y l i ! ' For example, there are tens of thousands (if not hundreds of thousands) of different COBOL payroll programs,' ' l . 7 ' ' j I , : a1l doing essentially the same thing. Surely, a1l that the world needs isjust one payroll program that can nln on ' 1 ! ! . a variety of hardware and be tailored, if necessary, to cater to the specihc needs of an individual organization . . . j j ; , j h j However, instead of utilizing previously developed payroll programs, myliad organizations all over the world . J ' ) ! ' have built their own payroll program from scratch. - : 1) l g! . I In this chapter, we investigate why software engineers delight in continually reinventing the wheel andI r ' . 1 j l what can be done to achieve portable software built using reusable components. We begin by distinguishing ' t ' between portability and reusability. . ' j q ' I j . j . j -I I 1 1 1 e.I R zus: toxtzpTs @ ' ' i j:' f : l j A product ksportable if it is signifkantly easier to modify the product as a whole to run l ? it on another compiler - hardware-operating system configuration than recode it from( i ; ' 1 h In contrast , reuse refers to using components of one product to facilitate thescratc .' . : j é j : r development of a different product with different functionality. A reusable component! ' t g i need not necessarily be a module or a code fragment it could be a design, a pal't of : 1 ) - . . ! i : a manual, a set of test data, or a duration and cost estimate. ' l ! i Th ere are two types of reuse, accidental reuse and deliberate reuse. lf the de-I j .i 1 , I ' i : velopers of a new product realize that a component of a previously developed prod-( t ' 1 ' f uct can be reused in the new product , then this is accidental reuse or opportunisticl j i reuse. On the other hand, utilization of software components constructed specih- l k i 11 for possible future reuse is deliberate reus e or systematic reuse. One potential; j ca y l' l ( .,A- e-ploi-ea i- th- p o , th- t i-I offhi- chopte- .oy in- t sf,, i- p II-I with p , 2. l ! i1 l . l I 11 ' aIa I l ë !. $ j. , : j ë ; y . ' . ! I ' Please purchase Image To PDF Converter on http://www.verypdf.com/ to remove this message, thank you. I 1 ' I ; . aa REusE CoNcEpTs m a l l l ! j l .I . ' itdvalltagc Of dcliberate retlse Over accidental reuse is that components specially con- l I ' j! structed for use in future products are more likely to be easy and safe to reuse', such l : ; ' i j , components generally are robust. well documented, and thoroughly tested. In addi- 1 i tion, they usually display a uniformity of style that makes maintenance easier. The I ql : : other side of the coin is that implementing deliberate reuse within a company can be p : ive. lt takes time to specify, design, implement, test, and document a software 1 1expens 1 component. However, there can be no guarantee that such a component will ever be ! 4! r p ' reused and thereby recoup the m oney invested in developing the potentially reusable 1I i component. I , 1W hen computers were first constructed , nothing was reused. Every time a prod- )1 - uct was developed, items such as multiplication routines, input-output routines, or 1 i, j ) ' routines for computing sines and cosines were constructed from scratch. Quite soon, I l 1 1 '! l .however , it was realized that this was a considerable waste of effort, and subroutine ji I libraries were constructed. Programmers then simply could invoke square root or sine I j )' jfunctions whenever they wished . These subroutine libraries have become more and 1 l more sophisticated and developed into run-tim e support routines. Therefore. when a j I programmer calls a C++ or Java method, there is no need to write code to manage 1 the stack or pass the arguments explicitly; it is handled automatically by calling the ' ijail . ! appropriate run-time support routines. The concept of subroutine libraries has been i jams , i extended to large-scale statistical libraries such as SPSS (Norusis, 20001 and to nu- I ln on j Imerical analysis libraries like NAG (Phillips . l 9861. Class libraries also play a major T jtion .' jd role in assisting users of object-oriented languages. The environment for the Ianguage ! !por Eiffel incorporates seven libraries of classes (Meyer, 19901. The success of Smalltalk ! 1: 1at least partly is due to the wide variety of items in the Smalltalk library . In bothl and i instances, the presence of a browser, a CASE tool that assists the user to scan a class ' 'hing library, is of enormous assistance. W ith regard to C++ , a large number of different libraries are available, many in the public domain. One example is the C++ Standard j ! Template Library (STL) LMusser and Saini, 19961. ! ! l An application programming interface (APl) generally is a set of operating sys- j tem calls that facilitate programming. For exam ple, W in32 is an API for M icrosoft ; l ' E ! . operating systems such as W indows 2000 and W indows NT', and the M acintosh Tool- ; . 11 lr 'box is an APl for M ac OS , the M acintosh operating system. Although an APl usua y is implemented as a set ot operating system calls, to the programmer the routines 1 7) run , 1 constituting the API can be viewed as a subroutine library. For example, the Java j jfrom Application Programming lnterface consists of a number of packages (libraries). je the ,N o matter how high the quality of a software product m ay be, it will not sell if it 'ZCFX takes 4 years to get it onto the market when a competitive product can be delivered in ' l l trt of only 2 years. The length of the development process is critical in a market economy. AlI other criteria as to what constitutes a 'tgood'' product are irrelevant if the product z de- g cannot com pete timewise. For a corporation that has repeatedly failed to get a product ë lrod- to market ûrst, software reuse offers a tempting technique. After all, if an existing ! tistic component is reused, then there is no need to design, implement, test, and document lcili- that component. The key point is that, on average, only about l 5 percent of any rntial I j ' software product serves a truly original purpose (Jones. 19841. The other 85 percent . j . l of the product in theory could be standardized and reused in future products. ' 1 ! l . -! 1 : @ - ) i è ' i Please purchase Image To PDF Converter on http://www.verypdf.com/ to remove this message, thank you. [...]... ii terapaefmbhn a hneper r eid h do Grs g n c ni dta tek n ao sweei io o o o f me h t h a g ro r mr me a ey dia me a d t r or i n w i s f t f dit l s r d n heef e t o s a e o l y a lneSnemslahhl prhp- softwaretl.untisnietswhpedng, n a cdtg iisteec t er oeAtproraeot otclmusttak careh enrni du h i r s t i eT o codrosaesBtlswtoadgh a yeusig e o v nurisina mulhfit.n i p n f si t e t e oo h o us ga r mme... td t b e s efa i ti rao igi ta amo uewi f n t a c h so i n t o e ay Th lw n hs e snn s h t d l t u ci l o e in s o h on j! l 1: , ;' 1! ; 4! ( ci n7 i i amo l p r me onyo ea t ,twa tou h t b Se t 2 6) That s f due et d l n ci i s h g t o e o br on j; ;! 1! i s fconti d an i el ane d ndepe t I ta i hast opert ondat I uc nden nse d t o ae a e i r us t n t da a on whi i i t ope a e mus be r e tfs h... ieta a yc mp ttrsma hn , u a yc so ri-d ie e o g e s x e sv h n n o eio ' c ie b t n utme la vsd n u h l t bu fom adif en manufct e wilbe s ng $35, o yr fer t a urr l pendi hvtpyo $0000toconvertexistingsoftwareanddatatoomuhadao aeoasme20 00ttheform an the 0 o c tofl s , n M CM mac ne onhi Mo igfo tep ee igi gn r staint tera wo l temo t u vn rm h rc dn ma iay i to o h e l rd,h s s c u cesf ln ofcomput . of software in a NASA software production $ ' ! 1 ! . ; ' : group that produces ground support software for unmanned spacecraft control (Selby, i ! ' i 19891 . Altogether 25 software. The NASA staffers reused software simply because they believed that reuse is a l I ? : ;lion , worthwhile software engineering technique. In addition, there were no software tools cent to assist. j ' hat the stnlctured paradigm was adopted at a time when software engineering was l i ' t y 5 st not widely practised. Instead, software was simply t'written.'' For managers,

Ngày đăng: 07/07/2014, 06:20

TỪ KHÓA LIÊN QUAN

w