软件工程英文教学课件:Ch10 Component-Level Design_第1页
软件工程英文教学课件:Ch10 Component-Level Design_第2页
软件工程英文教学课件:Ch10 Component-Level Design_第3页
软件工程英文教学课件:Ch10 Component-Level Design_第4页
软件工程英文教学课件:Ch10 Component-Level Design_第5页
已阅读5页,还剩35页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、1Chapter 10Component-Level DesignSoftware Engineering: A Practitioners Approach, 7/e by Roger S. Pressman 2What 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 expos

2、es a set of interfaces.”OO view: a component contains a set of collaborating classesConventional view: a component contains processing 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 pas

3、sed to it.3OO Component实例:自动印制车间的构件设计软件。左上:分析类中右:设计构件的UNL描述-含两个接口。右下:接口设计-含计算价格和下达任务。左下:构件设计-含全部属性和操作。4Conventional Component = Module5Conventional Component6Component Design PrinciplesOpen-Closed Principle (开闭原则). A module component should be open for extension but closed for modification.Substitut

4、ion Principle (替换原则). Subclasses should be substitutable for their base classes.Dependency Inversion Principle (依赖倒置原则). Depend on abstractions. Do not depend on concretions(具体).Interface Segregation Principle (接口分离原则). Many client-specific interfaces(专用接口) are better than one general purpose interf

5、ace.Release Reuse Equivalency Principle (发布和重用等价原则). The granule(粒度) of reuse is the granule of release.Common Closure Principle (共同封装原则). Classes that change together belong together.(同时变更的类应封装在一起) Common Reuse Principle (共同重用原则). Classes that arent reused together should not be grouped together. 7

6、Design GuidelinesComponentsNaming 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 modelInterfaces Interfaces provide important information about communication and collaboration (as w

7、ell as helping us to achieve the Open-Closed Principle)Dependencies and Inheritance(依赖与继承)it is a good idea to model dependencies from left to right and inheritance from bottom (derived classes) to top (base classes).8Cohesion(内聚-度量一个构件内操作间的关系)Conventional view: the “single-mindedness” of a moduleOO

8、 view: cohesion implies that a component or class encapsulates only attributes and operations that are closely related to one another.Levels of cohesion(内聚度依次递减)Functional cohesion - 模块的所有操作均实现统一功能Layer cohesion - 构件中高层可访问底层的服务,但底层不能访问高层的服务Communicational cohesion - 模块的所有操作均访问相同数据Sequential cohesion

9、Procedural cohesionTemporal cohesion设计目标: 模块内各动作的内聚度越高越好。9Coupling(耦合-度量相关构件间的操作关系)Conventional view: The degree to which a module is connected to other modules and to the external worldOO view:a qualitative measure of the degree to which classes are connected to one anotherLevel of coupling(耦合度依次递减

10、)Content-一个构件需要修改其他构件的内部数据Common-多个构件使用同一数据(如全局变量)Control-构件A直接向被调用的构件B发送控制标记Data-构件A直接向被调用的构件B发送数据参数 Routine call-构件A调用构件BExternal-构件与基础设施构件通讯(如OS,DB)设计目标: 模块之间的耦合度越底越好。10Component Level DesignStep 1. Identify all design classes that correspond to the problem domain. Step 2. Identify all design cla

11、sses that correspond to the infrastructure domain.(for example, GUI component, OS components)Step 3. Elaborate all design classes that are not acquired as reusable components,including the message, interface, attribute and operation.Step 3a. Specify message details when classes or component collabor

12、ate. (Collaboration Diagram with messages is shown) 左图-印制系统中准备印制任务的协作图-所涉及的3个对象类-带消息的协作关系11Component Level Design-IStep 3b. Identify appropriate interfaces for each component. 下图为PrintJob重构类和接口定义 Step 3c. Elaborate attributes and define data types and data structures required to implement them. 12Co

13、mponent-Level Design-IIStep 3d. Describe processing flow within each operation in detail.实例: 右图为ComputePaperCost()操作的Activity Diagram.13Component-Level Design-IIIStep 4. Describe data sources (database) and identify the classes required to manage them. Step 5. Elaborate behavioral representations fo

14、r a class or component.(右图为PrintJob类的State Chart)Step 6. Elaborate deployment diagrams to provide additional implementation detail. 14Algorithm Design Modelrepresents the algorithm at a level of detail that can be reviewed for qualityoptions:decision table/treegraphical (e.g. flowchart, box diagram)

