CPSC 333 - DCU School of Computing

Download Report

Transcript CPSC 333 - DCU School of Computing

UML & Programming
•
•
•
•
Activity diagrams
Package diagrams
Deployment diagrams
Moving to code
CPSC 333 - Lecture 21
1
Activity diagrams
• Dynamic aspects of a
system
• Describe
• parallel processing
• workflows
• Show flow from activity to
activity
• Activity
conceptual: task to be done
specification/implementation:
method
Activity
[condition 1]
[condition 2]
Activity
Activity
[synchronization
condition]
Activity
CPSC 333 - Lecture 21
2
Activity
Example activity diagram
Put coffee
in filter
Add water
to reservoir
Put filter
in machine
Turn on
machine
CPSC 333 - Lecture 21
3
UML & Programming
• Package diagrams
• Deployment diagrams
• Moving to code
CPSC 333 - Lecture 21
4
How to break a system into
smaller systems?
• Roman principle: Divide & conquer
– Split up a large system into manageable
parts
• Structured methods: functional
decomposition
• OO: Group classes into higher level units
Packages
CPSC 333 - Lecture 21
5
Package diagrams
• Show packages
• Show dependencies between packages
Dependency exists between 2 elements if
changes to the definition of one element
may cause changes to the other
• Goal (& art) of large scale design:
Minimize dependencies
– Constraints effects of changes
CPSC 333 - Lecture 21
6
Example package diagram
Order Capture
UI
AWT
Mailing List
UI
Order Capture
Application
Orders
Mailing List
Application
Customers
CPSC 333 - Lecture 21
7
Package diagram for the
assignment
Project
Planning GUIs
Project Member
GUIs
Project Plan
Management
Resource Pool
Workflow Engine
Product Version
Management
CPSC 333 - Lecture 21
8
Dependencies between packages
Shields UI from Project Plan
Management
(Layered architecture)
• Exist whenever there exist a
dependency between classes of
both packages
– class A calls method of class B
– class A has instance of B as part
– method of A has parameter of type B
Project
Project Member
Planning GUIs
GUIs
Resource
Pool
Project
Plan
Management
Workflow
Engine
• Dependencies are not transitive
(compilation dependencies are)
Product Version
Management
CPSC 333 - Lecture 21
9
Nested packages
Order Capture
UI
AWT
Mailing List
UI
Order Capture
Application
Mailing List
Application
Domain
Orders
• 2 interpretations
– transparent: all
contents of contained
packages visible
– opaque: only classes
of the container are
visible
Customers
CPSC 333 - Lecture 21
10
How can the complexity of a
package interface be restricted?
• Give all classes in the package only
package visibility
• Define a public class that provides the
public behavior of the package
• Delegate the public operations to the
appropriate class inside the package
Facades [Gamma et al. 1994]
CPSC 333 - Lecture 21
11
Rules of thumb
• Try to avoid cycles in the dependency
structure
• Too many dependencies: Try to refactor
the system
• Use them when the system class diagram
is not legible on a single letter size sheet
of paper
CPSC 333 - Lecture 21
12
UML & Programming
• Package diagrams
• Deployment diagrams
• Moving to code
CPSC 333 - Lecture 21
13
Deployment diagrams (1)
• Show physical relationship among
software & hardware components
• Show where components of a distributed
system are located
CPSC 333 - Lecture 21
14
Deployment diagrams (2)
Client part
Jav a RMI
• Nodes: Computational units (most often:
Hardware)
• Connections: Communication paths over
which the system will interact
Serv er part
CPSC 333 - Lecture 21
15
UML & Programming
• Package diagrams
• Deployment diagrams
• Moving to code
CPSC 333 - Lecture 21
16
Example - classes & packages
Object
(from java.lang)
Traveling
Car
currentLocation : Location
builtDate : Date
Location
city
getCity( )
setCity( )
start( )
stop( )
goto( )
CPSC 333 - Lecture 21
17
Class definition
package Traveling;
Car
currentLocation : Location
builtDate : Date
start( )
stop( )
goto( )
Location
city
getCity( )
setCity( )
public class Car {
private Location currentLocation;
private java.sql.Date builtDate;
}
public class Location {
private java.lang.String city;
}
CPSC 333 - Lecture 21
18
Adding methods
Car
currentLocation : Location
builtDate : Date
public class Car {
private Location currentLocation;
private java.util.Calendar builtDate;
s tart ()
s top ()
goto (newloc : Location = Calgary)
Missing: accessing
methods
public void start ( ) {
return;
}
public void stop ( ) {
return;
}
public void gotoLocation (Location newLoc ) {
currentLocation = newLoc;
}
}
CPSC 333 - Lecture 21
19
Example - state diagram
start[ gas available ]
started
stopped
Additional attributes
needed!
state: String
gasAvailable: Boolean
stop
CPSC 333 - Lecture 21
20
State transitions
start engine[ gas available ]
started
stopped
stop engine
public class Car {
private Location currentLocation;
private java.util.Calendar builtDate;
private String state;
private boolean gasAvailable;
public void start ( ) {
if (gasAvailable) {state = "started";};
return;
}
public void stop ( ) {
state = "stopped";
return;
}
public void gotoLocation (Location newLoc ) {
currentLocation = newLoc;
}
Car
currentLocation : Location
builtDate : Date
state : String
gasAvailable : Boolean
start ()
stop ()
goto (new loc : Location = Calgary)
}
CPSC 333 - Lecture 21
21
Adding initialization
public class Car {
private Location currentLocation;
private java.util.Calendar builtDate;
private String state;
private boolean gasAvailable;
start engine[ gas available ]
started
stopped
public Car ( ) {
state = "stopped";
}
stop engine
public void start ( ) {
if (gasAvailable) {state = "started";};
return;
}
…..
}
CPSC 333 - Lecture 21
22