版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 大年夜跨度桥梁施工操纵
- 2026学年延川县三年级数学下学期期末学业质量监测试题(含答案)
- 2026年广东省南雄市高二生物上册期末考试模拟卷附参考答案【B卷】
- 2026年辽宁省调兵山市高二生物上册期末考试模拟卷附参考答案(基础题)
- 2026年河北省南宫市高二生物下册期末考试模拟试卷含答案(黄金题型)
- 2026年广东省连州市高二历史下册期末考试检测卷附完整答案(有一套)
- 2026年山东省栖霞市高二生物下册期末考试模拟检测卷含完整答案(考点梳理)
- 2026年山东省曲阜市高二生物下册期末考试模拟考试卷附答案(轻巧夺冠)
- 2026年云南省开远市高二生物下册期末考试模拟测试卷及参考答案【综合卷】
- 2026年云南省瑞丽市高二生物下册期末考试模拟试卷及完整答案一套
- (人教版)2026秋一年级上册数学第一单元练习卷(含答案)
- 消防通道管理必知的6个细节
- 有限空间风险评估管理制度
- 1.3 潜望镜与万花筒 课件(内嵌视频)2026-2027学年苏教版科学五年级上册
- 新版2026秋新教材统编版九年级上册道德与法治第1-4单元共4个单元素养测试卷全套(含答案)合集
- 2026中秋国庆节前全员安全教育培训
- 2026年新高考I卷数学真题
- 硝化企业安全风险隐患排查表(2026年版)
- 老年人多重用药评估与管理专家共识2026
- 产品质量问题重复出现处理意见建议
- 多伦县北磁科技高性能软磁材料试验线项目环境影响报告书
评论
0/150
提交评论