15、PAD (Program Analysis Diagram )pseudocode (e.g. PDL)15Approach of Algorithm Designthe 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

16、 prove logic16Designing Conventional ComponentsThe design of processing logic is governed by the basic principles of algorithm design and structured programmingThe design of data structures is defined by the data model developed for the systemThe design of interfaces is governed by the collaboration

17、s that a component must effect 17Decision Table2022/7/1818Flowchart19NS (Box) Diagram20Program Analysis Diagram (PAD)21Program Analysis Diagram (PAD)例:模块binary(x,V,L)完成判断一个特定值x是否出现在已经按递增顺序排好序的数组V中。如果存在则返回相应下标mid,否则返回值-1。22Program Design Language (PDL)2022/7/1823Program Design Language (PDL)24Stepwis

18、e Refinementopenwalk to door;reach for knob;open door;walk through;close door.repeat until door opensturn knob clockwise;if knob doesnt turn, then take key out; find correct key; insert in lock;endifpull/push door;move out of way;end repeat2022/7/1825逐步求精方法示例:骑士周游问题。给出一块有n2个格子的棋盘。一位骑士放在初始坐标为(x0,y0)的

19、格子里,然后按照国际象棋的马的移动规则。问题是找到一种可以走遍整个棋盘的方案(如果这种方案存在),即计算一个n2-1次移动的周游,使得棋盘被遍历(即每一个格子恰好被访问过一次)。3241马5867kakbk1212123-124-215-2-16-1-271-282-1YX0PDL描述举例0表示格子x,y未被访问过i 表示格子x,y在第i次移动中被访问,1=i=n2hx,y =(1)数据结构设计:棋盘:用一个二维整型数组hi,j,i=1.n,j=1.n位置:马的移动位置有8种可能行(右上图)。设马的初始位置为(x,y),则:下一个移动位置为(x+ak,y+bk),其中k=1.8(右下图)。访问

20、标记:棋盘格子h x,y是否被访问过,可以用下面的方式记录: 2022/7/1826(2)算法设计:试探+回溯步1:初始化;步2:对给定的马的当前位置 调用“试探下步移动”;步3:if 下步移动成功 then步3.1: 打印移动结果; else步3.2: 打印无解 ednif “初始化”细化为:1.1马的8个可移动位置的差值分别按照前面表格中的值预先放在a、b数组中;1.2 棋盘hi,j在马未访问过时应该都预先置为0;1.3 马的最初位置可以是(1 ,1);此时该位置所确定的棋盘格子认为被访问过,因此应有h1,1=1。步3中对“下步移动成功”的判断可以对步2中“试探下步移动”即过程try(i,

21、x,y,q)调用结果的返回值q作判断即可: q为true即为移动成功, q为false即为移动失败。步3.1“打印移动结果”即输出数组hi,j 的各元素之值。其中i,j 的取值为1到n;步3.2“打印无解”即输出一个提示信息。PDL描述举例2022/7/1827(2)算法设计:试探+回溯步1:初始化;步2:对给定的马的当前位置 调用“试探下步移动”;步3:if 下步移动成功 then 步3.1: 打印移动结果; else步3.2: 打印无解。 endif 对于马的当前位置的下步移动应该有8个候选位置用K计数,候选次序是前面图示中的逆时针方向进行。一旦进入下一步即一个新的位置,同样又要“试探下步

22、移动”。如果本步移动成功,那么返回“真”,否则返回“假”。因此是一个递归过程try(i,x,y,q) 。2 “试探下步移动”可设为try(i,x,y,q) :2.0 做候选准备;2.1 repeat2.1.1 从下一步移动表中挑选出下一步候选位置;2.1.2 if 候选位置可接受 then 进行移动; endif2.2 until 移动成功或再无候选位置;2.3 返回移动成功与否的标志.马在当前位置而且在下步移动前,一个位置都没有试探过,因此k值应为0。8个候选位置试探完毕时k值应为8。PDL描述举例2 “试探下步移动”还需要细化:2.0 做候选准备;2.1 repeat2.1.1 从下一步移

