MATERI 5 INTERAKSI ANTAR OBJEK(angga dan syahrul)
INTERAKSIANTAROBJEK
Objektidakberdirisendiri
Objekberinteraksidenganobjek-objeklainnya
Bagaimanaobjek-objekituberinteraksi?
Objekberinteraksitergantungdariinformasi
yangdibutuhkannya
ANALOGIINTERAKSIANTAROBJEK
INTERAKSIANTAROBJEK
KomunikasiA dan B :
Objek A akan mencari method Objek B yang sesuai
perintah yang akan dikerjakan.
Berdasarkanservice request, Objek A memberikan
informasi tambahan ke Objek B yang akan diproses.
Objek B harus mengetahui apakah objek A
mengharapkan objek B untuk memberikan report
balik setelah perintah dikerjakan.
METODE / METHOD
NAMINGCONVENTION
Thefirst letter of the method name is in
lowercase.
Thefirst letter of each subsequent concatenated
word in the method name is in uppercase, and
the remaining characters are in lowercase.
Wedon’t use any “punctuation” characters—
dashes, underscores, etc.—to separate these
words.
Asan example, chooseAdvisor is an appropriate
method name, whereas none of thefollowing
would be appropriate: ChooseAdvisor (uppercase
“C”), chooseadvisor (lowercase “a”),
choose_advisor (separating underscore).
PASSINGARGUMENT
10
The purpose of passing arguments into a method
is twofold[Barker05]:
To provide it with the (optional) “fuel” necessary to do
its job
To otherwise guide its behavior in some fashion
Contoh :
booleanregisterForCourse(StringcourseID,int
secNo)
boolean registerForCourse()
CONTOHPASSINGARGUMENT
11
public void test() {
int x = 5;
proses(x);
System.out.println(“x1:”+ x);
}
public void proses(int x) {
x = x + 10;
System.out.println(“x2:”+ x);
}
CONTOHPASSINGARGUMENT
12
public void test() {
int x = 5;
proses(x);
System.out.println(“x1:”+ x);
}
public int proses(int x) {
x = x + 10;
System.out.println(“x2:”+ x);
return x;
}
TIPERETURNMETHOD
13
Tipe return method yaitu :
void
tipe data primitif
tipe data user-defined (class)
array
collection
Contoh :
void setName(String newName)
voidswitchMajor(StringnewDepartment, Professor
newAdvisor)
Professor getAdvisor()
ANALOGI
14
Aktivitas“household chores”:
Taking out the trash
Mowing the lawn
Washing the car
Berarti dengan aktivitas seperti diatas akan
memilikiclassPersondengan tiga method di
dalamnya. Methodnya yaitu :
void takeOutTheTrash()
boolean mowTheLawn()
void washTheCar(Car c)
REFERENSI
BeginningJavaObject:From Concept toCode.
Author:JACQUIEBARKER
SoftwareEngineering: A Practitioner Approach
7th Edition. Author: Roger S Pressman
Objektidakberdirisendiri
Objekberinteraksidenganobjek-objeklainnya
Bagaimanaobjek-objekituberinteraksi?
Objekberinteraksitergantungdariinformasi
yangdibutuhkannya
ANALOGIINTERAKSIANTAROBJEK
INTERAKSIANTAROBJEK
KomunikasiA dan B :
Objek A akan mencari method Objek B yang sesuai
perintah yang akan dikerjakan.
Berdasarkanservice request, Objek A memberikan
informasi tambahan ke Objek B yang akan diproses.
Objek B harus mengetahui apakah objek A
mengharapkan objek B untuk memberikan report
balik setelah perintah dikerjakan.
METODE / METHOD
NAMINGCONVENTION
Thefirst letter of the method name is in
lowercase.
Thefirst letter of each subsequent concatenated
word in the method name is in uppercase, and
the remaining characters are in lowercase.
Wedon’t use any “punctuation” characters—
dashes, underscores, etc.—to separate these
words.
Asan example, chooseAdvisor is an appropriate
method name, whereas none of thefollowing
would be appropriate: ChooseAdvisor (uppercase
“C”), chooseadvisor (lowercase “a”),
choose_advisor (separating underscore).
PASSINGARGUMENT
10
The purpose of passing arguments into a method
is twofold[Barker05]:
To provide it with the (optional) “fuel” necessary to do
its job
To otherwise guide its behavior in some fashion
Contoh :
booleanregisterForCourse(StringcourseID,int
secNo)
boolean registerForCourse()
CONTOHPASSINGARGUMENT
11
public void test() {
int x = 5;
proses(x);
System.out.println(“x1:”+ x);
}
public void proses(int x) {
x = x + 10;
System.out.println(“x2:”+ x);
}
CONTOHPASSINGARGUMENT
12
public void test() {
int x = 5;
proses(x);
System.out.println(“x1:”+ x);
}
public int proses(int x) {
x = x + 10;
System.out.println(“x2:”+ x);
return x;
}
TIPERETURNMETHOD
13
Tipe return method yaitu :
void
tipe data primitif
tipe data user-defined (class)
array
collection
Contoh :
void setName(String newName)
voidswitchMajor(StringnewDepartment, Professor
newAdvisor)
Professor getAdvisor()
ANALOGI
14
Aktivitas“household chores”:
Taking out the trash
Mowing the lawn
Washing the car
Berarti dengan aktivitas seperti diatas akan
memilikiclassPersondengan tiga method di
dalamnya. Methodnya yaitu :
void takeOutTheTrash()
boolean mowTheLawn()
void washTheCar(Car c)
REFERENSI
BeginningJavaObject:From Concept toCode.
Author:JACQUIEBARKER
SoftwareEngineering: A Practitioner Approach
7th Edition. Author: Roger S Pressman
Komentar
Posting Komentar