Chap 2-Intro To UML
Chap 2-Intro To UML
: Professor
ProfessorClark a + b = 10
Class Name Only
Professor Clark
ProfessorClark :
Professor Object Name Only
Realization relationship
Object Oriented Analysis and Design 10
Review: Interface Representations
Tube
Elided/Iconic
Representation
(“lollipop”) Pyramid
Shape Cube
Canonical Tube
<<interface>>
(Class/Stereotype) Shape
Representation
Draw Pyramid
Move
Scale
Rotate Cube
Login Login
Login Login
suspend()
flush()
Orderform
Object Oriented Analysis and Design 16
Structural things – Artifact
An artifact is a physical and replaceable part
of a system that contains physical information
("bits").
An artifact typically represents the physical
packaging of source or run-time information.
Graphically, an artifact is rendered as a
rectangle with the keyword «artifact» above
the name.
<<artifact>>
Login.dll
<<Node>>
Node #1
Sequence Diagrams
Communication Diagrams
Object Oriented Analysis and Design 24
Interaction Diagram Example - HelloWorldApp2.java
public class HelloWorldApp2 {
public static void main(String[] args) {
Greeting hello = new Greeting(); client hello : Greeting
hello.greet("Hello World");
} greet(String)
}
class Greeting {
public void greet(String s) {
System.out.println(s);
}
}
1: greet(String)
client hello : Greeting
waiting
One of these is
executed:
Event
Association
Role Names
Name
Professor Works for University
Employee Employer
Association
Object Oriented Analysis and Design 34
What Is an Association? – A example
class CatalogueEntry {
private string name; CatalogueEntry screw= new
CatalogueEntry
private int number; (“screw”, 28834, 0.02);
private double cost;
public double getCost () { Part screw1 = new Part(screw) ;
return cost;
screw1.cost();
}
}
class Part {
private CatalogueEntry
entry;
public double cost () {
return entry.getCost();
}
}
Object Oriented Analysis and Design 35
What Is an Association? – A example
An association is a structual relationship that desribes a set of
links.
a link being a connection among objects.
: CatalogueEntry
Describes Describes
: Part name = “screw” : Part
number = 28834
Fig. Links between objects cost = 0.02
A link specifies a path along which one object can dispatch a
message to another (or the same)object.
: CatalogueEntry
Client
cost() : Part
getCost()
name = “screw”
number = 28834
cost = 0.02
Fig. Finding the cost of a Part
CatalogueEntry
- name Part
- number
- cost
+ cost() * 1 + getCost()
‘ Schedule.cls
Schedule
Public theStudent as Student
1
1 ‘ Student.cls
Association
Name
nn job nn
Person Company
-employee -employer
Role Names
Whole Part
Student Schedule
Aggregation
Whole Part
Student Schedule
Composition
Job
-salary
+ getSalary()
Object Oriented Analysis and Design 43
Association - Association Class
Company 1..* Person
*
-employer -employee
Job
-salary
+ getSalary()
Design Decisions
prerequisites
0..*
Course
has 0..1
School Department
1 1..n 1..n
1..n 1..n
assignedTo
member
-chairperson
n 1..n 1..n 0..1
Student attends Course teaches Instructor
n n n 1..n
ClientPackage SupplierPackage
Dependency
relationship
Professor Course
class Professor {
public void teach(Course c) { ……..}
……………..
}
class Professor {
public void teach() { Course c = new Course(); ……..}
……………..
}
Graphics HelloWorld
paint()
Object Oriented Analysis and Design 49
Relationships: Generalization
A relationship among classes where one
class shares the structure and/or behavior
of one or more classes
Defines a hierarchy of abstractions in which
a subclass inherits from one or more
superclasses
Generalization
Single inheritance relationship
Multiple inheritance Employee
an “is-a-kind of” relationship
Engineer Manager
Object Oriented Analysis and Design 50
Generalization - Example
• Employee is a generalization of Engineers and
Managers.
• Engineer is a specialization of Employee.
• Manager is a kind of Employee.
• Engineers and Managers inherit the Employee interface
(and in this case, some implementation too).
class Employee {…...};
class Manager : public Employee {..};
class Engineer : public Employee {…};.
class Employee {…...}
class Manager extends Employee {..}
class Engineer extends Employee {…}
Object Oriented Analysis and Design 51
Example: HelloWorld.java
import java.applet.Applet;
import java.awt.Graphics;
Graphics HelloWorld
paint()
Object Oriented Analysis and Design 52
Example: Single Inheritance
One class inherits from another
Ancestor
Account
balance
name
Superclass number
(parent) Withdraw()
CreateStatement()
Generalizatio
n Relationship
Checking Savings
Descendents
FlyingThing Animal
multiple
inheritance
Use multiple inheritance only when needed, and always with caution !
GroundVehicle
owner Person
Superclass weight
(parent) licenseNumber 0..* 1
register( )
generalization
Tube
Tube
<<Interface>>
Shape
Pyramid
Pyramid
draw()
Shape move()
scale()
Cube
rotate() Cube
Elided/Iconic
Representation Canonical
(“lollipop”) (Class/Stereotype)
Representation
Circle
Shape
Scenario
Scenario State
State
Scenario
Scenario
Diagrams State
State
Diagrams
Sequence
Diagrams
Sequence
Diagrams State
Diagrams
State
Diagrams
Diagrams
Diagrams Models Diagrams
Diagrams
Diagrams Diagrams
Scenario
Scenario
Component
Component
Scenario
Scenario
Diagrams
Component
Diagrams
Component
Component
Diagrams
Collaboration
Diagrams
Collaboration
Diagrams Deployment
Deployment Component
Diagrams
Diagrams
Diagrams
Diagrams Diagrams Diagrams
Diagrams
Diagrams Diagrams
Order
Product
Ship via
image.java component.java
ImageObserver
:Client :Supplier
Object Lifeline
Reflexive Message
1: doSomething()
1.1: doAnotherthing()
Message
Sequence number
Focus of Control
Object Oriented Analysis and Design 77
Diagrams - Collaboration Diagram
A collaboration diagram emphasizes the
organization of the objects that participate in an
interaction.
Client Object Link Supplier Object
:Client :Supplier
1: doSomething()
Message
shutDown
keyPress
Idle Running
Finished
Unassigned
closeRegistration
cancel Cancelled
addProfessor
do: Send cancellation notices
close
removeProfessor cancel
[ numStudents = 10 ]
cancel
Full
close Cancelled
Unassigned do: Send cancellation notices
cancel
cancel
substate
Full
close[ numStudents < 3 ]
remove a professor
[ numStudents = 10 ] close
add a professor
closeRegistration [ has Professor assigned ]
initial state
Select site
action state
Bid Plan
concurrent join
Finish construction
final state
Object Oriented Analysis and Design 83
Extension mechanism of the UML
<<boundary>>
LoginForm LoginForm
Shape
MyClass
{Version =
1.02}
paint() HelloWorld
Graphics
paint()
g.drawString (“Hello World !”,10,10)
Component
jav
ImageObserver
a
Container
HelloWorld applet
Panel awt
lang
Applet
HelloWorld
callbackLoop( )
handleExpose( )
paint( )
Painting mechanism
Object Oriented Analysis and Design 96
Example - Components
HelloWorld.class hello.java
hello.html
hello.jpg
HelloWorld Component