軟件需求分析英文課件:Chap 8-Design to Code_第1頁
軟件需求分析英文課件:Chap 8-Design to Code_第2頁
軟件需求分析英文課件:Chap 8-Design to Code_第3頁
軟件需求分析英文課件:Chap 8-Design to Code_第4頁
軟件需求分析英文課件:Chap 8-Design to Code_第5頁
已閱讀5頁,還剩41頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、Elaboration Iteration 1- Design to CodepCh19. Designing for VisibilitypCh20. Mapping Designs to CodepCh21. Test-Driven Development and Refactoring1Chapter 17. Designing for Visibilityo Objectiveso Identify four kinds of visibility.o Design to establish visibility.2Visibility Between Objects oVisibil

2、ity is the ability of one object to see or have reference to another.oThe designs created for the system operations (enterItem, and so on) illustrate messages between objects.oFor a sender object to send a message to a receiver object, the sender must be visible to the receiver.nthe sender must have

3、 some kind of reference or pointer to the receiver object.3Example4: RegisterenterItem(itemID, quantity): ProductCatalogdesc = getProductDesc( itemID )public void enterItem( itemID, qty ) . desc = catalog.getProductDesc(itemID) .class Register . private ProductCatalog catalog; .Visibility from the R

4、egister to ProductCatalog is requiredWhat is Visibility?o There are four common ways that visibility can be achieved from object A to object B:nAttribute visibility- B is an attribute of A.nParameter visibility- B is a parameter of a method of A.nLocal visibility- B is a (non-parameter) local object

5、 in a method of A.nGlobal visibility- B is in some way globally visible.5Attribute Visibility6: RegisterenterItem(itemID, quantity): ProductCatalogdesc = getProductDesc( itemID )public void enterItem(itemID, qty) . desc = catalog.getProductDesc(itemID) .class Register . private ProductCatalog catalo

6、g; .Parameter Visibility72: makeLineItem(desc, qty)enterItem(id, qty)1: desc = getProductDesc(id)2.1: create(desc, qty):Register:Sale:ProductCatalogsl : SalesLineItemmakeLineItem(ProductDescription desc, int qty) . sl = new SalesLineItem(desc, qty); .Parameter to attribute visibility82: makeLineItem

7、(desc, qty)enterItem(id, qty)2: desc = getProductDesc(id)2.1: create(desc, qty):Register:Sale:ProductCatalogsl : SalesLineItem/ initializing method (e.g., a Java constructor)SalesLineItem(ProductDescription desc, int qty) .description = desc; / parameter to attribute visibility.Local Visibility9: Re

8、gisterenterItem(itemID, quantity): ProductCatalogdesc = getProductDesc( itemID )enterItem(id, qty) ./ local visibility via assignment of returning objectProductDescription desc = catalog.getProductDes(id);.Global VisibilityoGlobal visibility from A to B exists when B is global to A. oIt is a relativ

9、ely permanent visibility because it persists as long as A and B exist. oIt is the least common form of visibility in object-oriented systems.oOne way to achieve global visibility is to assign an instance to a global variablenwhich is possible in some languages, such as C+nbut not others, such as Jav

10、a.oThe preferred method to achieve global visibility is to use the Singleton pattern , which is discussed in a later chapter.10Chapter 20. Mapping Designs to Codeo Objectiveso Map design artifacts to code in an object-oriented language11Implementation Modelo OOD artifacts as inputnInteraction diagra

11、ms nDesign Class Diagrams o Source code o Database definitions o JSP / XML / HTML pages12Programming and Iterative, Evolutionary Developmento The creation of code in an OO language is not part of OOA/D, its an end goal. o The artifacts created in the Design Model provide some of the information nece

12、ssary to generate the code.o A traceable end-to-end roadmap nUse case - requirements nOOAD - logical solution, blueprints nOOP - running applications 13Mapping Designs to Codeo Code Changes are inevitable nCASE Tools, and Reverse-Engineering o Implementation in an object-oriented language requires w

13、riting source code fornclass and interface definitionsnmethod definitions14Creating Class Definitions from DCDso DCDs depict a basic element of class definition nClass or interface namenSuperclassesnOperation signaturesnAttributes of a classoFrom the DCD, a mapping to the attributes (Java fields) an

14、d method signatures is straightforward15Defining a Class with Method Signatures and Attributes16public class SalesLineItemprivate int quantity;private ProductDescription description;public SalesLineItem(ProductDescription desc, int qty) . public Money getSubtotal() . SalesLineItemquantity : Integerg

15、etSubtotal() : MoneyProductDescription description : Textprice : MoneyitemID : ItemID.1descriptionSalesLineItem in JavaReference AttributeSimple AttributeCreating Methods from Interaction DiagramsoThe sequence of the messages in an interaction diagram translates to a series of statements in the meth

