14 Component-Level Design
14 Component-Level Design
14 Component-Level Design
Component-Level Design
Slide Set to accompany
Software Engineering: A Practitioner’s
Approach, 8/e
by Roger S. Pressman and Bruce R. Maxim
All copyright information MUST appear if these slides are posted on a website for student
use.
Prin t Jo b
Component n u m b e rOf Pa g e s
n u m b e rOf Sid e s
p a p e rTy p e
m a g n if ic a t io n
p ro d u c t io n Fe a t u re s
d e sig n c o m p o n e n t
c o m p u t e Jo b Co st( ) c o m p u t e Jo b
p a ssJo b t o Prin t e r( )
Prin t Jo b
in it ia t e Jo b
5
Vinod: Nope. Doug wants to know Shakira: Knowing Doug, he'll keep
how much time it's going to take to us focused and not deliver the
add it to the security function. doggie thing until the next release.
Shakira (thinking a moment): Not Vinod: That's not a bad thing, but
much ... look. [She shows Vinod can you implement now if he wants
Figure 11.4] We've isolated the you to?
actual sensor classes behind the Shakira: Yeah, the way we designed
sensor interface. As long as we the interface lets me do it with no
have specs for the doggie sensor, hassle.
adding it should be a piece of cake. Vinod: have you ever heard of the
Only thing I'll have to do is create an
open-closed principle?
appropriate component ... uh, class,
for it. No change to the Detector
Shakira: Never heard of it
component at all. Vinod (smiling): Not a problem
Vinod: So I'll tell Doug it's no big
<<interface
deal >>
Sensor
read() Detecto
enable() r
disable()
test()
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 OCP)
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).
10
Cohesion in Action (pg 297)
The scene: Ed: We originally defined five
Jamie's cubicle. operations for camera. Look ...
The players: [shows Jamie the list]
Jamie, Ed determineType() tells me the type of
members of the SafeHome software camera.
engineering team who are working on translateLocation() allows me to move
the surveillance function. the camera around the floor plan.
displayID() gets the camera ID and
The conversation: displays it near the camera icon.
Ed: I have a first-cut design of the displayView() shows me the field of
camera component. view of the camera graphically.
displayZoom() shows me the
Jamie: Wanna do a quick review?
magnification of the camera
Ed: I guess ... but really, I'd like graphically.
your input on something. Ed: I've designed each separately,
(Jamie gestures for him to and they're pretty simple
continue.) operations. So I thought
11
11
it might be a good idea to combine Ed (mildly exasperated): So
all of the display operations into what? The whole thing will be less
just one that's called than 100 source lines, max. It'll be
displayCamera()--it'll show the ID, easier to implement, I think.
the view, and the zoom. Jamie: And what if marketing
Whaddaya think? decides to change the way that we
Jamie (grimacing): Not sure represent the view field?
that's such a good idea. Ed: I'll just jump into the
Ed (frowning): Why? All of these displayCamera() op and make the
little ops can cause headaches. mod.
Jamie: The problem with Jamie: What about side effects?
combining them is we lose Ed: Whaddaya mean?
cohesion. You know, the Jamie: Well, say you make the
displayCamera() op won't be
change but inadvertently create a
single-minded.
problem with the ID display.
12
12
Ed: I wouldn't be that sloppy. Jamie: Good decision.
Jamie: Maybe not, but what if
some support person two years
from now has to make the mod.
He might not understand the op as
well as you do and, who knows,
he might be sloppy.
Ed: So you're against it?
Jamie: You're the designer . . . it's
your decision . . . just be sure you
understand the consequences of
low cohesion.
Ed (thinking a moment): Maybe
we'll go with separate display ops.
13
13
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: one component modifies data of another component
Common: when components make use of a global variable
Control: A() invokes B() and passes a control flag to B
Routine call: one op invokes another
Type use: class A uses a data type defined in class B
Inclusion or import
External coupling: when a component collaborates with infrastructure
ocmponents
14
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.
Ex. GUI components, OS components, object & data management
components, etc
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.
Step 3c. Elaborate attributes and define data types and data structures
required to implement them.
Step 3d. Describe processing flow (activity diagram) within each
operation in detail.
15
Component-Level Design-II
Step 4. Describe persistent data sources (databases
and files) and identify the classes required to manage
them.
Step 5. Develop and elaborate behavioral
representations (statechart) 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.
16
Collaboration Diagram
:ProductionJob
1: buildJob ( WOnumber )
2: submitJob ( WOnumber )
:WorkOrder
:JobQueue
PrintJo b
initiateJo b
Wo rkOrd er
ap p ro p riat e at t rib u t e s <<interface>>
g etJo b Descriip tio n b uild Jo b initiateJo b
b uild Wo rkOrd er ()
p assJ o b To Pro d u ct io n ( )
Pro d uctio nJo b
sub mitJo b
Jo b Queue
ap p ro p riat e at t rib u t e s
checkPrio rity ()
18
va lida t e a t t ribut e s
input
re t urns ba s e C os t pe rPa ge
pa pe rC os t pe rPa ge =
ba s e C os t pe rPa ge
s iz e = B pa pe rC os t pe rPa ge =
pa pe rC os t pe rPa ge *1 . 2
s iz e = C pa pe rC os t pe rPa ge =
pa pe rC os t pe rPa ge *1 . 4
s iz e = D pa pe rC os t pe rPa ge =
pa pe rC os t pe rPa ge *1 . 6
c olor is c us t om
pa pe rC os t pe rPa ge =
pa pe rC os t pe rPa ge *1 . 1 4
c olor is s t a nda rd
re t urns
( pa pe rC os t pe rPa ge )
19
b eh avio r w it h in t h e
st at e b u ild in g Jo b Dat a
Statechar
d at aIn p u t In co mp let e
buildingJ obDa t a
e nt ry/ re a dJ obDa t a ()
e xit / dis pla yJ obDa t a ()
e nt ry/ c omput e J ob
e xit / s a ve t ot a lJ obCos t
formingJ ob
e nt ry/ buildJ ob
e xit / s a ve WOnumbe r
do/
s ubmit t ingJ ob
e nt ry/ s ubmit J ob
e xit / init ia t e J ob
do/ pla c e on J obQue ue
Reusable
Domain Software
Architecture Artifact
Analysis
Development Development
Repository
Domain Structural Reusable
model Model Artifacts/
Components
Software Engineering
System Specification
& Construction
Analysis
User Design
Requirements
Analysis Application
System
& Design
Spec Models Software
Server
LAN Objects
ORB Core
Server
ORB Object
interface IDL Adapter
Stubs Interface
Repository