Anda di halaman 1dari 14

Class Diagram Membantu dalam visualisasi struktur kelas-kelas dari suatu system dan hubungan antar kelas (inheritance,

, aggregation, and association) dan penjelasan detail tiap kelas (methode/function/behavior dan atribut/property/data) Diagram ini merupakan fondasi untuk component diagram dan deployment diagram Diagram paling penting pada object oriented analysis and design Class digambarkan dengan sebuah kotak dengan 3 section
Mahasiswa NIM NAMA ALAMAT Kuliah() Cuti() KKP() Class Name Atribut/ Property/ Data Methode/ Function/ Behavior

Disarankan untuk tidak menggambar tanpa 3 section ini Kadang-kadang boleh ada section tambahan untuk menggambarkan keterangan class Setiap atribut/methode/association diperbolehkan ada sebuah keterangan atribut/methode yang diletakkan diantara tanda { } Sebuah class atau atribut/methode bisa mempunyai dokumentasi dengan lambang dibawah ini dan ditarik dengan garis putus tanpa panah
Ganjil 2005/2006

Class Diagram Visibility Menyatakan level akses sebuah object Visibility dapat diterapkan pada atribut atau methode Tampilkan visibility secara urut berkelompok mulai dari urutan tertinggi Type data (int,float,char) dari sebuah atribut dapat disertakan design class model define the structure of your object source code and therefore should reflect the naming conventions for the implementation language that you using There are 4 types
Visibility Public Protected Private Symbol + # -

Contoh :
class A

# A2 : int = 100 - A1 : int + ENTRYA1( ) : void + ENTRYA1( ) : void

Ganjil 2005/2006

Class Diagram
Contoh konsep Inheritance pada class Contoh Program class B public public

class A
Private A1 Protected A2 Public Entry A1( ) EntryA2( )

# include<iostream.h> Private class A Protected { int A1 ; A2 protected: Public Entry A1( ) int A2; EntryA2( ) public: void ENTRYA1( ) { cout<<"Entry A1 ="; cin>>A1; } void ENTRYA2( ) { cout<<"Entry A2 ="; cin>>A2;} }; class B : public A { int B1; public: void ENTRYB( ) {cout<<" B1 = "; cin>>B1; // cout<<" A1 = "; cin>>A1;//error cout<<" A2 = "; cin>>A2; } };

private private

class C
Private A2 Entry A1( ) EntryA2( ) Protected Public

