软件工程Ch11.ppt
1,Chapter 11Component-Level Design(构件设计),2,What is a Component?,OMG Unified Modeling Language Specification OMG01 defines a component as“a modular,deployable,and replaceable part of a system that encapsulates implementation and exposes a set of interfaces.”(一个封装了实现细节而向外提供了一系列接口的可被布置和替代的模块)OO view(面向对象观点):a component contains a set of collaborating(协作)classesConventional view(常规观点):logic(逻辑的),the internal data structures that are required to implement the processing logic,and an interface that enables the component to be invoked and data to be passed to it.(内部数据结构要实现处理逻辑,接口允许部件被调用及进行数据传递),3,OO Component,4,Conventional Component,5,Basic Design Principles,The Open-Closed Principle(OCP).“A module component should be open for extension but closed for modification.(对外可扩展,对内不修改)The Liskov Substitution Principle(LSP).“Subclasses should be substitutable for their base classes.(子类能代替基类)Dependency Inversion Principle(DIP).“Depend on abstractions.Do not depend on concretions.”(依赖抽象,不依赖具体)The Interface Segregation Principle(ISP).“Many client-specific interfaces are better than one general purpose interface.(对某些客户专用的界面比通用界面好)The Release Reuse Equivalency Principle(REP).“The granule of reuse is the granule of release.”(复用的粒度就是发布的粒度)The Common Closure Principle(CCP).“Classes that change together belong together.”(共同封原则:一同变更的类应该打包在一起)The Common Reuse Principle(CRP).“Classes that arent reused together should not be grouped together.”(共同利用原则:不一起利用的类不放在一个分组内),6,Design Guidelines,ComponentsNaming conventions should be established for components that are specified as part of the architectural model and then refined and elaborated as part of the component-level model(命名方式应该是作为体系结构模型的一个部分,并对其做进一步的精化)Interfaces Interfaces provide important information about communication and collaboration(as well as helping us to achieve the OPC)接口提供关于通讯和协作的重要信息,7,Cohesion(内聚),Conventional view:the“single-mindedness”of a module(专诚性)OO view:cohesion implies(暗指)that a component or class encapsulates only attributes and operations that are closely related to one another and to the class or component itselfLevels of cohesionFunctional(功能性)Layer(层)Communicational(通讯)Sequential(顺序)Procedural(过程)Temporal(暂时)Utility(实用),These courseware materials are to be used in conjunction with Software Engineering:A Practitioners Approach,6/e and are provided with permission by R.S.Pressman&Associates,Inc.,copyright 1996,2001,2005,8,Coupling(耦合),Conventional view:The degree(程度)to which a component is connected to other components and to the external worldOO view:a qualitative(定性的)measure of the degree to which classes are connected to one anotherLevel of couplingContent(内容)Common(共用)Control(控制)Stamp(印记)Data(数据)Routine call(例程调用)Type use(类型使用)Inclusion or import(包含或导入)External(外部),These courseware materials are to be used in conjunction with Software Engineering:A Practitioners Approach,6/e and are provided with permission by R.S.Pressman&Associates,Inc.,copyright 1996,2001,2005,9,Component Level Design-I,Step 1.Identify all design classes that correspond to the problem domain.Step 2.Identify all design classes that correspond to the infrastructure domain.Step 3.Elaborate all design classes that are not acquired as reusable components.Step 3a.Specify message details when classes or component collaborate.Step 3b.Identify appropriate interfaces for each component.,These courseware materials are to be used in conjunction with Software Engineering:A Practitioners Approach,6/e and are provided with permission by R.S.Pressman&Associates,Inc.,copyright 1996,2001,2005,10,Component-Level Design-II,Step 3c.Elaborate attributes and define data types and data structures required to implement them.Step 3d.Describe processing flow within each operation in detail.Step 4.Describe persistent data sources(databases and files)and identify the classes required to manage them.Step 5.Develop and elaborate behavioral representations for a class or component.Step 6.Elaborate deployment diagrams to provide additional implementation detail.Step 7.Factor every component-level design representation and always consider alternatives.,These courseware materials are to be used in conjunction with Software Engineering:A Practitioners Approach,6/e and are provided with permission by R.S.Pressman&Associates,Inc.,copyright 1996,2001,2005,11,Collaboration Diagram,These courseware materials are to be used in conjunction with Software Engineering:A Practitioners Approach,6/e and are provided with permission by R.S.Pressman&Associates,Inc.,copyright 1996,2001,2005,12,Refactoring,These courseware materials are to be used in conjunction with Software Engineering:A Practitioners Approach,6/e and are provided with permission by R.S.Pressman&Associates,Inc.,copyright 1996,2001,2005,13,Activity Diagram,These courseware materials are to be used in conjunction with Software Engineering:A Practitioners Approach,6/e and are provided with permission by R.S.Pressman&Associates,Inc.,copyright 1996,2001,2005,14,Statechart,These courseware materials are to be used in conjunction with Software Engineering:A Practitioners Approach,6/e and are provided with permission by R.S.Pressman&Associates,Inc.,copyright 1996,2001,2005,15,Object Constraint Language(OCL),complements UML by allowing a software engineer to use a formal grammar and syntax to construct unambiguous statements about various design model elementssimplest OCL language statements are constructed in four parts:(1)a context that defines the limited situation in which the statement is valid;(2)a property that represents some characteristics of the context(e.g.,if the context is a class,a property might be an attribute)(3)an operation(e.g.,arithmetic,set-oriented)that manipulates or qualifies a property,and(4)keywords(e.g.,if,then,else,and,or,not,implies)that are used to specify conditional expressions.,These courseware materials are to be used in conjunction with Software Engineering:A Practitioners Approach,6/e and are provided with permission by R.S.Pressman&Associates,Inc.,copyright 1996,2001,2005,16,OCL Example,context PrintJob:validate(upperCostBound:Integer,custDeliveryReq:Integer)pre:upperCostBound 0 and custDeliveryReq 0 and self.jobAuthorization=no post:if self.totalJobCost=upperCostBound and self.deliveryDate=custDeliveryReq then self.jobAuthorization=yes endif,These courseware materials are to be used in conjunction with Software Engineering:A Practitioners Approach,6/e and are provided with permission by R.S.Pressman&Associates,Inc.,copyright 1996,2001,2005,17,Algorithm Design,the closest design activity to codingthe approach:review the design description for the componentuse stepwise refinement to develop algorithmuse structured programming to implement procedural logicuse formal methods to prove logic,These courseware materials are to be used in conjunction with Software Engineering:A Practitioners Approach,6/e and are provided with permission by R.S.Pressman&Associates,Inc.,copyright 1996,2001,2005,18,Stepwise Refinement,open,walk to door;,reach for knob;,open door;,walk through;,close door.,repeat until door opens,turn knob clockwise;,if knob doesnt turn,then,take key out;,find correct key;,insert in lock;,endif,pull/push doormove out of way;,end repeat,These courseware materials are to be used in conjunction with Software Engineering:A Practitioners Approach,6/e and are provided with permission by R.S.Pressman&Associates,Inc.,copyright 1996,2001,2005,19,Algorithm Design Model,represents the algorithm at a level of detail that can be reviewed for qualityoptions:graphical(e.g.flowchart,box diagram)pseudocode(e.g.,PDL).choice of manyprogramming languagedecision tableconduct walkthrough to assess quality,These courseware materials are to be used in conjunction with Software Engineering:A Practitioners Approach,6/e and are provided with permission by R.S.Pressman&Associates,Inc.,copyright 1996,2001,2005,20,Structured Programmingfor Procedural Design,uses a limited set of logical constructs:,sequence,conditional,if-then-else,select-case,loops,do-while,repeat until,leads to more readable,testable code,important for achieving high quality,but not enough,can be used in conjunction with proof of correctness,These courseware materials are to be used in conjunction with Software Engineering:A Practitioners Approach,6/e and are provided with permission by R.S.Pressman&Associates,Inc.,copyright 1996,2001,2005,21,A Structured Procedural Design,These courseware materials are to be used in conjunction with Software Engineering:A Practitioners Approach,6/e and are provided with permission by R.S.Pressman&Associates,Inc.,copyright 1996,2001,2005,22,Decision Table,These courseware materials are to be used in conjunction with Software Engineering:A Practitioners Approach,6/e and are provided with permission by R.S.Pressman&Associates,Inc.,copyright 1996,2001,2005,23,Program Design Language(PDL),These courseware materials are to be used in conjunction with Software Engineering:A Practitioners Approach,6/e and are provided with permission by R.S.Pressman&Associates,Inc.,copyright 1996,2001,2005,24,Why Design Language?,