Software Architecture - Unified Modeling Language 1
Chapter 3 The Unified Modeling Language
Software Architecture - Unified Modeling Language 2
Process Phase Affected by This Chapter
Requirements Analysis
Design
Implementation
Architecture Framework Detailed Design
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 3
Classes at Detailed Design
Responsibilities: -- describes each canister undergoing fabrication
+ display() - getNumOpenSlots() + setStatus()
+ numCanisters: int - numWafers: int - size: float
Canister Class name
Attribute: type
Operations
Place for comments
+:Visible from without
wafer
canister
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 4
Key Concept: à Representing a Class in UML ß
UML represents a class with a rectangle containing the class name. We display additional information within the rectangle as needed: Variables, methods, etc.
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 5
package of classes
abstract class
package MyPackage; abstract class MyAbstractClass . . . . package MyPackage; class MyDerivedClass extends MyAbstractClass { int att; . . . . . void myFunction( ReferencedClass r ) { . .. } }
MyDerivedClass att: int myFunction()
UML Notation … and … Typical Implementation
MyPackage
attribute operation
inheritance
MyAbstractClass
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 6
interface interface MyAbstractClass . . . . class MyClass implements MyInterface { . . . . . }
MyClass myMethod()
Interfaces UML Notation …… Typical Java Implementation
realization
MyInterface myMethod()
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 7
Key Concept: à Representing Inheritance in UML ß
UML represents inheritance and interface realization with an open triangle.
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 8
class MyClass { MyAggregatedClass ac; int att; . . . . . }
MyClass att: int myFunction()
MyAggregatedClass ac aggregation
Aggregation : UML Notation and Typical Implementation
1
ac composition Composed object exists only in
the scope of owner object
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 9
Key Concept: à Representing Aggregation in UML ß
Class A aggregates class B if A objects require B objects in a structural sense – typically with an instance variable. UML symbol is an open diamond.
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 10
class MyDependentClass { . . . . . void myFunction1( MyReferencedClass r ) { . .. } MyReferencedClass myFunction2( … ) { . .. } void myFunction3( … ) { MyReferencedClass m … } }
MyDependentClass att: int myFunction()
MyReferencedClass
Dependence : UML Notation … and …Typical Implementation
dependence (reference to a class)
parameter
or return type
or local variable type
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 11
Key Concept: à Representing Dependency ß
Class A depends on class B if A objects require B objects for their definition. In practice, this means that B appears in at least one method of A. UML representation: a dotted arrow.
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 12
class Employer { Employee[ ] employees; . . . . . } class Employee { Employer[ ] employers; . . . . . }
Employer Employee A
ssoc
iatio
n : U
ML
Not
atio
n an
d Ty
pica
l Im
plem
enta
tion
1..n 1..3 employs
is employed by
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 13
Customer Mail Application
CustomerMailApplication generateMail()
getCustomerTypeFromUser() main()
Customer createMail()
DelinquentCustomer createMail()
MountainCustomer createMail()
RegularCustomer createMail()
customer 1
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 14
Key Concept: à Use Cases ß
-- a sequence of actions taken by an application and its user.
The user takes one role.
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 15
Use Cases For Video Store Application
clerk
Check in
Check out
1. . . . .
Activate
1. Actor hits any key. 2. Application displays main
menu. …
stocker
Add video
1. … . . . . . . . . .
Precondition: Application has been activated
1. Actor clicks “check out.” 2. Actor swipes bar code. 3. Application prompts for
rental duration. 4. Actor enters duration. 5. Application stores record. 6. Application prints
customer’s account status.
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 16
Dispatcher
Warehouse worker
Use Case Generalization
& Usage
A. Application displays main options B. User selects icon
ControlApplication
Perform warehouse transaction
Modify Stock
«extends»
«uses»
A. Application displays main options 1. User moves cursor to stock icon B. User selects icon 2. Application displays stock window
(i). Application displays logo (ii). “Perform warehouse Transaction” use case. (iii) Application displays farewell screen (iv) Application shuts down
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 17
Beginning of Sequence Diagram for Check Out Use Case
Clerk :BarCodeReader
:Checkout
initiate() show()
:CheckoutOptionDisplay
} Step 2 of use case
Note 1
order
Note 3
doCheckout()
:MainScreen
read()
Note 2
{Step 3 of use case
Note 0
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 18
4. store()
2.3 show()
3. setDuration()
1. read()
Beginning of Sequence Diagram for Check Out Use Case User :BarCodeReader
doCheckout()
:MainScreen
Use case: 1. User swipes bar code 2. Application prompts for rental duration 3. User enters duration 4. Application stores record 5. Application prints customer’s account status
:Checkout 2.1 initiate()
:CheckoutOptionDisplay
:Account
2.2 create()
5. print()
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 19
Building a Sequence Diagram 1
1. Identify the use case whose sequence diagram you will build (if applicable).
2. Identify which entity initiates the use case – the user, or – an object of a class
• name the class • name the object
3. Draw a rectangle to represent this object at left top – use UML object:Class notation
4. Draw an elongated rectangle beneath this to represent the execution of an operation
5. Draw an arrow pointing right from its top
myObject :MyClass
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 20
Building a Sequence Diagram 2
6. Identify which entity handles the operation initiated – an object of a class
• name the class • name the object
7. Label the arrow with the name of the operation
8. Show a process beginning, using an elongated rectangle
9…… Continue with each new statement of the use case.
myObject :MyClass
myObject1 :MyClass1
operation()
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 21
Key Concept: à Sequence Diagrams ß
A sequence diagram shows the order in which methods of various objects execute.
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 22
States for OnlineShopper Class
Browsing ItemsChosen
CreditUnderValidation
CheckingOut
CreditDenied Complete
Incomplete
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 23
Conditions on Events
CreditUnderValidation Incomplete Hit Submit button
[credit card data incomplete]
[credit card data complete]
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 24
Hit checkout button
CheckingOut
State/Transition Diagram for OnlineShopper Class
Browsing ItemsChosen
CreditUnderValidation
CreditDenied Complete
Incomplete hit Submit button
[credit card data incomplete]
[credit card data complete]
put back last item
select item
hit OK validation received
denial received
hit OK
hit Quit
select item
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 25
Key Concept: à State Diagrams ß
Some applications or parts thereof are conveniently thought of as being in one of several possible states. UML state diagrams help us visualize these, and the events that cause transitions among them.
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 26
Activity Chart Notation Do Something
Do Something More
Do A Task Do Another Task
Do Even More
else [condition true]
} In parallel
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 27
A Class Model for Chaining
Rule addRule()
proveAntecedents() forwardChain()
Fact content
addFact() proveBack()
consequent
antecedents
static factList static ruleBase
Set Fact.factList to the known facts and a Rule.ruleBase to the known rules. Create Fact object soughtFact Execute soughtFact.proveBack( ruleBase );
1
1..n
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 28
Flowchart for soughtFact.proveBack()
Apply R.proveAntecedents()*
Report TRUE
Report FALSE
else
Another rule R exists with soughtFact as its consequent else
else
soughtFact in factList
Fact Rule
* Prove that every antecedent fact is true
proof succeeded
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 29
Specifications for Figure Drawing
q Facilitate drawing stick figures
q Drag to vicinity to auto-complete
q Feet can be rectangles or ellipses
q (Rest to be specified)
Releasing dragged figure anywhere in this area causes it to appear in position at end of left leg
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 30
Bad Attempt: “A Foot is Either an Ellipse or a Rectangle”
Foot
Ellipse Rectangle
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 31
Better Attempt: “A Foot is Either an Ellipse or a Rectangle”
RectangleFoot
Foot Rectangle Ellipse
EllipseFoot
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 32
Another Attempt: “A Foot is Either an Ellipse or a Rectangle”
Foot FootShape
Ellipse Rectangle
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 33
Best Attempt So Far: “A Foot is Either an Ellipse or a Rectangle”
Foot draw()
FootShape drawAsEllipse()
drawAsRectangle()
Ellipse draw()
Rectangle draw()
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 34
Class Model Showing All Dependencies
Foot draw()
FootShape drawAsEllipse()
drawAsRectangle()
Ellipse draw()
Rectangle draw()
GeometricFigure Area releaseCursor()
Leg
Position
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 35
Sequence Diagram for Figure Drawing Application
:FootShape :Foot
releaseCursor
drawAsEllipse*
:Ellipse
draw( aPosition )
:Area
draw ( GeometricFigure aGeometricFigure )
( Position aPosition )
( Leg aLeg, aGeometricFigure )
* or drawAsRectangle() …
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Software Architecture - Unified Modeling Language 36
Lesson Summary
q Use Cases o Actor / application
interactions q Sequence Diagrams
o Objects o Sequence of methods
§ calling methods among objects
q Class Models q Activity Diagrams
o Flow of control q State Diagrams
o States o Transitions among states
§ caused by events
q Dependency o member method mentions
another class q Association
o structural o e.g., sale / receipt o Aggregation
§ common kind of association § e.g. airplane / wing § one-way § “has-a”
q Inheritance o “is-a”
UML Models Relationships between Classes