Pbo10

36
Pemrograman Berorientasi Obyek Class Diagram [email protected]

description

java uml

Transcript of Pbo10

Page 1: Pbo10

Pemrograman Berorientasi

ObyekObyek

Class Diagram

[email protected]

Page 2: Pbo10
Page 3: Pbo10

• Sebuah bahasa pemodelan terstandar untuk

bahasa pemrograman berorientasi obyek

• UML merupakan perpaduan dari tiga

What is UML ?

• UML merupakan perpaduan dari tiga

paradigma pemodelan sistem object oriented:

– OMT (James Rumbaugh)

– OOSE (Ivan Jacobson)

– Booch (Grady Booch)

Page 4: Pbo10

What is UML ?

• UML bukan alat untuk membuat software,

UML membantu membuat model dari

software yang akan dibuat

• UML berupa gambar, berisi notasi-notasi

untuk membuat software blueprints

(rancangan)

• Digunakan juga untuk mendokumentasikan

Page 5: Pbo10

• UML untuk membuat software blueprints bagianalysts, designers dan programmers

• UML merupakan bahasa “universal” untuk pihak-pihak yang terlibat dalam pembuatan suatu

Why is UML Important

pihak yang terlibat dalam pembuatan suatusoftware

• Pada OO, modelling merupakan bagian yang sangat penting. UML membantu prosesmodelling tersebut

Page 6: Pbo10

• Menyediakan seperangkat notasi dan tools

untuk melakukan pemodelan software dengan

sederhana dan mudah digunakan

What is UML goals ?

• UML bersifat independen dari bahasa

pemrograman tertentu, UML bukan bahasa

pemrograman, UML hanya berupa notasi

untuk pemodelan software

Page 7: Pbo10

• Semua pihak yang terlibat dalam pembuatansoftware

• System Analysts, Programmers, Business Designer, dsb

Who is need UML ?

Designer, dsb

• UML berupa notasi-notasi yang berupa gambarsehingga mudah untuk dipelajari, selain itu UML juga tidak terkait pada bahasa pemrogramantertentu

Page 8: Pbo10

UML Diagrams

• Tipe diagram pada UML dibagi menjadi 2 kategori :

• Structure Diagrams

Diagram yang menggambarkan aspek statis dari system yang kita buatyang kita buat

- Contoh: Class Diagram

• Behavior Diagrams

Diagram yang menggambarkan aspek dinamis darisystem yang kita buat

- Contoh: Activity Diagram, Sequence Diagram

Page 9: Pbo10

Diagrams in the UML

• Class diagram

• Object diagram

• Use case diagram

• Sequence diagram• Sequence diagram

• Collaboration diagram

• Statechart diagram

• Activity diagram

• Component diagram

• Deployment diagram

Page 10: Pbo10

Class Diagram

� Apa yang ada pada class diagram

� Class dan interface beserta atribut dan method-

nya

� Relasi yang terjadi antar objek� Relasi yang terjadi antar objek

� Constraint terhadap objek-objek yang saling

berhubungan

� Inheritance untuk organisasi class yang lebih baik

Page 11: Pbo10

Class Diagram

• A class diagram consists of three

sections:

– The upper part holds the name of the class– The upper part holds the name of the class

– The middle part contains the attributes of

the class

– The bottom part gives the methods or

operations the class can take or undertake

Page 12: Pbo10

Tools

• Free Solution:

• Dia (Gnome)

• IBM Rational Modeler

• Kivio (KDE)• Kivio (KDE)

• Netbeans

• Umbrello UML Modeller (KDE)

• StarUML

• ArgoUML

Page 13: Pbo10

Tools

• Proprietary Solution :

• Microsoft Visio

• Rational Software Architects• Rational Software Architects

• Enterprise Architects

• Poseidon for UML

Page 14: Pbo10

Construct Description Syntax

class a description of a set of objects that share the same attributes, operations, methods, relationships and semantics.

interface a named set of operations that characterize the behavior of an

«interface»

Structural Modeling: Core Elements

characterize the behavior of an element.

component a modular, replaceable and significant part of a system that packages implementation and exposes a set of interfaces.

node a run-time physical object that represents a computational resource.

Reference: OMG tutorial on UML by Cris Kobryn

