Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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.
Object Composition
10
Class Representation
...
}
11
Aggregation or Composition
12
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
18
ClassName
• The arg list is a list of parameter types (e.g., int, double, String);
• Parameter names are not included in the UML class diagram
• Methods that don't return a value (i.e. void methods) should give a
return type of void
• Class (i.e. static) methods and fields are indicated by underlining
• Constant (i.e. final) fields are indicated via naming convention:
constants should be in ALL_CAPS
public class Employee {
Register( ) Name
Students Submit Score( ) 0..* Value
Print Transcript( )
Student/Grades
Print
Transcript
Addition of a New Student Type
Student
Register Score
Submit
Student Register( ) Name
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
Transcript Report Print Transcript( )
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( )
30
Starting to Program the Classes of the ATM System
31
Fig. 8.24 | Class diagram with visibility markers.
32
1 // Class Withdrawal represents an ATM withdrawal transaction 33
2
3
public class Withdrawal
{
Class for
Outline
4 // no-argument constructor
Withdrawal
5 public Withdrawal() •
Empty no-argument withdrawal.ja
6 {
constructor va
7 } // end no-argument Withdrawal constructor
8 } // end class Withdrawal
Fig. 8.24 | Class diagram with visibility markers.
34
1 // Class Withdrawal represents an ATM withdrawal transaction 35
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.
36
1 // Class Withdrawal represents an ATM withdrawal transaction 37
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; // ATM’s screen
10 private Keypad keypad; // ATM’s keypad
11 private CashDispenser cashDispenser; // ATM’s 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.
38
1 // Class Withdrawal represents an ATM withdrawal transaction 39
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; // ATM’s screen
10 private Keypad keypad; // ATM’s keypad
11 private CashDispenser cashDispenser; // ATM’s 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