View
216
Download
1
Tags:
Embed Size (px)
Citation preview
CS 3500
L03A - 1
What is UML?
A modeling language standardized by the OMG (Object Management Group), and widely used in OO analysis and design
– A modeling language is a visual language for representing software blueprints
– Latest version is 2.0
UML provides a standard notation, semantics for a set of OO abstractions
CS 3500
L03A - 2
UML Overview
UML defines a visual representation of a concept Everything that is defined in this has meaning
– Just like when writing code, you use () or , or + to represent something
– Same is true in UML
So, be careful of the types of arrows, boxes, etc. that you use
Be careful of where you put other symbols Remember that there is a REAL syntax defined for
UML– You can’t just write/draw whatever you like
Our focus – reading UML Class diagrams – Next semester, writing them and other diagrams
CS 3500
L03A - 3
+name()+method1(:double):double+method2():bool+classMethod()
-x: double-y: double-z: double-n: int
name
UML ClassClass name
Data members(attributes)
Instance methods
Arguments
Return typesClass method (static)
These compartments are optional. But if you need methods, then you have to have at least empty data member compartment.
Important – if something isn’t specified, then that doesn’t necessarily mean that it isn’t there. For example, does name take an argument or not, does it return a value?
CS 3500
L03A - 4
+Name()+Name(:Name)+operation()+classMethod
-instanceDataMember: type-classDataMember: type
Name
Class Attributes
Attributes are the instanceand class data members
Class data members (underlined) are shared between all instances(objects) of a given class (think static).
Data types shown after ":"
Visibility shown as+ public- private# protected
Attributecompartment
Attribute Modelvisibility name : type multiplicity = default {property-string}
CS 3500
L03A - 5
+Name()+Name(:Name)+operation()+classMethod
-instanceDataMember: type-classDataMember: type
Name
Class Operations
Operations are the classmethods with their argumentand return types
Public (+) operations define theclass interface
Class methods (underlined) have only access to class datamembers, no need for a classinstance (object)
Parameter List –direction name: type = defaultDirection Model –direction – in, out, inout
Operationscompartment
Operations Modelvisibility name (parameter-list) : return-type {property-string}
CS 3500
L03A - 6
Multiplicity - 1
Indicates how many objects may fill the property– 1 – exactly one
– 0 .. 1 – may or may not have one
– * – zero or more
– n .. m – from n to m where n < m
Default is [1]– But it is best to not use default even if value is 1 to make it clear
Question – if you indicate that something is a n..m multiplicity, then how is this realized?
CS 3500
L03A - 7
Unary Association
A knows about B, but B knows nothing about A
Arrow shows direction of association in direction ofdependency
+doSomething()
-myB: B
A
+service()
B
Void doSomething() { myB.service();}
+doSomething()
A
+service()
B-myB
1
UML Comment
These twodiagramsare identicalin what theymean.
CS 3500
L03A - 8
Unary Association IS an Attribute
Exactly the same as an attribute– Did you hear me? Exactly the same!!!
Solid line (source to target) Name goes at the target end, plus multiplicity It is WRONG to include both an association and a
attribute of the same thing– That implies that BOTH exist at the same time
What is the difference between a unary association (line) and an attribute?
– IT IS THE SAME THING!!!!! Don’t forget!!!!
CS 3500
L03A - 9
Binary Association
Binary association: both classes know each other
Usually "knows about" means a pointer or referenceOther methods possible: method argument, tables, database, ...Implies dependency cycle
void doSomething() { myB.service();}
+doSomething()
A
+service()+operation()
B-myB-myA
1 1
void operation() { myA.service();}
CS 3500
L03A - 10
Dependency
Weak relationships (also transitory):– Class A simply knows of class B
» E.g., a method in A creates and immediately returns an object of class B
That is: a change in one may force changes in the other although there is no explicit association between them.
A B
CS 3500
L03A - 11
Generalization (Inheritance)
Base class or super class
Derived class or subclass
Arrow shows directionof dependency
+setX(:double)+getX():double
-myX: double
A
+operation()
B
public class B : A { …}
CS 3500
L03A - 12
Aggregation
Aggregation = Association with "whole-part" relationship
Shown by hollow diamondat the "whole" side
No lifetime control implied
+doSomething()
Box
void doSomething() { … aContent.service(); ..}
+service()
ContentaModule
1
CS 3500
L03A - 13
Composition
Composition = Aggregation with lifetime control
Shown by filled diamondat the "owner" side
Lifetime control implied
Lifetime control can betransferred
Lifetime control: construction anddestruction controlled by "owner"→ call constructors and destructors
(or have somebody else do it)
+speed(): double
Car
double speed() { … wheels[1] .. wheels[3] …}
+type
Wheelwheels
4
CS 3500
L03A - 14
Composition/AggregationNotations
MovieTheater BoxOffice
Movie
1 1
0..*
0..*
composition
aggregation
whole
part
part
CS 3500
L03A - 15
Vehicle
+ weight : int+ topSpeed : int+ VIN : string
+ getOwner ( )
Owner
+ firstName : string+ lastName : string+ phoneNumber : string
+ contactOwner ( [in] message : string ) : bool+ getName ( ) : string
- myOwner
10..*
- myVehicles
Car
+ modelType : string+ maxPassengers : int
+ addRepairNote ( [in] note : string ) : bool
Motorcycle
+ modelType : stringWheel
+ maxMileage : int
- wheels
2
- wheels 4
Describe This Diagram