KONSEP OOP
DIAGRAM UML
Association A---->B
Composition A-----<filled>B
Aggregation A-----<>B
Aggregation
In transportation systems Car has many Passenger,
relationship between them is Aggregation.
class Engine
{ private String type; }
Composition vs Aggregation
Jika suatu objek adalah bagian dari (part-of) objek lain,
misalnya Engine is part of Car, maka asosiasi atau relationship
diantara keduanya disebut Composition (Komposisi).
Jika suatu objek memiliki objek lain maka ini disebut
Aggregation (Agregasi).
Aggregation (many-to-one relationships)
Whole Part ( Composition)
Containership
Collection
Group
Composition
Komposisi adalah bentuk khusus dari Agregasi (disebut juga death
relationship). Child Object (Objek yang digunakan dalam objek
induknya) tidak memiliki lifecycle. Jika objek induknya dihapus maka
objek anaknya juga akan terhapus.
Misalnya:
House -----<filled> Rooms
House can contain multiple rooms there is no independent life of
room and any room can not belong to two different houses. If we
delete the house - room will automatically be deleted.
Questions -----<filled> options. Single questions can have multiple
options and option can not belong to multiple questions. If we delete
questions options will automatically be deleted.
Relasi
an "is-A" relationship
Inheritance
for type - a re-use of common interface
for class - a re-use of common interface and
implementation
Person Student
Name Name
Attendence
Current
Grade
Class Diagram
Visibility
Attributes normally should be private, methods invoked by clients
should be public
Visibility markers in UML
A plus sign (+) indicates public visibility
A minus sign (-) indicates private visibility
A sharp sign (#) indicates protected visibility
Navigability
Navigability arrows indicate in which direction an association can
be traversed
Bidirectional navigability
Associations with navigability arrows at both ends or no navigability
arrows at all can be traversed in either direction
15
Contoh Class Diagram
Comparison of
Functional vs. OO Views
Register Submit
Student Grade
Student
Students Grades Score
Register( ) Name
Students Submit Score( ) 0..* Value
Print Transcript( )
Student/Grades
Print
Transcript
Addition of a New Student Type
Student
Register Score
Submit Name
Student Register( )
Grade Submit Score( ) 0..* Value
Print Transcript( )
Students/
Pass Fail Students Grades/PF
Students Impact
Student/Grades/PF Areas
PassFail Student
Print
Transcript Print Transcript( ) function override
Areas
Students
Student/Grades/PF
Student/Grades/PF
PassFail Student
Print Print
Print Transcript( )
Transcript Report Print Report Card(
Card
Transcript
0..1
Print( ) Student
Score PassFail Student
Name
Register( )
0..* Value Determine Grade( )
Submit Score( )
Report Card Determine Grade( )
0..1
Print( )
PassFail Student
Determine Grade( )
25
Starting to Program the Classes of the ATM System
26
Fig. 8.24 | Class diagram with visibility markers.
27
1 // Class Withdrawal represents an ATM withdrawal transaction 28
2
3
public class Withdrawal
{
Class for Outline
4 // no-argument constructor
Withdrawal
5 public Withdrawal()
Empty no-argument withdrawal.ja
6 {
7 } // end no-argument Withdrawal constructor
constructor
va
8 } // end class Withdrawal
Fig. 8.24 | Class diagram with visibility markers.
29
1 // Class Withdrawal represents an ATM withdrawal transaction 30
2
3
public class Withdrawal
{
Outline
4 // attributes
5 private int accountNumber; // account to withdraw funds from
6 private double amount; // amount to withdraw withdrawal.ja
7 va
8 // no-argument constructor
9 public Withdrawal() Declare instance
10 { variables
11 } // end no-argument Withdrawal constructor
12 } // end class Withdrawal
Fig. 8.25 | Class diagram with navigability arrows.
31
1 // Class Withdrawal represents an ATM withdrawal transaction 32
2
3
public class Withdrawal
{
Outline
4 // attributes
5 private int accountNumber; // account to withdraw funds from
6 private double amount; // amount to withdraw
withdrawal.ja
7
8 // references to associated objects
va
9 private Screen screen; // ATMs screen
10 private Keypad keypad; // ATMs keypad
11 private CashDispenser cashDispenser; // ATMs cash dispenser
12 private BankDatabase bankDatabase; // account info database
13
14 // no-argument constructor
15 public Withdrawal()
16 {
17 } // end no-argument Withdrawal constructor Declare references to other
18 } // end class Withdrawal
objects
Fig. 8.24 | Class diagram with visibility markers.
33
1 // Class Withdrawal represents an ATM withdrawal transaction 34
2
3
public class Withdrawal
{
Outline
4 // attributes
5 private int accountNumber; // account to withdraw funds from
6 private double amount; // amount to withdraw
7
withdrawal.ja
8 // references to associated objects va
9 private Screen screen; // ATMs screen
10 private Keypad keypad; // ATMs keypad
11 private CashDispenser cashDispenser; // ATMs cash dispenser
12 private BankDatabase bankDatabase; // account info database
13
14 // no-argument constructor
15 public Withdrawal()
16 {
17 } // end no-argument Withdrawal constructor
18
19 // operations
20 public void execute()
21 {
22 } // end method execute
23 } // end class Withdrawal Declare shell of a method with
return type void
Studi Kasus: Sistem Penggajian Pegawai
date
Employee -day: int;
-fullName: string; - month: int;
- birthDate: date; - year int;
-hireDate: date; + date(d,m,y);
-salary: Salary; + setDate(d, m, y);
-numberOfEmployee: int static
+employee(name, birth)
+getName(): string
+getBirthdate(); Salary
- gajiPokok
+ hitungGaji()
Tugas 3