软件工程-实践者的研究方法 (9)
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
OO view:
Level of coupling(耦合度依次递减) Content Common Control Data Routine call External 设计目标: 模块之间的耦合度越底越好。
9
Component Level Design-I
Conventional view:
The degree to which a module is connected to other modules and to the external world a qualitative measure of the degree to which classes are connected to one another
design component getJobData ComputePageCost accessCostsDB
elaborated module PageCost
in: numberPages in: numberDocs in: sides= 1, 2 in: color=1, 2 , 3, 4 in: page size = A, B, C, B out : page cost in: j ob size in: color=1, 2, 3, 4 in: pageSize = A, B, C, B out : BPC out : SF get JobDat a ( num berPages, num berDocs, sides, color, pageSize, pageCost ) accessCost sDB (j obSize, color, page Size, BPC, SF) com put ePageCost( )
5
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 clientspecific 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 aren’t reused together should not be grouped together.”
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.
“… 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.
job size ( JS) = num berPages * num berDocs; lookup base page cost ( BPC) --> accessCost sDB ( JS, color) ; lookup size fact or ( SF) --> accessCost DB ( JS, color, size) j ob com ple xit y fact or ( JCF) = 1 + [ ( sides-1) * sideCost + SF] pagecost = BPC * JCF
elaborat ed design class Print Job
number Of Pages number Of Sides paper Type paper Weight paper Size paper Color magnif icat ion color Requir ement s pr oduct ionFeat ur es collat ionOpt ions bindingOpt ions cover St ock bleed pr ior it y t ot alJobCost WOnumber comput ePageCost ( ) comput ePaper Cost ( ) comput ePr odCost ( ) comput eTot alJobCost ( ) buildWor kOr der ( ) checkPr ior it y ( ) passJobt o Pr oduct ion( )
Step 3a. Specify message details when classes or component collaborate. (Collaboration Diagram with messages is shown)
10
Component Level Design-I
Step 3b. Identify appropriate interfaces for each component. 下图为PrintJob重构类和接口定义
Print Jo b
init ia t e Job
< < in t er f ace> > co m p u t eJo b comput ePageCost ( ) comput ePaper Cost ( ) comput ePr odCost ( ) comput eTot alJobCost ( )
OO view:
Levels of cohesion(内聚度依次递减) Functional Layer Communicational Sequential Procedural Temporal 设计目标: 模块内各动作的内聚度越高越好。
8
Coupling(耦合度)
Chapter 10
Component-Level Design
Software Engineering: A Practitioner’s Approach, 7/e
by Roger S. Pressman
1
What is a Component?
OMG Unified Modeling Language Specification [OMG01] defines a component as
6
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).
< < in t er f ace> > in it iat eJo b buildWor kOr der ( ) checkPr ior it y ( ) passJobt o Pr oduct ion( )
3
Conventional Component
4
Conventional Component
7
Cohesion(内聚度)
Conventional view:
the “single-mindedness” of a module cohesion implies that a component or class encapsulates only attributes and operations that are closely related to one another.
2
OO Component
an aly sis c lass Prin t Jo b nu m b erOf Pag es nu m b erOf Sid es pa pe rTy pe m a gn if ic a t io n pro du c t ion Fe at ure s d esign c o m po ne nt c o m p ut eJo bCost( ) pa ssJob t o Prin t e r( ) c om p ut e Jo b
实例: 右图为ComputePaperCost()操 作的Activity Diagram.
Step 3c. Elaborate attributes and define data types and data structures required to implement them.
11
Component-Level Design-II
Step 3d. Describe processing flow within each operation in detail.