OBJECT MODELINGPertemuan 9
Matakuliah : Konsep object-orientedTahun : 2009
Object Modelling
Modelling• Model adalah representasi dari bagian dunia
nyata• Modeling adalah proses mengambarkan dan
mengorganisir fitur-fitur yang berarti dari bagian dunia nyata.
• Sebuah model yang baik akan merepresentasikan hanya fitur dari kenyataan yang berguna dan mengabaikan detail yang tidak relevan
Kegunaan Model:• Untuk komunikasi• Menangani kompleksitas• Digunakan dalam setiap tahap pembangunan
sistem
Untuk komunikasi• Komunikasi dengan klien atau user dengan
developer, atau developer dengan developer• Sekarang ini model biasanya menggunaka
diagram grafik, teks atau keduanya• Dengan model dapat mengidentifikasi perbedaan,
mengurangi ketidak konsistenan dan salah pengertian.
• Lebih mudah dan menghasilkan umpan balik
Untuk menangani kompleksitas• Model membantu developer untuk
mengkomunikasikannya dengan klien dan membantu klien mengerti tentang sistem yang baru.
• Menangani kompleksitas dengan cara:– Dekomposisi: membagi problem menjadi ukuran yang
dapat dimengerti oleh otak– Abstraction: berkonsentrasu oada detil yang penting dan
mengabaikan detail yang tidak relevan.
Tahap berbeda didalam pembangunan sistem
• Dapat menggunakan model dari tahap awal sampai tahap selanjutnya.
Class Diagram• Titik awal dari O-O sistem development adalah
sebuah obyek, tetapi konsep utama dari setiap tahap adalah class diagram.
Class Diagram(lanj’)• Untuk setiap class, diagram terdiri dari atribut
dan operasi yang berhubungan dengannya.• Class diagram berdasarkan data, lebih stabil
daripada proses.• Struktur yang berdasarkan data memberikan
dasar yang kuat ketika sistem dibuat.
Tahap membuat class diagram• Tahap membuat class diagram:
– Identifikasikan obyek dan class turunannya– Identifikasikan atribut class– Mulai membuat kamus data– Identifikasikan operasi tiap class– Gunakan teknik CRC untuk mengkover tanggung
jawab dan kolaborasi– Identifikasikan hubungan antar class,
menggunakan asosiasi, agregasi dan inheritance– Iterasikan dan definisikan model
Identifikasikan obyek dan class turunannya
• Identifikasikan obyek fisik dan konsep yang potensial didalam problem domain
Just A Line management wishes to increase security, both their building and on site, without antagonizing their employees. They would also like to prevent people who are not part of the company from using the Just a Line car park.
It has been decided to issue identity cards to all employees, which their expected to wear while on Just a Line sites. The card records the name, departement and number the member of staff, and permit access to the Just A Line car park.
A barrier and card reader are placed at the entrance to the car park. The driver of an approaching car inserts his or her numbered card in the card reader, which then checks that number is known to the Just A Line system. If the card is recognized, the reader send a signal to raise the barrier and the car able to enter the car park
A the exit, there also barrier, which raised when a car wishes to leave the car park.
When there are no spaces in the car park a sign at the entrance display Full and is only switched off when a card is leaves.
Special visitors cards which record a number and the current date also permit acces to the car park. Visitors cards may be sent out in advance, or collected from reception . All visitors cards must be returned to reception when visitor leave Just A Line
• Daftarkan obyek fisik dan obyek konsep yang ada diproblem domain
Just A Line management security building
site employee people company
car park card name departement
number member of staff access barrier
card reader entrance driver car
system signal exit space
sign visitor reception
• Pelajari obyek dan buat obyek yang tidak berguna. Buang jika :– Duplikat– Tidak relevan– Mempunyai arti ganda– Terlalu umum– Merupakan atribut– Merupakan asosiasi– Merupakan aturan(Roles)– Merupakan implementasi
management security building
site employee people company
car park card name departement
number access barrier
card reader entrance driver car
system signal exit space
sign visitor reception
Duplikat• Jika ada dua atau lebih obyek yang berbeda nama tetapi
menunjuk ke hal yan sama, hanya satu yang digunakan, buang yang lainnya
• Contohnya : employee/member of staff dan company/Just a Line
Just A Line
member of staff
security
employee people
car park card name departement
number access barrier
card reader entrance driver car
system signal exit space
sign
Tidak relevan• Obyek berada didalam problem domain tetapi tidak merupakan
bagian dari sistem, dibuang saja• Contohnya : management, site, company, visitor dan reception
management buildingsite company
visitor reception
Mempunyai arti ganda (Vague) • Ketika sebuah kata dibaca dengan hati-hati, kadang sebuah
kata tidak mempunyai arti yang tepat sehingga tidak dapat dijadikan basis data contohnya : security dan people
employee
car park card name departement
number access barrier
card reader entrance driver car
system signal exit space
sign
securitypeople
Terlalu umum• Sebuah kata seperti kata sistem tidak bisa menjadi class
yang berguna karena terlalu umum artinya:
employee
car park card name departement
number access barrier
card reader entrance driver car
signal exit space
sign system
employee
car park card
access barrier
card reader entrance driver car
signal exit space
sign
Attributes• Sometime we discover a word is a part of some other
class. Such departement, name and number may be would be attributes of the class card
name departementnumber
Asosiasi• Kadang sebuah kata, seperti “ACCESS” keluar sebagai
obyek, tetapi sebetulnya kata tersebut mewakili relasi antar obyek
employee
car park card
barrier
card reader entrance driver car
signal exit space
sign
access
Aturan (Roles)• Jangan ambil sebuah kata yang bersifat aturan(role)
sebagai anggota class diagram kata “driver” hanya berlaku sementara, sesorang yang mengendarai kednaraan bermotor, jika sudah tidak mengendarai tidak dapat disebut driver lagi
employee
car park card
barrier
card reader entrance car
signal exit space
sign
driver
Implementasi
• Jangan mengambil sebuah kata sebagai class, jika kata tersebut nantinya akan digunakan diwaktu implementasi contoh “SIGNAL”
employee
car park card
barrier
card reader entrance car
exit space
sign signal
• Find any missed class– Is common sense if we have include a “sensor” into
class, because need sensor for each barrier to opened the barrier if any car arrives and leaves.
• Potential class in Just A Line
Car Park Staff Card Visitor Card Employee
Entrance Exit Card reader Barrier
Full Sign Space Sensor Car
Identifikasikan atribut sebuah class• Identifikasikan aribut dari kata-kata. • Kumpulkan data yang penting dan relevan tentang obyek
tersebut dan buang informasi yang tidak relevan• Buang atribut jika dapat diturunkan dari class lain.• Ketika kita memikirkan atribut. Sering kali kita menemukan
bahwa:– Detil yang sama dari dua class yang berbeda, misalnya
employee dengan staf card, artinya salah satunya tidak berguna, dapat dibuang.
– Tidak ada atribut atau sesuatu yang dilakukan oleh class tersebut, contohnya : entrance, exit, car and space, karena tidak berguna dapat dibuang
Car Park Staff Card Visitor Card
Card reader Barrier
Full Sign Sensor
Employee
Entrance Exit
Space Car
Mulai membangun kamus data
Car Park : represent the physical car park and keeps count of the
number of spaces available
Staff Card : a card, issued to a member of the just a line staff. That record the staff member number, name and departement. The number uniquely identifies. The card also permits access to Just A Line car park
Visitor Card : a card, with permit access to Just A Line car park. Given to someone visiting the company. The card record number and the current date. Visitor card may be send out in advanced or collected from reception and all cards must be returned to reception when visitor leave from Just A Line.
Card reader: a machine that read a card that is input and check the card number against a list of valid number. If the card is valid , the reader sends a signal to raise the barrier
Barrier: a bar, which raise or lower itself according the signal received from either other associate sensor or card reader.
Sensor: a device for detecting the presence of a card
Identifikasikan operasi yang dilakukan class
Car Park
Capacity
spaces
inc.spaces()
dec.spaces()
Spaces left()
Gunakan CRC card untuk menembukan tanggung jawab
dan kolaborasi
• CRC(class-responsibility-collaboration)
• CRC card adalah bagian dalam metode pendekatan sistem dengan nama Responsibility-Driven-Design
Full Sign
On : Boolean
Switch on()
Switch of()
• Tujuan dari Responsibility Driven Design adalah untuk melihat semua fungsi didalam sistem dan membaginya kedalam class.
• Tanggung jawab untuk menyediakan layanan bagi class lain.
• Contoh:– Class Full sign
bertanggung jawab untuk menyala ketika tidak ada lagi tempat yang tersisa didalam parkir dan padam ketika ada tempat kosong(tersedia)
Full Sign
On:Boolean
Switch on()
Switch off()
• Kadang sebuah class berlaku sebagai server dan memberikan layanan kepada class lain dan di lain waktu berlaku sebagai client menerima layanan dari class yang lainnya
Car Park
Capacity
spaces
Inc.spaces()
Dec.spaces()
Spaces left()
Barrier
Up:boolean
Raise()
Lower()
Full Sign
On:boolean
Switch on()
Switch off()
• Sebuah contoh CRC Card dengan responsibilities and collaborations
Barrier
Responsibillity Collaborator
Raise()
Lower()
Sensor
Sensor
• Jika sebuah class tidak menjadi solusi yang fleksibel
Card reader
Valid card nos.
Read card()
Card OK()
Card reader
Read card()
Valid Card
Valid card nos.
Card OK()
Identifikasikan hubungan apakah menggunakan association, aggregation
atau inheritance• Asosiasi(association) : hubungan singkat antar
obyek.
StudentCourse
0..* 1..*
studies
Zero or one 0..1Exactly one 1(or ommited)Zero, one or many *, or 0..*One or more 1..*An exact number 2,3,4, 24An a range 2..3,4..6
Card reader
Read card()
Valid Card
Valid card nos.
Card OK()
1..*
1
• Agregasi(Aggregation): hubungan antar obyek ketika sebuah class terdiri dari class yang lain (“part of”, ”consist of”, “made up of”).
2..* 2..* 1..*
1..*
Car ParkCar Park
BarrierBarrier Sensor Sensor Card ReaderCard Reader
Full SignFull Sign
• Inheritance: ketika sebuah obyek merupakan spesialisasi dari class yang lain.
• Kadang orang lain menyebutnya Gen-Spec
Card
card number
delete()
Visitor Card
current date
delete()
Staff Card
namedeptexpiry date
delete()
2..* 2..* 1..*
1..*
Car ParkCar Park
BarrierBarrier Sensor Sensor Card ReaderCard Reader
Full SignFull Sign
Sebuah class diagram komplit Just A line
Kamus data(Data Dictionary)• Kamus data merupakan sumber keterangan
utama tentang data.• Kamus data menyediakan cara yang pasti untuk
mencatat data.
• Notasi kamus data:– Harus mengekspresikan:
• Urutan atribut yang muncul;• Atribut atau grup atribut yang berulang;• Atribut yang opsional;• Atribut merupakan pilihan yang harus dipilih;
• Notasi kamus dataSymbol Arti Keterangan
= Terdiri dari (Consist of)
Mengindikasikan permulaan definisi dari data item
+ Dan(And) Pengabungan definisi komponen didalam urutan
{ } Satu atau lebih(One on more)
Atribut mungkin berulang
( ) Kosong atau satu(Zero or one)
Atribut adalah opsional
[ ] Pilihan(alternatives) Isi yang berada dalam kotak merupakan pilihan yang dapat dipilih, [ ]
| Atau(Either.. Or) Alternatif pilihan dipisahkan dengan garis vertikal
“ ” Nilai khusus(Specific value)
Mengindikasikan pilihan khusus contoh [“Y”|”T”]
*..* Komentar(comment)
Komentar berada didalam tanda asterik
• Contoh employee obyek
:Employee
Number=JL104
Title = Mrs.
First name = Anne, Christine
Last name = Raines
Address = 46, ferry road.
Phone number = 1231312
Dept.= account
Jika dilukiskan dalam kamus data dapat berbentuk seperti ini
Employee = number + (title) + {first name}+ last name + address + phone number+ dept
Lebih tepatnya:
Employee = number + (title) + 1{ [ first name | title ] }3+ last name + address + phone number+ dept
Lebih dalam lagi
Dept. = [“Accounts” | “Design” | “Marketing” | “Administration” ]
• Mendeskripsikan dokumen
Just A Line Car Park List April 2003name Dept. Ext. Car make model Number Colour
Sue Preston 316 Renault Clio P0146JPG Red
Harry Preston 360 Porsche Carrera JAL 1 Silver
Annie Raines Account 465 Volvo 349 H4624KL White
Chris doolan Design 767 VW Golf 6883PP Green
Chris doolan Design 767 Renault Escape 65765 Grey
– Dari dokumen tersebut dapat didefinisikan kamus data
Car Park List = month + year+ {employee name + (dept). + ext + 1{ car make + car model + car number + car colour } 2}
Untuk mencegah kesalahan membaca dan membuat mudah dalam membacanya maka kamus data tersebut ditulis :
Car Park List = Date + { entry }Date = month + yearEntry = employee + { Car }2
Employee = name + ( dept ) + extension Dept. = [“account” | “Design” | “Marketing” | “Administration” ]Car = make + model + number + colour
Langkah berikutnya adalah• Membuatnya lebih detil dan• Gambarkan operasi nya ) contohnya pada halaman berikut:
Disarikan dari kamus data sistem parkir just a line
Barrier = Barrier type + up Barrier type = [“entrance”|”exit”] up = [“true”|”False”] raise: if the barrier not already raised, this operation takes an argument an object if the barrier class and returns an object of the same class. With the up attribute set to “true”. If the barrier is already up the operation returns the error message “Barrier already raised”. lower: if the barrier not already lower, this operation takes an argument an object if the barrier class and returns an object of the same class. With the up attribute set to “False”. If the barrier is already down the operation returns the error message “Barrier already lowered”.
Card = Number + [staff card|visitor card] delete: this operation remove the card from the set of cards known to Just A Line.
Car Reader = location read card: this operation takes a card number as input and check it against the number of known card in the Valid Card class
Car Park = capacity + spaces capacity:*the total number of parking places in the car park*
spaces:*the number of currently free spaces in the car park* inc.spaces: this operation check that the car park is not empty (number of
spaces left is not equal to capacity of the car park. In this the case the value of “space” increment by 1.
dec.spaces: this operation check that value of attributes in the car park is greather than 0. in this the case the value of space decrement by 1
Full sign = location + on on = [ “true”|”false”] switch on: switch off:
Sensor = Car Sensed car sensed=[“true”|”false”] sense car:if a car is detected by the sensor , this operation sets the car sensed
attribute to “true”
Staff Card = name + dept + expiry date name = first name + last name Dept. = [“Accounts” | “Design” | “Marketing” | “Administration” ] expiry date = *date after which card is no longer valid* delete: if the expiry date on the card has passed, this operation removes the
card number from the list of known to just a line.
Valid Card = known card * the set of cards whose numbers are recorgnized by Just A Line
Visitor card = current date * date that the card is issued* delete:if the date on the card has passed, this operation removes the card number
from the list of known to just a line