You are on page 1of 35

Class Diagram

Agenda
• What is a Class Diagram?
• Essential Elements of a UML Class Diagram
What is Class Diagram?
• Class diagram is a static diagram. It represents the static view of an
application. Class diagram is not only used for visualizing, describing, and
documenting different aspects of a system but also for constructing
executable code of the software application.
• Class diagram describes the attributes and operations of a class and also
the constraints imposed on the system. The class diagrams are widely
used in the modeling of objectoriented systems because they are the only
UML diagrams, which can be mapped directly with object-oriented
languages.
• Class diagram shows a collection of classes, interfaces, associations,
collaborations, and constraints. It is also known as a structural diagram.
Purpose of Class Diagrams
Class diagrams are the only diagrams which can be directly mapped
with object-oriented languages and thus widely used at the time of
construction.
The purpose of the class diagram can be summarized as −
• Analysis and design of the static view of an application.
• Describe responsibilities of a system.
• Base for component and deployment diagrams.
• Forward and reverse engineering.
Basic Components of a Class diagram
The standard class diagram is composed of three sections:
• Upper section: Contains the name of the class. This section is always
required, whether you are talking about the classifier or an object.
• Middle section: Contains the attributes of the class. Use this section
to describe the qualities of the class. This is only required when
describing a specific instance of a class.
• Bottom section: Includes class operations (methods). Displayed in list
format, each operation takes up its own line. The operations describe
how a class interacts with data.
Member Access Modifiers
All classes have different access levels depending on the access
modifier (visibility). Here are the access levels with their corresponding
symbols:
• Public (+)
• Private (-)
• Protected (#)
• Package (~)
• Derived (/)
• Static (underlined)
Interactions
• The term "interactions" refers to the various relationships and links
that can exist in class and object diagrams. Some of the most
common interactions include:
Inheritance
• The process of a child or sub-class taking on the
functionality of a parent or superclass, also known as
generalization. It's symbolized with a straight connected line
with a closed arrowhead pointing towards the superclass.
• In this example, the object "Car" would inherit all of the
attributes (speed, numbers of passengers, fuel) and
methods (go(), stop(), changeDirection()) of the parent class
("Vehicle") in addition to the specific attributes (model type,
number of doors, auto maker) and methods of its own class
(Radio(), windshieldWiper(), ac/heat()). Inheritance is shown
in a class diagram by using a solid line with a closed, hollow
arrow.
Bidirectional Association
• The default relationship between two classes. Both classes are aware of each
other and their relationship with the other. This association is represented by
a straight line between two classes.
• In the example above, the Car class and RoadTrip class are interrelated. At one
end of the line, the Car takes on the association of "assignedCar" with the
multiplicity value of 0..1, so when the instance of RoadTrip exists, it can either
have one instance of Car associated with it or no Cars associated with it. In
this case, a separate Caravan class with a multiplicity value of 0..* is needed to
demonstrate that a RoadTrip could have multiple instances of Cars associated
with it. Since one Car instance could have multiple "getRoadTrip" associations
—in other words, one car could go on multiple road trips—the multiplicity
value is set to 0..*
Unidirectional Association
• A slightly less common relationship between two classes. One class is
aware of the other and interacts with it. Unidirectional association is
modeled with a straight connecting line that points an open
arrowhead from the knowing class to the known class.
How to Draw a Class Diagram?
The following points should be remembered while drawing a class diagram −
• The name of the class diagram should be meaningful to describe the aspect of
the system.
• Each element and their relationships should be identified in advance.
• Responsibility (attributes and methods) of each class should be clearly
identified
• For each class, minimum number of properties should be specified, as
unnecessary properties will make the diagram complicated.
• Use notes whenever required to describe some aspect of the diagram. At the
end of the drawing it should be understandable to the developer/coder.
• Finally, before making the final version, the diagram should be drawn on plain
paper and reworked as many times as possible to make it correct.
Example of class Diagram
The following diagram is an example of an
Order System of an application. It describes a
particular aspect of the entire application.
• First of all, Order and Customer are identified
as the two elements of the system. They have
a one-to-many relationship because a
customer can have multiple orders.
• Order class is an abstract class and it has two
concrete classes (inheritance relationship)
SpecialOrder and NormalOrder.
• The two inherited classes have all the
properties as the Order class. In addition, they
have additional functions like dispatch () and
receive ().
Class Diagram for a hotel management
system
• A class diagram can show
the relationships between
each object in a hotel
management system,
including guest information,
staff responsibilities, and
room occupancy. 
ATM class diagram
• ATMs are deceptively simple:
although customers only need to
press a few buttons to receive cash,
there are many layers of security
that a safe and effective ATM must
pass through to prevent fraud and
provide value for banking
customers. The various human and
inanimate parts of an ATM system
are illustrated by this easy-to-read
diagram—every class has its title,
and the attributes are listed
beneath.
Class Diagram
• Menggambarkan Objek/Class pada sistem
• Contoh :
• Object Class Program
• Tabel Data Pada Database
Object – Class Diagram
• Atribut
• Operation/Function/Method
• Relationship
• Note / Keterangan (Opsional)
Class – Class Diagram
Class ICON – Class Diagram
Relation – Class Diagram
Indikator Relation – Class Diagram
Indikator Variable – Class Diagram
Contoh – Class Diagram
• Setiap Nomor Rekening Harus Memiliki ATM
Contoh – Class Diagram
• Satu dosen memiliki (kediaman) atau tinggal di satu wilayah,
sedangkan wilayah tersebut bisa saja mempunyai banyak dosen
Contoh – Class Diagram
• Satu dosen tidak harus terdata wilayah, sedangkan wilayah tersebut
bisa saja mempunyai banyak dosen
Contoh – Class Diagram
• Many To Many Association
• 1 (satu) dosendapat mengajar banyak mata kuliah dan 1 (satu) mata
kuliah dapat diajarkan oleh banyak dosen.
Contoh – Class Diagram
• Terdapat tabel pegawai, dimana diantara pegawai tersebut terdapat
pimpinan dari pegawai-pegawai lainnya. Tetapi pimpinan tertinggi
tidak dipimpin oleh pegawai lainnya dengan kata lain pimpinan
tertinggi adalah top level
• Dua atau lebih class dapat melakukan berbagai atribut dan method
Figure 8-7

Attributes

 = private
+ = public Methods
() = attribute affected by,
input data
: string, number = data type

3510 Systems Analysis & Design * Bob Travica 28 of 9


 Class adalah sebuah spesifikasi yang jika diinstansiasi akan
menghasilkan sebuah objek dan merupakan inti dari pengembangan
dan desain berorientasi objek. Class menggambarkan keadaan
(atribut/properti) suatu sistem, sekaligus menawarkan layanan untuk
memanipulasi keadaan tersebut (metoda/fungsi).
 Class diagram menggambarkan struktur dan deskripsi class, package
dan objek beserta hubungan satu sama lain seperti containment
(pengurungan/penspesifikasian), pewarisan, asosiasi, dan relasi yang
lain.
 Class dapat merupakan implementasi dari sebuah interface, yaitu
class abstrak yang hanya memiliki metoda. Interface tidak dapat
langsung diinstansiasikan, tetapi harus diimplementasikan dahulu
menjadi sebuah class.
 Sebagai contoh, jika ada interface remote control TV yang dapat
menambah, mengurangi volume atau mengganti channel (beberapa
metoda dalam 1 interface). Tapi pengimplementasian’nya dapat di
berbagai macam class TV berdasarkan merek TV tersebut.
“ Class diagrams describe three different perspectives when designing
a system, conceptual, specification, and implementation. ”
 Konseptual disini mengajarkan bahwa secara konsep yang kita dapat
itu bisa beraneka ragam, dan banyak bentuk pengerjaan saat kita
memulai dari awal pembuatan sistem.
 Spesifikasi disini menjelaskan bahwa untuk menerangkan suatu
sistem yang akan kita bangun, akan semakin spesifik dari setiap tahap
yang sudah dilewati oleh pembuat / pengembang sistem. Semakin
kita membuat suatu rincian alur program untuk mendapatkan hasil
yang maksimal, supaya dapat dimengerti oleh user, maka spesifikasi
design sistem kita akan semakin terlihat.
• Implementasi disini menjelaskan bahwa pada waktu implementasi
sistem yang sudah kita gambarkan secara abstrak di “tool” yang sudah
kita gunakan, ini dapat membantu “paling tidak” dapat menjelaskan
alur sistem yang sedang dibangun. Hubungan antar objek yang kita
gambarkan dalam Class Diagram akan membantu dalam
implementasi sistem di “lokasi” serta kita dapat menjelaskan lebih
detail apa yang sudah kita rancang. Akan tetapi tidak menutup
kemungkinan adanya “enginnering change” (perubahan rancang
bangun) sistem.
MAHASISWA Nama Class

+ NIM:String
+ NAMA:String
Attribut Class
+ ALAMAT:String
+ TGLLAHIR:Date

tambahMhs()
updateMhs() Behaviour Class
hapusMhs()

NIM : 2 digit pertama adalah tahun,


digit 3 dan 4 adalah angkatan, digit 5 Keterangan
adalah jenjang (tambahan / option)
RELATION – CLASS DIAGRAM

MAHASISWA WILAYAH

+ NIM:String 1..* 1 +kdPos:String


+ NAMA:String +nmWilayah:String
+ ALAMAT:String
+ TGLLAHIR:Date tambahWLY()
updateWLY()
tambahMhs() hapusWLY()
updateMhs()
hapusMhs()
selectWLY(kdPos)

INDIKATOR

You might also like