




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Elaboration Iteration 2- More PatternspCh24. Iteration 2More PatternspCh23. Quick Analysis Update pCh25. GRASP: More Objects with Responsibilities1Chapter 24. Iteration 2-More Patternso Objectiveso Define the requirements for iteration-2.2Introductiono Object Design and Patterns o In this iteration,
2、 the case study just emphasizes nessential object design nuse of patterns to create a solid design nApplying the UML to visualize the models o The discussion of requirements and domain modeling will be minimal o The explanation of the design will be succinct 3From Iteration 1 to 2o Achievements at t
3、he end of iteration 1 nAll the software has been vigorously tested; unit, acceptance, usability, nCustomers have been regularly engaged in evaluating the partial system, to obtain feedback for adaptation and clarification of requirements nThe system, across all subsystems, has been completely integr
4、ated and stabilized as a baselined internal release4Iteration 2 Requirements & Emphasiso NextGen POS nSupport for variations in third-party external services. oDifferent tax calculators oDifferent accounting systemsnComplex pricing rules nA design to refresh a GUI when the sale total changes 5o Mono
5、poly nImplement a basic, key scenario of the Play Monopoly Game moving around the squares of the board nSome of the special square rules apply oEach player receives $1500 at the beginning of the gameoGo square oGo-To-Jail square oIncome-Tax square 6Chapter 24. Quick Analysis Updateo Objectiveso Quic
6、kly highlight some analysis artifact changes, especially in the Monopoly domain model7Case Study: NextGen POS -SSD89Case Study: Monopoly-Domain ModelChapter 25. GRASP: More Objects with Responsibilitieso The five GRASP patterns explored nCreator nInformation Expert nLow Coupling nController nHigh Co
7、hesion o Learn to apply the remaining GRASP patternsnPolymorphism nIndirection nPure Fabrication nProtected Variations10Polymorphism oName: Polymorphism oProblem: nHow to handle alternatives based on type? How to create pluggable software components? oSolution: nWhen alternate behaviours are selecte
8、d based on the type of an object, use polymorphic method call to select the behaviour, rather than using if statement to test the type.oassign responsibility to the types for which the behaviors vary.oExamples: nIn the NextGen POS application, there are multiple external third-party tax calculators
9、that must be supported; the system needs to be able to integrate with different ones nWhat objects should be responsible for handling these varying external tax calculator interfaces?11NextGen Problem: Example 1How Support Third-Party Tax Calculators?1213NextGen Problem: Example2CreditPaymentauthori
10、ze() CheckPaymentauthorize() By Polymorphism, each payment should authorize itselfCashPaymentauthorize()PaymentamountoWho should be responsible for authorising different kinds of payments?authorize()Monopoly Problem: Example 3How to Design for Different Square Actions?14Applying Polymorphism to the
11、Monopoly problem15Applying Polymorphism16The GoSquare case17The RegularSquare case18The IncomeTaxSquare case19The GoToJailSquare case20Improving the Coupling21Iteration-2: Improved DCD22Iteration-2: Improved Interaction Diagram23DiscussionoPolymorphism is a fundamental principles in designing how a
12、system is organized to handle similar variations. oA design based on assigning responsibilities by Polymorphism can be easily extended to handle new variations. oContradications nSometimes, developers design systems with interfaces and polymorphism for speculative future-proofing against an unknown
13、possible variation. oBenefits nExtensions required for new variations are easy to add nNew implementations can be introduced without affecting clients2425Pure FabricationoProblem:What object should have the responsibility, when you do not want to violate High Cohesion and Low Coupling, or other goal
14、s, but solutions offered by Expert (for example) are not appropriate?oSolution:Assign a highly cohesive set of responsibilities to an artificial class that does not represent anything in the problem domain, in order to support high cohesion, low coupling, and reuse. Benefits:nHigh cohesion is suppor
15、ted because responsibilities are factored into a class that only focuses on a very specific set of related tasks.nReuse potential may be increased because of the presence of fine grained Pure Fabrication classes.26Example :oSuppose, in the POS example, that support is needed to save Sale instances i
16、n a relational database. By Expert, there is some justification to assign this responsibility to Sale class. However.nThe task requires a relatively large number of supporting database-oriented operations and the Sale class becomes incohesive.nThe sale class has to be coupled to the relational datab
17、ase increasing its coupling.nSaving objects in a relational database is a very general task for which many classes need support. Placing these responsibilities in the Sale class suggests there is going to be poor reuse or lots of duplication in other classes that do the same thing. 27Pure Fabricatio
18、n : Example 1PersistentStoragesave()By Pure FabricationoThe Sale remains well design, with high cohesion and low couplingoThe PersistentStorage class is itself relatively cohesiveoThe PersistentStorage class is a very generic and reusable objectPure Fabrication:Example 2 o Monopoly Problem: Handling
19、 the Dice282930Pure Fabricationo Preserves low coupling and high cohesion of classeso Improve reusability of classesNote: All the GoF patterns involve fabricating new classes-e.g. observer, adapter, abstract factory, etc.31IndirectionoProblem:Where to assign a responsibility, to avoid direct couplin
20、g between two (or more) things? How to de-couple objects so that low coupling is supported and reuse potential remains higher?oSolution:Assign the responsibility to an intermediate object to mediate between other components or services, so that they are not directly coupled. 32Example1 : PersistentS
21、torageoThe Pure fabrication example of de-coupling the Sale from the relational database services through the introduction of a PersistentStorage is also an example of assigning responsibilities to support Indirection. oThe PersistentStorage acts as a intermediary between the Sale and databaseExampl
22、e2: TaxCalculatorAdapter33Indirection : Example3oConsider a CreditAuthorizationService class that needs to use a ModemnBad approach: Put low-level calls to the Modem API directly in the methods of the CreditAuthorizationClassnBetter approach: Add an intermediate Modem class that insulates CreditAuth
23、orizationClass from the Modem API3435Indirection : Example3Modemdial( )receive( )send( )By IndirectionModem:dial(phoneNum):OS_OpenPort(1);:OS_Dial(phoneNUM)CreditAuthorizationServiceModem1:dial(phoneNum)authorize(payment)36Indirectiono Low couplingo Promotes reusabilityProtected VariationoProblem: H
24、ow do we design objects and systems so that instability in them does not have undesirable effects on other elements?oInstability here doesnt mean “crashy”. It means prone to change or evolve.oSolution: Identify points of predicted instability (variation) and assign responsibilities to create a stabl
25、e interface around them37Key ConceptExample: ITaxCalculatorAdapter oInstability or variation ndifferent interfaces or APIs of external tax calculators.nintegrate with many existing tax calculator systems, and also with future third-party calculators not yet in existence.oBy adding a level of indirec
26、tion, an interface, and using polymorphism with various ITaxCalculatorAdapter implementations, protection within the system from variations in external APIs is achieved. nInternal objects collaborate with a stable interface; the various adapter implementations hide the variations to the external sys
27、tems.38Protected Variation is Pervasive in ComputingoVirtual machines and operating systemsoData-driven designs (e.g., configuration files)oLiskov Substitution PrincipleoLSP Liskov88 formalizes the principle of protection against variations in different implementations of an interface, or subclass e
28、xtensions of a superclass.nTo quote:nIf for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2 then S is a subtype of T Liskov88.npublic void getTaxes( ITaxCalculatorAdapter calcula
29、tor, Sale sale ) List taxLineItems = calculator.getTaxes( sale ); / . 3940Law of Demeter“Dont Talk to Strangers”oProblem:To avoid knowing about the structure of indirect objects?oSolution:If two classes have no other reason to be directly aware of each other or otherwise coupled, then the two classe
30、s should not directly interact.Special Case of PV41Law of DemeterIt states that within a method, messages should only be sent to the following objects:nThe this object (or self)nA parameter of the methodnAn attribute of selfnAn element of a collection which is an attribute of selfnAn object created
31、within the methodBetter: Dont talk to strangers who seem unstableThis guideline warns against code like:osale.getPayment().getAccount().getAccountHolder()42Law of Demeter : ExampleRegisterpaymentAmount () : FloatendSale ()enteritem ()makePayment ()11Saledate : DateisComplete : Booleantime : Timebeco
32、meComplete ()makeLineitem ()makepayment ()payment () : Paymenttotal () : Float11PaymentamountTenderedamountTendered () : Float11 11CapturesPaid-by43Violates Law of Demeter : Example:Sale1:prnt:=payment() : payment:Registerprnt:Payment1.1:amt:=amountTendered():Floatamt:=paymentAmount():Float Register
33、 :PaymentAmount()prnt:= m_sale-Payment()/Violates Law of DMreturn prnt-amountTendered();Violates Law of DMprnt is a Stranger to POST44Support Law of demeter1:prnt:=payment() : payment1.1:amt:=amountTendered():Floatamt:=paymentAmount():Float Supports the Law of Demeter: Registerprnt:Payment:SaleRegister : PaymentAmount()return m_sale - PaymentAmount();Saledate : DateisComplete : Booleantime : TimebecomeC
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 三年级上册信息技术教学设计-7.装扮美丽的花园∣粤教版
- 2024年届九年级历史上册 第15课 决定美利坚命运的内战说课稿1 北师大版
- 单元学习总结教学设计-2025-2026学年高中信息技术教科版2019选择性必修4 人工智能初步-教科版2019
- 2025年中考数学试题分类汇编:勾股定理与翻折、动点、最值问题(10大考点40题) (第1期)解析版
- (2025秋新版)苏教版科学三年级上册全册教案2
- 小学科学新教科版三年级上册全册教案(2025秋新版)
- 神奇的泡泡 教学设计-2023-2024学年小学生科学课后服务拓展
- 人教版 2019年第二学期高中物理必修2 7.8 机械能守恒定律 教学设计
- 2025年中考地理试题分类汇编:西半球的地区和国家、极地地区、地区综合(第1期)解析版
- 本章复习与测试教学设计-2025-2026学年初中数学鲁教版五四制2012六年级下册-鲁教版五四制2012
- 14 《中国胰岛素泵治疗指南(2021年版)》要点解读
- 幼儿园内大事记表模板
- GB/T 38049-2019船用内燃机油
- 食源性疾病暴发调查指南及案例分析
- 中国天麻产量、进出口及发展趋势分析
- 盐碱地改造报告精要
- 企业合规管理培训课件讲义
- 幼儿园大班美术:《线条画:花》课件
- 燃气具安装维修工(中级)教学课件完整版
- 适龄儿童免(缓)学申请表
- 小学综合实践一年级上册各单元教材分析及全一册全部教案
评论
0/150
提交评论