Introduction to UML. What is UML UML stands for Unified Modelling Language A way to talk about...

Post on 01-Apr-2015

222 views 1 download

Tags:

Transcript of Introduction to UML. What is UML UML stands for Unified Modelling Language A way to talk about...

Introduction to UML

What is UML

UML stands for Unified Modelling Language

A way to talk about Object Oriented Design

UML is a visual language

first second third

class :

attribute :

value :

instance :Colour

hue

"blue"

name : second

first second third

Colour

hue : String

"red"

"blue"

"green"

first : Colour

hue : "red"

second : Colour

hue : "blue"

third : Colour

hue : "green"

Class (UML)

instance(UML)

actual instance

shape1 shape2 shape3

Shape

form : String

setShape( String)

shape1 : Shape

form = "triangle"

shape2 : Shape

form = "rectangle"

shape3 : Shape

form = "pentagon"

shape1 shape2 shape3

Shape

form : String

setShape( String)

shape3 : Shape

form = "pentagon"

shape3.setShape("hexagon")

form = "hexagon"

shape1 shape2 shape3

ColouredShape

hue : String form : String

setHue( String) setShape( String)

shape1 : ColouredShape

hue = "blue"form = "triangle"

Attributes

methodsState of an instance is the values held in its attributes

shape1 shape2 shape3

shape1 : ColouredShape

hue = "blue"form = "triangle"

shape3 : ColouredShape

hue = "green"form = "hexagon"

shape1.setHue("red")

shape1 : ColouredShape

hue = "red"form = "triangle"

shape3.setShape("octagon")

shape3 : ColouredShape

hue = "green"form = "octagon"

Exercise 1

A hospital bed

attributes

methods

ward

bedNumber

occupied

patient

getBedNumber( ) : intgetWard( ) :String

getPatient ( ) : PatientisOccupied( ) : boolean

empty( )fill( Patient )

typesString

integer

boolean

Patient

List all the attributes you can think of for a hospital bed

For each attribute write down the type of the value

List all the methods you can think of for a hospital bed

Exercise 1

Draw a class diagram for a HospitalBed

HospitalBed

ward : StringbedNumber : integeroccupied : booleanpatient : Patient

getWard() :StringgetBedNumber():integerisOccupied() :booleangetPatient() :Patientempty()fill( Patient)

HospitalBed

ward : StringbedNumber : integeroccupied : booleanpatient : Patient

getWard():StringgetBedNumber():integerisOccupied():booleangetPatient():Patientempty()fill( Patient)

fred

CurrentBed:HospitalBed

ward : "Iris"bedNumber : 14occupied : TRUEpatient : fred

«instance of»

Exercise 1

Patient

Write down attributes fora patient

attributespatientID

name

address

bedNumber

ward

dateOfAdmission

DoB

consultant

notes

typesString

String

String

integer

String

Date

Date

Doctor

Notes...and their types

bed Bed

typical Patient instance

freddy : Patient

name = "Fred Smith"address = "14 Penny Lane"DOB = (07/12/1962)PatientID = "CM897DT"Bed = ("Rose",17)dateOfAdmission = (15/9/2003)consultant=(32331, "Dr A Dass", "Oncology")notes = (File: 2877738)

Extension

Exercise 2

Draw a class diagram for a Bank account

BankAccountaccountNumber: StringaccountName : Stringbalance : double

deposit( amount : double)withdraw(amount : double)

getAccountNumber():String

getBalance():doublegetAccountName():String

BankAccountaccountNumber: StringaccountName : Stringbalance : double

deposit( amount: double)withdraw( amount: double)getAccountNumber():StringgetAccountName():StringgetBalance():double

first : BankAccount

accountNumber: "123212"accountName : "Fred"balance : 1029.34

second : BankAccount

accountNumber: "786348"accountName : "Harry"balance : 1.77

third : BankAccount

accountNumber: "498101"accountName : "Asif"balance : 1102.95

fourth : BankAccount

accountNumber: "858838"accountName : "Hans"balance : -7.34

fifth : BankAccount

accountNumber: "573562"accountName : "Nadine"balance : 20351.12 Instances of the class BankAccount

Exercise 3Draw a class diagram for a Rectangle. The methods include finding the area and perimeter of the rectangle

Rectangle

height : doublewidth : doublearea(): doubleperimeter(): doublegetHeight(): doublegetWidth(): doublesetHeight( aHeight: double)setWidth( aWidth: double)

Exercise 4Write a class diagram for an item stored in a warehouse( ignore methods)

Item

itemNo : Stringdescription : StringitemCost : doublenumberInStock : integerreorderLevel : integerrow : integerbay : integerlevel : integer

Problem: If no item in a location in the warehouse, there is nothing recording the state of that location.

Exercise 4

Item Location0..1 1

itemNo : Stringdescription : StringitemCost : doublenumberInStock : integerreorderLevel : integer

row : integerbay : integerlevel : integer

Item Location

If the system was also used to create a catalogue, an item not held in stock cannot appear in the catalogue!

... much later ...

CatalogueItem

itemNo : Stringdescription : StringitemCost : double

Item

numberInStock : integerreorderLevel : integerisOrdered : boolean

Box

numberPerBox: integerboxIdNo : String

Location

row : integerbay : integerlevel : integerWareHouse

Catalogue1*

1

0..1

1*

1

*

*1

Exercise 5

A system keeps track of the arrivals and departures of aircraft at any airport for an airline.

Identify classes and attributes that might be used by the system

FlightTimeDate

FromLocationDestinationFlightNumber

more?

Exercise 5

A system keeps track of the arrivals and departures of aircraft at any airport for an airline.

Identify classes and attributes that might be used by the system

Flight

Time Date

fromtonumber

hoursminutesseconds

yearmonthday

Exercise 5

Flightnumbertime : Timedate : Date

Departureto: String

Arrivalfrom: String

...