7 - UML Class Diagrams
7 - UML Class Diagrams
UML Diagram
UML 2.2 has 14 types of diagrams divided into two categories. Seven diagram types represent structural information. Seven represent general types of behavior.
Methods
Person
- Name : String
Example 2:
CD Models (Class, Attributes, Method)
MyCar
+ Color : String + yearOfProduction : int + printMyCar (): void
Example 3:
CD Models (Class with main method)
MyCarInAction
+ main(String[]): void
Exercise 1:
Create code from UML class diagram below!
MyCar2
+ Color : String + yearOfProduction : int
+ printMyCar (): void + turnOnMechine (): void + changeGear (): void + turnOffMechine (): void
MyCarInAction2
+ main(String[]): void
Example 4:
CD Models (Class with main constructor)
Constructor
Students
- nim : String - nama : String + Students(nim : String, nama : String) + getNim (): String + getNama (): String
StudentsCard + main(String[]): void
Example 4:
CD Models (Class with constructor) Result
Exercise 2:
Create code from UML class diagram below!
Students2
- nim : String - nama : String
+ Students2(nim : String) + setNim(String): void + setNama(String): void + getNim (): String + getNama (): String
StudentsCard2
+ main(String[]): void
Example 5:
CD Models (Inheritence)
Bicycle - gear: int - speed : int + changeGear(int): void + speedUp(int): void + applyBrake(int): void MountainBikeAction
+ main(String[]): void
Example 5:
CD Models (Inheritence) Result
Bicycle
- gear: int - speed : int
+ changeGear(int): void + speedUp(int): void + applyBrake(int): void
Example 5:
CD Models (Inheritence) Result contd
MountainBike
- seatHeight : int + setHeight (int): void
MountainBikeAction
+ main(String[]): void
Exercise 3:
Create code from UML class diagram below!
Calc
# result: double = 0 # operand1: double = 0 # operand2: double = 0 # setOperand1(double): void # setOperand2(double): void # getOperand1(): double # getOperand2(): double # addition(): double # subtraction(): double # multiplication (): double # division(): double
AdvancedCalc
+ modulo(double,double): double
Exercise 3:
Result
Example 6:
CD Models (Multilevel Inheritance)
Person
# name: String # address: String # setName(String): void # setAddress(String): void # getName(): String # getAddress(): String
PersonInAction
+ main(String[]): void
Student
- campus : String # setCampus(String): void # getCampus(): String
Employee
# totalSalary: double # setTotalSalary(double): void # calculateSalary(): void # getTotalSalary(): double
Monthly
- numberOfAbsent : int - salaryPerMonth : double
Hourly
- salaryPerHour : double + calculateSalary(): void + addHour(float): void
Exercise 4:
Create code from class diagram in the previous slide
Clue:
calculateSalary is polymorhism method
THANKS
Contact : [email protected] Website : http://mosesdinus.wordpress.com/