Upload
hughbertz
View
249
Download
0
Embed Size (px)
Citation preview
8/9/2019 introduction to Unified Modelling Language Uml
1/23
UML: Uniform Modeling Language
UML is a standardized design language for object-oriented
programming in various languages. The website for UML ishttp://www.uml.org. UML diagrams can be classified into fourtypes.
◮ Class Diagram. Shows relationships between various classes ina project.
http://find/http://goback/
8/9/2019 introduction to Unified Modelling Language Uml
2/23
UML: Uniform Modeling Language
UML is a standardized design language for object-oriented
programming in various languages. The website for UML ishttp://www.uml.org. UML diagrams can be classified into fourtypes.
◮ Class Diagram. Shows relationships between various classes ina project.
◮ Object Diagram. Shows interactions between various objectsin your project.
http://find/
8/9/2019 introduction to Unified Modelling Language Uml
3/23
UML: Uniform Modeling Language
UML is a standardized design language for object-oriented
programming in various languages. The website for UML ishttp://www.uml.org. UML diagrams can be classified into fourtypes.
◮ Class Diagram. Shows relationships between various classes ina project.
◮ Object Diagram. Shows interactions between various objectsin your project.
◮ Collaboration Diagram. Shows associations between variousobjects. Similar to relationships between classes but differs
since we usually show the methods being called and valuesbeing returned.
http://find/
8/9/2019 introduction to Unified Modelling Language Uml
4/23
UML: Uniform Modeling Language
UML is a standardized design language for object-oriented
programming in various languages. The website for UML ishttp://www.uml.org. UML diagrams can be classified into fourtypes.
◮ Class Diagram. Shows relationships between various classes ina project.
◮ Object Diagram. Shows interactions between various objectsin your project.
◮ Collaboration Diagram. Shows associations between variousobjects. Similar to relationships between classes but differs
since we usually show the methods being called and valuesbeing returned.
◮ Sequence Diagram. Shows interactions between variousobjects based on a time-line.
http://find/
8/9/2019 introduction to Unified Modelling Language Uml
5/23
Class Diagrams
◮ Classes are drawn as rectangles, which may be divided into 1,2 or 3 partitions. The top partition is for the class name, thesecond one for the class variables, and the third one for themethods or operations. Each variable/method is preceded bya visibility indicator .◮ + indicates public◮ - indicates private◮ # indicates protected
http://find/
8/9/2019 introduction to Unified Modelling Language Uml
6/23
Class Diagrams
◮ Classes are drawn as rectangles, which may be divided into 1,2 or 3 partitions. The top partition is for the class name, thesecond one for the class variables, and the third one for themethods or operations. Each variable/method is preceded bya visibility indicator .
◮ + indicates public◮ - indicates private◮ # indicates protected
◮ Interfaces are shown as classes except it has only twopartitions. A interface name is preceded by a stereotype tag
to show that it is a special kind of a class.
http://find/
8/9/2019 introduction to Unified Modelling Language Uml
7/23
Class Diagrams
◮ Classes are drawn as rectangles, which may be divided into 1,2 or 3 partitions. The top partition is for the class name, thesecond one for the class variables, and the third one for themethods or operations. Each variable/method is preceded bya visibility indicator .
◮ + indicates public◮ - indicates private◮ # indicates protected
◮ Interfaces are shown as classes except it has only twopartitions. A interface name is preceded by a stereotype tag
to show that it is a special kind of a class.
◮ Methods/classes that are abstract are shown italicized.
http://find/
8/9/2019 introduction to Unified Modelling Language Uml
8/23
UML Class Diagram
Rectangle-width: double-length: double
+Rectangle()+calculateArea(): double
We are using the Dia program to generate the UML diagrams. It is
available for free for Linux, MS Windows, MacOS X from
http://projects.gnome.org/dia/For eclipse, you can download the free Object Aid UML reverse
engineering plugin that draws UML diagrams for your existing classes!
http://find/
8/9/2019 introduction to Unified Modelling Language Uml
9/23
UML Interface Diagram
«interface»
Drawable +draw()+fill()
http://find/http://goback/
8/9/2019 introduction to Unified Modelling Language Uml
10/23
Inheritance and Associations
◮ Inheritance. A solid line with a closed arrowhead from thesubclass to the superclass.
◮ Implements. A dashed line with a closed arrowhead from theimplementing class to the interface.
http://find/
8/9/2019 introduction to Unified Modelling Language Uml
11/23
Inheritance
http://find/
8/9/2019 introduction to Unified Modelling Language Uml
12/23
Inheritance Hierarchy
Animal
Invertebrae Vertebrae
Amphibian Mammal Reptile
Dog Cat
http://find/
8/9/2019 introduction to Unified Modelling Language Uml
13/23
A Package
java.animals
Animal
Invertebrae Vertebrae
Amphibian Mammal Reptile
Dog Cat
http://find/
8/9/2019 introduction to Unified Modelling Language Uml
14/23
Implements
http://find/
8/9/2019 introduction to Unified Modelling Language Uml
15/23
Associations
◮ Associations (or dependencies). A solid labeled line showsthat two classes are associated. A small solid triangle (rightnext to the label) shows the direction of the association. Anoptional open arrowhead can be used to denote the directionof the association.
◮ Numbers at either end indicate are the multiplicity indicators .Here are are some examples of multiplicity indicators.
1 one0..2 zero to two
0..∗
zero or more∗ zero or more
1..∗ one or more
http://goforward/http://find/http://goback/
8/9/2019 introduction to Unified Modelling Language Uml
16/23
Association Example
http://find/
8/9/2019 introduction to Unified Modelling Language Uml
17/23
Aggregation
◮ An Aggregation is an association in which one class containsmany others. The container class has a diamond on its end of
the association line.
http://find/
8/9/2019 introduction to Unified Modelling Language Uml
18/23
Inheritance and Association
E l E l
http://find/
8/9/2019 introduction to Unified Modelling Language Uml
19/23
Employees Example
Firm
+main(args:String[]): void
Staff
-staffList: StaffMember[]
+payday(): void
StaffMember
#name: String
#address: String
#phone: String
+toString(): String
+pay(): double
Volunteer
+pay(): double
Employee
#socialSecurityNumber: String
#payRate: double
+toString(): String
+pay(): double
Executive
-bonus: double
+awardBonus(execBonus:double): void
+pay(): double
Hourly
-hoursWorked: int
+addHours(moreHours:int): void
+pay(): double
+toString(): String
1
0..*
1
1
A Cl k H i h Di
http://find/
8/9/2019 introduction to Unified Modelling Language Uml
20/23
A Clock Heirarchy Diagram
Clock
#seconds: int
#minutes: int
#hours: int
+getSeconds(): int
+getMinutes(): int
+getHours(): int
+draw(page:Graphics): void
+paint(page:Graphics): void
+actionPerformed(event:ActionEvent): void
DigitalClock
+draw(page:Graphics): void
AnalogClock
+draw(page:Graphics): void
javax.swing.JApplet
javax.swing.Timer
+Timer(delay:int,listener:ActionListener)
ActionListener
+actionPerformed(event:ActionEvent): void
Uses1
1
actionPerformed(event)
The paint method calls
the draw method
Th Add B k Cl Di
http://find/
8/9/2019 introduction to Unified Modelling Language Uml
21/23
The Address Book Class Diagram«interface»
Comparable
+compareTo(obj:Object): int
Name-first: String-middle: String-last: String
Address-postOfficeBox: String-streetAddr: String-city: String-state: String-postalCode: String-country: String
ContactDate-date: Date-df: DateFormat
Contact-name: Name-address: Address-phone: String-email: String-homePage: String-birthDate: ContactDate-lastMeeting: ContactDate-relationship: String-photo: Image-note: String
AddressBook-contacts: Contact[]-size: int-capacity: int-dataFile: String-DEBUG: boolean = false-tags: String[]-nextToken: String
Get
CmdLineAddressBook-mycontacts: AddressBook
Uses
1
1
Uses
1
1Uses
1
2
Uses
1
1
Uses
1
2
Uses
Uses
Uses
Uses
Uses
UsesUses
Obj t Di
http://find/
8/9/2019 introduction to Unified Modelling Language Uml
22/23
Object Diagrams
Objects are drawn the same way as classes with 1/2/3 partitions.
The difference is that names for objects are underlined and consistof the name and type of the objects.When depicting object interactions, an active object is shown inbold face.Objects send messages to each other (through method class and
return values). This are shown as labeled links with an arrowdenoting the direction.
[object1:RectangleUser]
[object2:Rectangle]
calculateArea
Object I te actio
http://find/http://goback/
8/9/2019 introduction to Unified Modelling Language Uml
23/23
Object Interaction
app: CmdLineAddressBook
mycontacts: AddressBook
...
mycontacts:AddressBook
contacts: Contact[]...«create»
addContact()
sortContacts()
getAllContacts()
Contact[]
findByName(fname, lname)
Contact[]
running AddMenu()
running printMenu()
running findMenu()
http://find/