Page 15: Pbo10

Structural Modeling: Core Elements(cont’d)

Construct Description Syntax

constraint¹ a semantic condition or restriction.

{constraint}

¹ An extension mechanism useful for specifying structural elements.

Reference: OMG tutorial on UML by Cris Kobryn

Page 16: Pbo10

Construct Description Syntax

association a relationship between two or more classifiers that involves connections among their instances.

aggregation A special form of association that specifies a whole-part relationship between the aggregate (whole) and

Structural Modeling:

Core Relationships

between the aggregate (whole) and the component part.

generalization a taxonomic relationship between a more general and a more specific element.

dependency a relationship between two modeling elements, in which a change to one modeling element (the independent element) will affect the other modeling element (the dependent element).

Reference: OMG tutorial on UML by Cris Kobryn

Page 17: Pbo10

Construct Description Syntax

realization a relationship between a specification and its implementation.

Structural Modeling:

Core Relationships (cont’d)

and its implementation.

Reference: OMG tutorial on UML by Cris Kobryn

Page 18: Pbo10

• Notasi class digambarkan dengan kotak seperti

contoh berikut:

Class Diagrams

Page 19: Pbo10

Class Diagrams

• Modifier akses dilambangkan dengan 3 macam

notasi:

– (+) � public

– (-) � private

– (#) � protected

Page 20: Pbo10

� Notasi dari atribut

� visibility name: type multiplicity = default {property-string}

� Contoh

� - name: String [1] = "Untitled" {readOnly}

+ berarti public, - berarti private, # berarti protected

Class Diagrams

� + berarti public, - berarti private, # berarti protected

� “Untitled” adalah nilai yang diberikan secara default

jika tidak ditentukan saat objek dibuat

� {readOnly} adalah properti tambahan dari atribut,

dimana disini berarti tidak bisa dimodifikasi

Page 21: Pbo10

� Notasi dari operations� visibility name (parameter-list) : return-type {property-string}

� Parameter pada parameter-list dinotasikan seperti pada atribut

� direction name: type = default value

direction bisa berupa: in, out, atau inout

Class Diagrams

� direction bisa berupa: in, out, atau inout

� Contoh

� + balanceOn (in date: Date) : Money

• Bagaimana dengan constructor?

– Sama dengan methods• visibility name_constructor([parameter-list])

Page 22: Pbo10

Atribut dan Method

Page 23: Pbo10

• Contoh: Buatlah class diagram dari program java

di bawah ini:

Class Diagrams

class Anjing {public Anjing() {

System.out.println("Anjing tercipta");}}public String bersuara() {

System.out.println("Guk guk guk");}public void makan(String makanan) {

System.out.println("Sedang makan "+makanan);}

}

Page 24: Pbo10

• Bagaimana kalau class tersebut merupakan

abstract class?

• Bagaimana dengan abstract methods?

• Bagaimana kalau ada beberapa kelas

Class Diagrams

• Bagaimana kalau ada beberapa kelas

dimasukkan dalam satu package?

• Bagaimana dengan interface?

Page 25: Pbo10

Class Diagrams Example

Page 26: Pbo10

• Bagaimana kalau ada hubungan antar class

seperti inheritance, agrregation, composition,

dsb.?

• Inheritance:

Class Diagrams

Page 27: Pbo10

Generalization

Page 28: Pbo10

• Association:

Class Diagrams

Page 29: Pbo10

• Composition:

Class Diagrams

Page 30: Pbo10

• Whole-part (aggregation):

Class Diagrams

Page 31: Pbo10

Composition

� 'has a' or 'contains a' relationship (whole-part)

� Kampus memiliki fakultas CS atau kampus terdiri

dari fakultas CS (salah satunya)

� Jika tidak ada fakultas, tidak mungkin ada kampus� Jika tidak ada fakultas, tidak mungkin ada kampus

Page 32: Pbo10

Aggregation

� Sebuah ruangan memiliki meja dan kursi

� Tanpa kehadiran ruang, meja dan kursi bisa

tetap ada

Page 33: Pbo10

Class diagram Example

Page 34: Pbo10

Class diagram Example

Page 35: Pbo10
Page 36: Pbo10

NEXT

• Exception Handling in Java