class C:A { int C1; public: void ENTRYC() { cout<<"C1 =";cin>>C1; // cout<<"A1 =";cin>>A1;//error cout<<"A2 =";cin>>A2; } }; void main() { B JONI; C TUTI; JONI.ENTRYB( ); JONI.ENTRYA1( ); JONI.ENTRYA2( ); TUTI.ENTRYC( ); //TUTI.ENTRYA1( );//ERROR //TUTI.ENTRYA2( );//ERROR }
Ganjil 2005/2006

Class Diagram
Association classes/link classes (Many to Many association) Which is used to model association that have methods and attributes depicted as class attached via a dashed line to association Programming language such as C++ and java do not (yet) have native support this concept Do not name association that have association classes Center the dashed line of an association class Kurangi penggunaan association class ini, sehingga tidak perlu menambah sebuah pekerjaan pada tahap analisa

Berikut ini adalah gambar class diagram dari gambar diatas yang tanpa menggunakan association class

Ganjil 2005/2006

Class Diagram

Relationship
Association Inheritance/generalization Aggregation Composition Dependencies Realizations

Association
When classes are connected together conceptually, that connection is called an association An association allows one class to know about the public attributes and methode of another class Center names on association Gunakan kalimat singkat Indicate directionality with a filled triangle ( ) to clarify an association name Sebuah association dimungkinkan adanya sebuah constraint yang menggambarkan sebuah kondisi (lihat gambar dibawah ada kata NAND) Indicate role names when multiple associations between 2 classes exist Role names are optionally indicated on association ends to indicate how a class is involved in the association Role names can be used to clarify recursive associations
Ganjil 2005/2006

Association - Class Diagram Association unidirectional menggunakan garis berpanah terbuka Association bi-directional menggunakan garis tanpa panah Multiplicity indicator Association may be drawn as a diamond for association with more than two Indicator Meaning Example ends
0..1 0..* 0..n 1 1..* 1..n * n n..* n..m Zero or one Zero or more Zero to n (where n>1) One only One or more One to n (where n>1) Many Only n (where n>1) n or more, where n >1 Where n& m both >1 0..3

Binary and Ternary association Contoh :

1..5 9 7..* 3..10

Dibaca : 1 object Mahasiswa punya 0..* object Nilai dan 1 object Nilai dipunyai 1 object Mahasiswa

Ganjil 2005/2006

Inheritance/generalization - Class Diagram Two or more classes will share the same attributres and/or the same methods Inheritance use a line with a closed arrowhead ( ) pointing from the sub class to the super class Place sub class below super class A sub class should inherit attributes and methods of its superclass

Ganjil 2005/2006

Aggregation and Composition - Class Diagram


Represent is part of relationship, ketika sebuah class dibuat berdasarkan class lainnya maka gunakanlah aggregation atau composition When deciding whether to use aggregation or composition over association, you can say if in doubt, leave it out There is very little difference between association, aggregation and composition at the coding level

Aggregation Aggregation menggunakan lambang diamond terbuka Aggregation is a specialization of association, specifying a whole part relationship between objects Composition Composition menggunakan lambang diamond tertutup Composition is a strong type of a aggregation Composition is a stronger form of aggregation where the whole and parts have coincident lifetimes, and it is very common for the whole to manage the lifecycle of its parts

Ganjil 2005/2006

Dependencies and Realizations - Class Diagram Dependencies Dependencies adalah Sebuah class yang membutuhkan class lain untuk spesifikasi classnya Dependencies is shown as a dashed open headed arrow Contoh:

Class mobil bergantung pada class Mesin Realizations Realizations adalah sebuah relasi antar 2 buah class, dimana class lainnya mewakili sebuah class implementation (implementation of the later) Realizations is shown as a dashed close headed arrow Disebut dengan istilah lain Interfaces (lihat materi berikutnya) The relationship between a class and interfaces is called realization
atau

Ganjil 2005/2006

Interfaces - Class Diagram An interface is a set of operation that specifies some aspect of a classs behavior Interfaces adalah kumpulan fungsi yang dapat dipakai pada class tanpa menjadi behavior suatu class. Di bahasa C++ disebut friend function Friend function become friend more than 1 class Friend function can access private from the other class Friend function isnt member a class
Contoh: program //Static harus dicompile pake turbo c #include<iostream.h> class barang { char nama[20]; float harga,jumlah; static float bayar,total; public: void entry( ) { cout <<"entry nama :";cin>> nama ; cout <<"entry jumlah:";cin>>jumlah; cout <<"entry harga :";cin >>harga ; } static void proses(barang B1) { bayar =B1.harga * B1.jumlah; total =total + bayar; } friend void tampil (barang B1); float kasir( ) { return total;} }; void tampil(barang B1) { cout <<"nama barang :" ; cout<<B1.nama <<endl; cout <<"harga barang :"<<B1.harga <<endl; cout <<"jumlah barang :"<<B1.jumlah<<endl; cout <<"bayar :"<<B1.bayar <<endl; }

main() { barang buku,tas,pena; buku.entry( ); tas.entry( ); pena.entry( ); buku.proses(buku); buku.proses(tas ); buku.proses(pena); tampil(buku); tampil(tas ); tampil(pena); cout<<"jumlah bayar="<<buku.kasir( ); return 0; }
Ganjil 2005/2006

Interfaces - Class Diagram The relationship between a class and interfaces is called realization Sebuah interfaces dapat digambarkan dengan cara association sebuah class dengan cara: sebuah class ditulis <<interfaces>> dengan tidak mempunyai attributes small circle connected by a line to the class A class can realize more than 1 interfaces, and an interfaces can be realized by more than 1 class

Ganjil 2005/2006

Class Diagram

Ganjil 2005/2006

Kerangka berfikir object


Penentuan Matrikulasi Staff Pendaftaran Entry Pendaftaran Cetak Kwitansi Pendaftaran Sekretaris Program
No Pendaftaran Nama Tempat Tgl Lahir Jenis Kelamin Alamat

Layar/GUI

Catatan
PENDAFTARAN
Tgl Pendaftaran Kode Angkatan Type Mahasiswa mm Wanita Telp Kantor Telp Rumah x 15 - x x 15 - x xxxx Total Pembayaran Dd / mm / yyyy Tampil Tampil 99,999,999 Pria HP X 15 - x Kelengkapan Dokumen Tampil

X7-x x 25 - x x 30 - x dd

X 100 - x

Kota

X 25 - x X 10 - x X 30 - x

Staff Keuangan

Kode Pos

E-mail

Agama Konsentrasi yang diminati Jadwal Wawancara Waktu Wawancara

Tampil Tampil Dd/mm/yyyy X - 10 - x Type Pembayaran Tempo Dp Discount Pembayaran Tunai 99 Kali Cicilan

9,999,999 999,999 99,999,999

Riwayat Pendidikan No 99 Nama Universitas X 30 - x Program Studi X 30 - x Thn Lulus xxxx Jenjang Pendidikan xx

Modul Control
Clear Save Update

Delete

Exit

Table/Relasi

Object yg terlibat pada saat Use Case Fill order

Ganjil 2005/2006

Object Diagram Hubungan antara object digambarkan Menggambarkan object dan dengan sebuah garis tanpa panah yang hubungannya dalam urutan berisi sebuah role/peran, role ini boleh time, umumnya sebuah special dipakai atau tidak case dari class diagram atau communication diagram Digambarkan sebagai sample diagram (diagram yang menggambarkan sample object dari sebuah class dan relasi diantaranya) Sebuah object dapat digambarkan dengan cara Nama object : nama class
Joni : anggota

:nama class dan nilai atribut yang terdapat pada section ke-2
:Anggota Nama=Joni
Ganjil 2005/2006

Anda mungkin juga menyukai