23、动表中挑选出下一步候选位置2.1.2 if 候选位置可接受 then 进行移动 endif2.2 until 移动成功或再无候选位置;2.3 返回移动成功与否的标志.如果候选者的当前步为k,则候选者的下一步变为k+1。下一步的候选者“可接受”的条件应该是:u,v不能越界而且该步所处位置未被访问过,可表示为(1=u=n)and(1=v=n)and (hu,v=0)“进行移动”可以进一步细化为:记录移动;if 盘未走遍 then “试探下步移动”即为递归调用步2; if “试探下步移动”不成功 then 删去这一记录即回溯; else 用局部变量q1表示并赋true;

24、 endif endif设挑出的下一步候选位置为(u,v),则u用x+ak,v用y+bk替换。“移动成功”可把ture赋予局部变量q1;“再无候选者”意味着当前马的位置的下一步已经对可能的8个位置都试完了,因此可表示为k=8。移动成功与否可把变量q1的值赋予变量qPDL描述举例2022/7/182“进行移动”还需要细化:记录移动;if 盘未走遍 then “试探下步移动”即为递归调用步2; if “试探下步移动”不成功 then 删去这一记录; else 给q1赋值true; endif endif“记录移动”可以表示为:hu,v被赋予当前所试探的次数i。i是一个全局变量“盘未

25、走遍”可以表示为:in2“试探下步移动”应该是一个递归调用,可以表示为:try(i+1,x,y,q1)“试探下步移动不成功”可以表示为:NOT q1“删去这一记录”可以表示为:hu,v被赋予0PDL描述举例2022/7/1830PRAGRAM KNIGHTSTOUR/第1步:定义变量并初始化DECLARE n:as integer; q:as boolean;GET(n);DO-WHILE i=n DO-WHILE j=n hi,j=0; j=j+1; ENDDO i=i+1;ENDDOa1=2; b1=1; a2=1; b2=2;a3=-1;b3=2; a4=-2;b4=1;a5=-2;b5

26、=-1;a6=-1;b6=-2;a7=1; b7=-2;a8=2; b8=-1;/第2步 :试探下步移动h1,1=1;/指定开始位置try(2,1,1,q) ;/调用递归过程 /第3步: 输出结果IF q THEN DO-WHILE i=n DO-WHILE j=n PUT(hi,j); j=j+1; ENDDO PUT(换行符); i=i+1; ENDDOELSE PUT(“打印无解”);ENDIFENDPROG基于PDL描述获得最终算法/递归过程定义PROCEDURE try(i,x,y,q) DECLARE i,x,y:as integer ARG; q:as boolean ARG;/

27、第i步从位置x,y开始试探下一步 k=0; REPEAT UNTIL k=8 or q1 k=k+1;q1= FALSE;u=x+ak;v=y+bk;IF (1un)and (1vn) and (hu,v=0)THEN hu,v=i; IF in*n THEN try(i+1,u,v,q1);/继续试探 ENDIF IF NOT(q1) THEN hu,v=0;/试探不成功 ELSE q1=TRUE;/试探成功 ENDIFENDIF ENDREP q=q1;ENDPROC31Component-Based DevelopmentWhen faced with the possibility o

28、f reuse, the software team asks:Are commercial components available to implement the requirement?Are internally-developed reusable components available to implement the requirement?Are the interfaces for available components compatible within the architecture of the system to be built?强调重用而非构造构件-核心思

29、想是尽量利用现成构件实现系统功能。强调集成构件而非编码-主要完成构件的可用性检查、构件的适应性修改、以及构件的组装。323C Model for Component DevelopmentComponent-Based SE鼓励尽量使用现有软件构件集成新的软件系统,与此同时也提倡软件企业要不断开发积累暂时缺少的软件构件,以便今后重用。构件开发的3C模型:Concept: 构件概念描述“构件做什么?”Content: 构件内容描述“构件如何被实现?”Context: 构件环境描述“构件如何被应用?”33Component-Based SEA library of components must

30、be available.Components should have a consistent structure.Standards of component should exist, e.g.:OMG/CORBAMicrosoft COMSun JavaBeans34OMG/CORBAThe Object Management Group has published a common object request broker architecture (公共对象请求代理架构,简称OMG/CORBA). 服务端:An object request broker (ORB) provid

31、es services that enable reusable components (objects) to communicate with other components. 客户端:Objects within the client application request one or more services from the ORB server. Requests are made dynamically at run time. 接口:An interface contains all necessary information about the services request and response formats. CORBA架构图35基于CORBA的技术架构实例 统一接入平台的技术架构图 3637Microsoft COMThe component object model (COM组件对象模型) provides a specification for using components produced by various vendors(供应商) within an applicati

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论