16、od definitions.172: makeLineItem(desc, qty)enterItem(id, qty)1: desc = getProductDesc(id)2.1: create(desc, qty)1.1: desc = get(id):Register:Sale:ProductCatalogsl: SalesLineItemlineItems : List: Map2.2: add(sl)The enterItem interaction diagramThe Register.enterItem Method18ProductCatalog.getProductDe

17、sc(.)SaleisComplete : Booleantime : DateTimebecomeComplete()makeLineItem(.)makePayment(.)getTotal()Register.endSale()enterItem(id: ItemID, qty : Integer)makeNewSale()makePayment(cashTendered : Money)public class Registerprivate ProductCatalog catalog;private Sale currentSale;public Register(ProductC

18、atalog pc) .public void endSale() .public void enterItem(ItemID id, int qty) .public void makeNewSale() .public void makePayment(Money cashTendered) .11catalogcurrentSaleThe Register class19The Register.enterItem Method2: makeLineItem(desc, qty)enterItem(id, qty)1: desc := getProductDescription(id):

19、Register:Sale:ProductCatalog ProductDescription desc = catalog.ProductDescription(id); currentSale.makeLineItem(desc, qty);The enterItem methodCollection Classes in Codeo One-to-many relationships are commonnImplemented with a collection objecto The choice of collection class depends on requirements

20、n Eg, key-based lookup requires the use of a Map, a growing ordered list requires a List, or simple array , and so on.o Guideline: nIf an object implements an interface, declare the variable in terms of the interface, not the concrete class2021SalesLineItemquantity : IntegergetSubtotal()1.*SaleisCom

21、plete : Booleantime : DateTimebecomeComplete()makeLineItem()makePayment()getTtotal()public class Sale.private List lineItems = new ArrayList();A collection class is necessary to maintain attribute visibility to all the SalesLineItems.lineItemsAdding a collectionDefining the Sale.makeLineItem Method2

22、2 lineItems.add( new SalesLineItem(desc, qty) );2: makeLineItem(desc, qty)enterItem(id, qty)2.1: create(desc, qty):Register:Salesl: SalesLineItemlineItems :List2.2: add(sl)Sale.makeLineItem methodOrder of Implementation23SalesLineItemquantity : IntegergetSubtotal()ProductCatalog.getProductDesc(.)Pro

23、ductDescriptiondescription : Textprice : MoneyitemID : ItemID.Storeaddress : Addressname : TextaddSale(.)Paymentamount : Money.1.*1.*Register.endSale()enterItem(.)makeNewSale()makePayment(.)SaleisComplete : Booleantime : DateTimebecomeComplete()makeLineItem(.)makePayment(.)getTotal().111111*1234567S

24、ummary of Mapping Designs to CodeoThere is a translation process from UML class diagrams to class definitions, and from interaction diagrams to method bodies. oThe basic translation process looks straightforward, sometimes can be done by a CASE tool oThere is still lots of room for creativity, evolu

25、tion, and exploration during programming work.24Introduction to the NextGen POS Program SolutionoA sample domain layer of classes in Java for this iteration.oThe main point of this listing is to show that there is a translation from design artifacts to a foundation of code.oThis code defines a simpl

26、e case; it is not meant to illustrate a robust, fully developed Java program with synchronization, exception handling, and so on.2526Eclipse project for NextGen POS 27282930313233Chapter 21. Test-Driven Development and Refactoringo Objectiveso Introduce these two important development practices in t

27、he context of the case studies34Test-Driven Development (TDD)oAn excellent practice promoted by the iterative and agile XP method , also known as test-first developmentoIn OO unit testing TDD-style, test code is written before the class to be tested, and the developer writes unit testing code for ne

28、arly all production codeoAdvantagesnThe unit tests actually get writtennProgrammer satisfaction leading to more consistent test writingnClarification of detailed interface and behaviornProvable, repeatable, automated verificationnThe confidence to change things35TDD (cont.)oThe most popular unit tes

29、ting framework is the xUnit family nJUnit for java, NUnit for .NET, and so forth. oExample: using JUnit and TDD to create the Sale class.oBefore programming the Sale class, we write a unit testing method in a SaleTest class that does the followingnCreate a Sale nAdd some line items to it with the ma

30、keLineItem method nAsk for the total and verify that it is the expected value oEach testing method follows this patternnCreate the fixture.nDo something to it (some operation that you want to test).nEvaluate that the results are as expected.36TDD Example3738IDE Support for TDD and xUnitRefactoringoC

31、ontinuously refactoring code is another XP practice and applicable to all iterative methods nA structured, disciplined method to rewrite or restructure existing code without changing its external behavior .nApplying small transformation steps combined with re-executing tests each step. oThe essence of refactoring is applying small behavior preserving transformations (each called a refactoring), one at a time .oAfter each transformation, the unit tests are re-executed to prove that the refactoring did not cause a regression (failure).39The Activities and Goals of RefactoringoThey

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論