Top Banner
Abstract & Interface GOF Design Pattern Tim Asisten Praktikum PSBO 08/09
42

Abstract & Interface GOF Design Pattern

Feb 02, 2016

Download

Documents

Jihan

Abstract & Interface GOF Design Pattern. Tim Asisten Praktikum PSBO 08/09. Once upon a time. Buat program tentang simulasi hewan untuk anak sayaa!. Boss besar. Yawda, desain dulu aja. Aha! Gimana kalo bikin hewan-hewan jadi objek?. 1. Lihat atribut dan behaviour!. Atribut : picture - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Abstract & Interface GOF Design Pattern

Abstract & InterfaceGOF Design Pattern

Tim Asisten Praktikum PSBO 08/09

Page 2: Abstract & Interface GOF Design Pattern

Once upon a time..

Buat program tentang simulasi

hewan untuk anak sayaa!Boss besar

Yawda, desain

dulu aja..

Aha! Gimana kalo bikin hewan-hewan jadi objek?

Page 3: Abstract & Interface GOF Design Pattern

1. Lihat atribut dan behaviour!

• Atribut :– picture– food– hunger– boundaries– location

• Behaviour– makeNoise()– eat()– sleep()– roam()

Page 4: Abstract & Interface GOF Design Pattern

2. Buat classSUPERCLAS

S

SUBCLASS

Do all animals eat the same

way?

Page 5: Abstract & Interface GOF Design Pattern

3. Subclass memiliki behaviour yang lebih spesifik.

Jadi,Kedua method ini akan dioverride, sementara dua method yang lain akan tetap generic..

Page 6: Abstract & Interface GOF Design Pattern

4. Lihat kesamaan behaviour yang lain..

Page 7: Abstract & Interface GOF Design Pattern

Class Hierarchy

Page 8: Abstract & Interface GOF Design Pattern

???

?

?

?

Page 9: Abstract & Interface GOF Design Pattern

.. Some classes just should not be instantiated!

Page 10: Abstract & Interface GOF Design Pattern

Abstract Class

• Tidak dapat diinstantiasi -> superclass• Class yang berisi satu atau lebih abstract

method– Jika suatu kelas memiliki abstract method,

maka kelas tersebut harus didefinisikan sebagai abstract class

• Subclass harus mengimplementasikan abstract method superclassnya (abstract class)

Page 11: Abstract & Interface GOF Design Pattern

Abstract Method

• Method yang tidak memiliki body– Harus di override oleh subclassnya

• Constructor dan static method tidak boleh abstract

• Harus diimplementasikan oleh method dari subclass

Page 12: Abstract & Interface GOF Design Pattern

Sooo.. Abstract..

Shape

draw{abstract}() : void

Segitiga

draw() : void

SegiEmpat

draw() : void

SegiLima

draw() : void

Page 13: Abstract & Interface GOF Design Pattern

Sintaks

• Abstract Class– [ClassModifier] abstract class [ClassName]– contoh :public abstract class Shape{}

• Abstract Method– [Modifier] abstract [ReturnType][MethodName]

([parameter])– contoh :public abstract void draw();

Page 14: Abstract & Interface GOF Design Pattern

Sintaks

• Subclass (pengguna abstract)– [ClassModifier] class [ClassName] extends

[AbstractClass]– contoh :public class Segitiga extends Shape{}

Page 15: Abstract & Interface GOF Design Pattern

Another case..

Page 16: Abstract & Interface GOF Design Pattern
Page 17: Abstract & Interface GOF Design Pattern

What if..

..semua anggota abstract class adalah abstract method?

Page 18: Abstract & Interface GOF Design Pattern

Interface

• Interface adalah abstract class yang seluruh methodnya adalah abstract method.

• Variabel dari interface selalu static dan final.• Bukan class, tapi prototype untuk class (yang

nanti akan mengimplementasikan)• Sebuah class dapat mengimplementasikan lebih

dari satu interface.

Page 19: Abstract & Interface GOF Design Pattern

Interface sebagai Tipe Data

• Dapat digunakan sebagai variabel sebuah class• Dapat digunakan sebagai parameter

Page 20: Abstract & Interface GOF Design Pattern

Sintaks

• Membuat interface :– interface [InterfaceName]– Contoh :

