资源描述
,Click to edit Master title style,Click to edit Master text styles,Second level,Third level,Fourth level,Fifth level,These slides are designed to accompany,Software Engineering:A Practitioners Approach,7/e,(McGraw-Hill,2009).Slides copyright 2009 by Roger Pressman.,*,Click to edit Master title style,Click to edit Master text styles,Second level,Third level,Fourth level,Fifth level,*,1,Chapter 10,Component-Level Design,Software Engineering:A Practitioners Approach,7/e,by Roger S.Pressman,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 classes,Conventional 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 passed to it.,3,OO Component,4,Conventional Component,5,Conventional Component,6,Basic Design Principles,Open-Closed Principle(开闭原则).,“A module component should be open for extension but closed for modification.,Substitution 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 interface.,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,Design Guidelines,Components,Naming 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),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).,8,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.,Levels of cohesion(内聚度依次递减),Functional,Layer,Communicational,Sequential,Procedural,Temporal,设计目标:模块内各动作的内聚度越高越好。,9,Coupling(耦合度),Conventional view:,The degree to which,a module is connected to other modules,and to the external world,OO view:,a qualitative measure of the degree to which classes are connected to one another,Level of coupling(耦合度依次递减),Content,Common,Control,Data,Routine call,External,设计目标:模块之间的耦合度越底越好。,10,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,.(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,collaborate.(Collaboration,Diagram with messages is shown),11,Component Level Design-I,Step 3b.Identify appropriate,interfaces,for each component,.,下图为PrintJob重构类和接口定义,Step 3c.Elaborate,attributes,and define data types and data structures required to implement them.,12,Component-Level Design-II,Step 3d.,Describe,processing flow within each operation,in detail,.,实例:右图为ComputePaperCost()操作的Activity Diagram.,13,Component-Level Design-III,Step 4.Describe,data sources,(database)and identify the,classes required to manage them.,Step 5.Develop and elaborate,behavioral representations,for a class or component.(右图为PrintJob类的State Chart),Step 6.Elaborate,deployment diagrams,to provide additional implementation detail.,14,Algorithm Design Model,represents the algorithm at a level of detail that can be reviewed for quality,options:,decision table/tree,graphical,(e.g.flowchart,box diagram),PAD,(Program Analysis Diagram),pseudocode,(e.g.PDL),15,Decision Table,10/7/2024,16,Flowchart,17,NS(Box)Diagram,18,Program Analysis Diagram(PAD),19,Program Analysis Diagram(PAD),例:模块binary(x,v,n,p)完成判断一个特定值x是否出现在已经按递增顺序排好序的数组v中。如果存在则返回相应下标,mid,,否则返回值-1。,20,Program Design Language(PDL),10/7/2024,21,Program Design Language(PDL),22,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 door,move out of way;,end repeat,23,Designing Conventional Components,The design of,processing logic,is governed by the basic principles of algorithm design and structured programming,The design of
展开阅读全文