The UML Class Diagram: - Is A Static Diagram (Describes System Structure)
The UML Class Diagram: - Is A Static Diagram (Describes System Structure)
Operations
Attribute syntax:
Visibility name:type=init_value{property_string}
UML Class Attribute Examples
UNIXaccount UNIXaccount
+ username : string + username : string
+ groupname : string + groupname : string = “staff"
+ filesystem_size : integer + filesystem_size : integer
+ creation_date : date + creation_date : date
- password : string - password : string
Invoice
Invoice + amount : real
+ amount : real + date : date = current date
+ date : date = current date + customer : string
+ customer : string + specification : string
+ specification : string - administrator : string = "unspecified"
- administrator : string = "unspecified" - number_of_invoices : integer
- number_of_invoices : integer + status : status = unpaid { unpaid, paid }
UML Class-to-Java Example
Public class UNIXaccount UNIXaccount
{ + username : string
public string username; + groupname : string = “staff"
public string groupname = "csai"; + filesystem_size : integer
public int filesystem_size; + creation_date : date
public date creation_date;
private string password; - password : string
static private integer no_of_accounts = 0 - no_of_accounts : integer = 0
public UNIXaccount()
{
//Other initialisation
no_of_accounts++;
}
//Methods go here
};
Operations (Methods)
Public class Figure Figure
{ - x : integer = 0
private int x = 0; - y : integer = 0
private int y = 0; + draw()
public void draw()
{
//Java code for drawing figure
}
};
Figure fig1 = new Figure();
Figure fig2 = new Figure();
fig1.draw();
fig2.draw();
Constraints on Operations
PoliceStation
alert (Alarm)
1 station
BurglarAlarm
report () { if isTripped
then station.alert(self)}
Association Examples
Drives
Person * * Car
Driver Company
car
* 1 1 Drives
Person Employee * Car
Adult Driver Driver Company
car
Married to
Person Person
Husband Wife
Radio Child
Qualified and "Or" Associations
season
Team Player
team goalkeeper
Record
goals for
goals against
wins
losses
ties
Association Classes
Host
Computer
*
Network adapter
Adapter Queue
Print spooler
1
1..*
Network1 Printer
Notary
Purchaser Real-estate
Client Contract
Association by Aggregation
Alternative Notation for
Composition Association
Car
*
Wheels
Body
*
*
Engine
My family
Ernest: Family member
Fiona: Family member
Ernest
Fiona
Zoo Family
member
Zoo
Monkey[0..*]: Mammal
Giraffe[0..*]: Mammal
Human[1..*]: Mammal
Falcon[0..*]: Bird
0..* 0..* 1..* Falcon 0..* Cage 1..*
Cage[1..*]: Equipment
Mammal Bird Equipment
Abstract Classes
Abstract Classes and
Generalisation Example
Aircraft
{abstract}
Make
Seats
Engine type
Start() {abstract}
land() {abstract}
Make Make
Seats Seats
Engine type Engine type
Start() Start()
land() land()
Start jet engines Start blades
Consists of *
Radio Monitor
Amplifier unit
receiver
TV set
Complete Generalisation
University
faculty
component
{complete}
University University
department institute
Person
{complete}
Man Woman
Expressing Rules in UML
• Rules are expressed using constraints and
derivations
● Constraints were mentioned earlier (e.g. or-
associations, ordered associations, inheritance
constraints, etc.)
Is on
/1 class passenger /1 class passenger
Passenger
Passenger
Name
Surname
Age
Nationality
Destination Turbo-prop Jet-turbine
Ticket price aircraft aircraft
/1 class passenger
Supplies Processes
Wholesaler Shop Order
Places
Shop
Name
Address
Owner
Category /bulk-buying customer
Date of registration Customer
Area
/Supermarket
Maintains
Entry in
Organisation
{subset}
Project manager of
Member of Employee
«call» ClassC
«refine»
ClassC combines
two logical classes
ClassD ClassE
Concrete Dependency Example
Controller
«access»
«access»
«access» Diagram
Elements
«access»
«access»
Domain Graphics
Elements Core
Class Diagram Example
Element
C <<covalent>>
Carbon Hydrogen
C H
<<covalent>> C
Instantiation of Class Diagram
(in previous slide)
:Hydrogen :Hydrogen
:Hydrogen :Hydrogen
Another Class Diagram Example
CreditCard
{abstract} MyCreditCard
OrderBean
<<interface>> {abstract}
EntityBean
+getOrderStatus
+setOrderStatus MyOrder
+getLineItems
+setLineItems
order +getCreditApproved
+setCreditApproved
* ...
1 order
buyer 1 * item
Customer LineItem
{abstract} MyLineItem
*
* item
1 commodity
Product
Try This Yourselves…
• Create a class diagram to represent a
arbitrary interconnection of computers