UML a crash course Alex Lo Brian Kiefer. Overview Classes Class Relationships Interfaces Objects...
-
date post
22-Dec-2015 -
Category
Documents
-
view
218 -
download
0
Transcript of UML a crash course Alex Lo Brian Kiefer. Overview Classes Class Relationships Interfaces Objects...
UML
a crash courseAlex LoBrian Kiefer
Overview
ClassesClass RelationshipsInterfacesObjectsStatesWorksheet
Classes
Drawn as a three section box: Name Fields Functions
+Operation1()
-Attribute1
Class Name
ClassesFields and functions given visibility signs+ sign indicates public- sign indicates private# sign indicates protected
Fields are shown as name:typeFunctions are shown as Function(argument1:type, …):returnTypeItalic class or method names indicate the class is abstractStatic fields and functions are underlined
Cooper Examplepublic abstract class Person
{
protected String personName;
private int age;
public Person (String name) { personName = name; }
static public String makeJob () {return "hired";}
public int getAge () {return age;}
private void splitNames () { }
abstract String getJob ();
}
Alternate Diagrams
Packages
Packages are depicted as large folders with classes contained inside
Package Name
+Operation1()
-Attribute1
Class Name
+Operation1()
-Attribute1
Class Name Class1
Notes
UML does not require that you show everythingTo draw a note in UML
+Operation1()
-Attribute1
Class Name
This is some sort of note
Class Relationships
Use a solid line with a hollow arrowhead to show a parent class
Class1 Class2
Class2 extends Class1
Cooper Examplepublic class Employee extends Person { public Employee (String name) { super (name); }
public String getJob () { return "Research Staff"; } }
Relationships
A single line often represents that one class contains an instance of anotherUse a diamond to show that one class has a collection of the other classSometimes a small circle is used to show that the instance is singular
Class1 Class2
Class1 Class2
Class1 Class2
Relationship Cardinality
Exactly 1
Many (0 and up)
Optional (0 or 1)
One or moreN to M (not shown)
Class2-N
0..1
-M
1
Class2-N
0..1
-M
*
Class2-N
0..1
-M
0..1
Class2-N
0..1
-M
1..*
Relationships
An open arrow indicates navigability – it shows that one class has a ref to another and the other may not
Class1 Class2
Class1 Class2relationship
relationship
Dependency
A dashed arrow shows a dependency on a class that does not use an object ref Example: using static method of another
classothers?
Class1 Class2
Other Relations
Another relation can be done using the dashed arrows like throwing
Class1 Class2«bind»
(bind can be any keyword, such as throw, send, become, friend, etc)
InterfacesInterfaces are drawn similarly to classes, except without a field area (usually) and the <<interface>> stereotypeAn interface which you don’t need to define can be drawn as a “lollipop”
«interface»InterfaceName RemoteInterface
Interfaces
To show a class implements an interface, use a dashed line with an open arrowhead
Class1 «interface»InterfaceName
Class2
RemoteInterface
Notes on Interfaces
While interfaces and their methods are always abstract in java, their methods do not appear italicized. As opposed to abstract classes and abstract methods.
*This was disagreed on between Cooper and our book.
Objects
You can show an object by giving its name and type separated by a colon (or just either/or) and underlining itA line between objects indicates that one object has a reference to another.
s:String :Char«uses»
Calling Methods from Objects
You can show a sequence of objects calling methods of other objects
The order is from top to bottom
The dashed line indicates the object over time
A bold outline of the box represents the class is running on a separate thread
LinkedList List
addFirst(:Object)
States
UML can also be used to model the various states of a program or method Think Introduction to Logic Design Think events (clicks, key presses, etc.)
Closed
Opening
Open StayOpen
Closing
click
click
click
click
click
complete
completetimeout
Other uses of UML
Collaboration diagramsUse case diagramsActivity diagramsDeployment diagramsEtc.
More Resources
Our book, p 442-447Safari Online:Java™ Design Patterns: A TutorialBy James W. CooperChapter 2
UML Distilled
Message Repository
MailAccountList
MailAccount(POP3, IMAP or
Local)
...
POP3Account
LocalAccount
IMAPAccount
Inherits from
MailAccount
Contains
MailAccount(POP3, IMAP or
Local)
MailboxList
MailBox(POP3/Local or
IMAP)
...
MailBox(POP3/Local or
IMAP)
Mailbox
LocalMailbox(POP3Mailbox)
IMAPMailbox
Inherits from
Contains
MailMessageList
MailMessage(POP3/Local or
IMAP)
...
MailMessage(POP3/Local or
IMAP)
Contains
MailMessage
LocalMailMessage(POP3MaiMessage)
IMAPMailMessage
Inherits from
POP3 Protocol
IMAP Protocol
Internal
Use
Use
Pluggable Universal Multiple Mail Account Structure
Discussion