Sie sind auf Seite 1von 24

Software Engineering: A Practitioner’s Approach, 6/e

Chapter 11
Component­Level Design
copyright © 1996, 2001, 2005
R.S. Pressman & Associates, Inc.

For University Use Only


May be reproduced ONLY for student use at the university level
when used in conjunction with Software Engineering: A Practitioner's Approach.
Any other reproduction or use is expressly prohibited.

These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 1
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:  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.

These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 2
OO Component
analysis c lass

Print J ob

numberOf Pages
numberOf Sides
paperType
magnif ic at ion
produc t ionFeat ures

design c omponent
c omput eJ obCost( ) c omput eJ ob
passJ obt oPrint er( )

Print J ob

init iat eJ ob

<<in t erf ace>> elaborated design class


co mp u t eJ o b
PrintJ ob
comput ePageCost ( ) numberOf Pages
comput ePaperCost ( ) numberOf Sides
comput eProdCost ( ) paperType
comput eTot alJ obCost ( ) paperWeight
paperSize
paperColor
magnif icat ion
colorRequirement s
product ionFeat ures
collat ionOpt ions
bindingOpt ions
coverSt ock
<<in t erf ace>> bleed
in it iat eJ o b priorit y
t ot alJ obCost
buildWorkOrder( ) WOnumber
checkPriorit y ( )
passJ obt o Product ion( ) comput ePageCost ( )
comput ePaperCost ( )
comput eProdCost ( )
comput eTot alJ obCost ( )
buildWorkOrder( )
checkPriorit y ( )
passJ obt o Product ion( )

These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 3
Conventional Component
design component
getJ obData

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: job size
in: color=1, 2, 3, 4
in: pageSize = A, B, C, B
out : BPC
out : SF

get J obDat a ( numberPages,numberDocs,


sides, color, pageSize, pageCost ) job size ( J S) =
accessCost sDB (jobSize, color, pageSize, numberPages * numberDocs;
BPC, SF) lookup base page cost (BPC) -->
comput ePageCost( ) accessCost sDB ( J S, color) ;
lookup size fact or ( SF) -->
accessCost DB ( J S, color, size)
job complexit y factor ( J CF) =
1 + [ ( sides-1) * sideCost + SF]
pagecost = BPC * J CF

These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 4
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 aren’t reused together should not 
be grouped together.” 

Source:  Martin, R., “Design Principles and Design Patterns,” downloaded from http:www.objectmentor.com, 2000.

These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 5
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).

These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 6
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 itself
 Levels of cohesion
 Functional
 Layer
 Communicational
 Sequential
 Procedural
 Temporal
 utility

These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 7
Coupling
 Conventional view: 
 The degree to which a component is connected to other 
components 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
 Stamp
 Data
 Routine call
 Type use
 Inclusion or import
 External

These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 8
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 Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 9
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 Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 10
Collaboration Diagram

:ProductionJob

1: buildJob (WOnumber)
2: submitJob (WOnumber)

:WorkOrder

:JobQueue

These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 11
Refactoring
computeJ ob

PrintJ ob
initiateJ ob

WorkOrder
appropriat e at t ribut es <<interface>>
getJ obDescriiption buildJ ob initiateJ ob
buildWorkOrder ()
passJ obToProduct ion( )
ProductionJ ob

submitJ ob
J obQueue
appropriat e at t ribut es

checkPriority ()

These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 12
Activity Diagram
validate attributes
input

accessPaperDB (weight)

returns baseC ostperPage

paperC ostperPage =
baseC ostperPage

size = B paperC ostperPage =


paperC ostperPage * 1 .2

size = C paperC ostperPage =


paperC ostperPage * 1 .4

size = D paperC ostperPage =


paperC ostperPage * 1 .6

color is custom
paperC ostperPage =
paperC ostperPage * 1 .1 4

color is standard

returns
( paperC ostperPage )

These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 13
Statechart
behavior wit hin t he
state buildingJ obDat a

dat aInput Incomplet e


buildingJ obData

entry/ readJ obData ()


exit/displayJ obData ()
do/ checkConsistency()
include/ dataInput

dat aInput Complet ed [ all dat a


it ems consist ent ] / displayUserOpt ions

computingJ obCost

entry/ computeJ ob
exit/ save totalJ obCost

jobCost Accept ed [ cust omer is aut horized] /


get Elect ronicSignat ure

formingJ ob

entry/ buildJ ob
exit/ save WOnumber
do/

submittingJ ob

entry/ submitJ ob
exit/initiateJ ob
do/ place on J obQueue

jobSubmit ted[all aut horizations acquired] /


printWorkOrder

These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 14
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 elements
 simplest 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 Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 15
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 Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 16
Algorithm Design
 the closest design activity to coding
 the approach:
 review the design description for the 
component
 use stepwise refinement to develop algorithm
 use structured programming to implement 
procedural logic
 use ‘formal methods’ to prove logic

These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 17
Stepwise Refinement
open

walk to door;
reach for knob;
open door; repeat until door opens
turn knob clockwise;
walk through; if knob doesn't turn, then
close door.     take key out;
    find correct key;
    insert in lock;
endif
pull/push door
move out of way;
end repeat

These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 18
Algorithm Design Model
 represents the algorithm at a level of detail 
that can be reviewed for quality
 options:
 graphical (e.g. flowchart, box diagram)
 pseudocode (e.g., PDL)  ...   choice of many
 programming language
 decision table
 conduct walkthrough to assess quality

These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 19
Structured Programming
for 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
can be used in conjunction with ‘proof of 
correctness’
important for achieving high quality, 
but not enough

These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 20
A Structured Procedural Design
add a condition Z, 
a if true, exit the program

x1

b x2 c

x3 d

f e

x4

x5

These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 21
Decision Table
Rules

Conditions 1 2 3 4 5 6

regular customer T T

silver customer T T

gold customer T T

special discount F T F T F T

Rules

no discount

apply 8 percent discount

apply 15 percent discount

apply additional x percent discount

These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 22
Program Design Language (PDL)
if condition x 
  then process a; 
  else process b; 
endif 
if­then­else PDL
easy to combine with source code 
 
machine readable, no need for graphics input 
 
graphics can be generated from PDL 
 
enables declaration of data as well as procedure 
 
easier to maintain

These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 23
Why Design Language?
can be a derivative of the HOL of choice 
e.g., Ada PDL 
 
machine readable and processable 
 
can be embedded with source code,  
therefore easier to maintain 
 
can be represented in great detail, if 
designer and coder are different 
 
easy to review

These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and 
are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 24

Das könnte Ihnen auch gefallen