interface Animal

• Menggunakan interface :– [ClassModifier] class [ClassName] implements

[InterfaceName]– Contoh :

public class Cat implements Animal

Page 21: Abstract & Interface GOF Design Pattern

Pewarisan antar interface

• Interface dapat mewarisi interface lainnya• Contoh :

interface Animal{

/*some code*/ }

interface Mammal extends Animal {

/*some code*/ }

Page 22: Abstract & Interface GOF Design Pattern

Class Diagram

Page 23: Abstract & Interface GOF Design Pattern

Latihan

• Refer to labwork_05.pdf

Page 24: Abstract & Interface GOF Design Pattern

Rational Objectory

• Software Engineering Process• Its goal is to ensure :

– the production of high-quality software– meeting the needs of its end-users– within a predictable schedule and budget

Page 25: Abstract & Interface GOF Design Pattern

Objectory

• Objectory adalah suatu proses iterasi atau bisa juga diartikan sebagai suatu proses terkontrol

• Jadi objectory adalah proses iterasi terkontrol• Objectory focus pada arsitektur dari sistem• Aktifitas pengembangan objectory diarahkan

oleh use case, object oriented proses, penggunaan UML sebagai pemodelan dan bisa di konfigurasi untuk menentukan ruang lingkup suatu project

Page 26: Abstract & Interface GOF Design Pattern

Objectory (cont)

• Objectory proses dibagi menjadi 4 phase yang membentuk pola pengembangan cycle– Inception phase/ fase permulaan– Elaboration phase/ fase perluasan– Construction phase/ fase pembentukan– Transition phase/ fase transisi

Page 27: Abstract & Interface GOF Design Pattern

Objectory (cont)

Setiap fase di tutup oleh suatu milestone, yaitu suatu keadaan di mana beberapa keputusan critical harus dibentuk

Page 28: Abstract & Interface GOF Design Pattern

Once upon a time.. (AGAIN)

Sekarang....tolong bikinin

simulai bebek2an buat

anak kedua saya..

Boss besar

Bagus juga

desain Animalmu

!

Page 29: Abstract & Interface GOF Design Pattern
Page 30: Abstract & Interface GOF Design Pattern
Page 31: Abstract & Interface GOF Design Pattern
Page 32: Abstract & Interface GOF Design Pattern
Page 33: Abstract & Interface GOF Design Pattern

What do you think about this design?

Page 34: Abstract & Interface GOF Design Pattern

Design Pattern

• Muncul masalah ketika membuat program OOP :– Handle Object– Perubahan pada sistem

• Bagaimana biasanya programmer mengatasi masalah?– Some say, “Pengalaman! Semakin banyak pengalaman

seorang designer software, semakin elegant, simple dan flexible-lah code-nya. ”

• New problem : TIME

Page 35: Abstract & Interface GOF Design Pattern

Design Pattern

• Solusi yang sama untuk problem yang sama yang berulang-ulang

• Learning curve yang hanya bisa didapat dari pengalaman dapat di kurangi

Page 36: Abstract & Interface GOF Design Pattern

GoF Design Pattern

• Gank of Four (GoF) :Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides

• “Design Patterns: Elements of Reusable Object-Oriented Software”

Page 37: Abstract & Interface GOF Design Pattern

GoF Design Pattern

Creational (C) • Factory Method, Abstract Factory, Builder, Singleton,

PrototypeStructural (S) • Decorator, Composite, Proxy, Adapter, Bridge, Flyweight,

Façade Behavioral (B) • Strategy, Iterator, Template Method, Mediator, Observer,

Chain of Responsibility, Memento, Command, State, Visitor, Interpreter

Page 38: Abstract & Interface GOF Design Pattern

Strategy Pattern

Motivation• "Define a family of algorithms, encapsulate each one, and

make them interchangeable. Strategy lets the algorithm vary independently from the clients that use it." [Gamma, p315]

• Capture the abstraction in an interface, bury implementation details in derived classes

Page 39: Abstract & Interface GOF Design Pattern

Structure

Page 40: Abstract & Interface GOF Design Pattern

Contoh

Page 41: Abstract & Interface GOF Design Pattern
Page 42: Abstract & Interface GOF Design Pattern

GOF Design Pattern

..to be continue..