html5-img
1 / 14

Decorator Pattern

Decorator Pattern. Tujuan Pembelajaran. Mengetahui model persoalan yang menggunakan Decorator pattern Mengetahui bagaimana menerapkan Decorator pattern pada program Mampu menerapkan Decorator pattern untuk meningkatkan fleksibilitas kode. Koleksi Desain Pattern.

idana
Download Presentation

Decorator Pattern

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Decorator Pattern

  2. TujuanPembelajaran Mengetahui model persoalan yang menggunakan Decorator pattern Mengetahuibagaimanamenerapkan Decorator pattern pada program Mampumenerapkan Decorator pattern untukmeningkatkanfleksibilitaskode

  3. KoleksiDesain Pattern • Creational Patterns : • Singleton • Factory • Behavioural Patterns : • Strategy • Decorator

  4. Problem

  5. Example : Starbuzz Coffee Bgmjikakitainginmenambahkanpelengkap pd kopi, misalnya steamed milk, soya, mocha, dll ? Decaf DarkRoast HouseBlend Espresso cost() cost() cost() cost() Beverage description getDescription() cost() //other methods

  6. AlternatifPertama DecafWith Mocha HouseBlendWithSoya DecafWithSteamedMilk EspressoWithSoya HouseBlendWithMocha DecafWithSoya HouseBlendWithSteamedMilk cost() cost() cost() cost() cost() cost() cost() Beverage description getDescription() cost() //other methods

  7. AlternatifKedua Bgmjikaterjadiperubahanhargadaritiappelengkap, penambahanjenispelengkap, bgmjikapelangganingin double whip? Decaf DarkRoast HouseBlend Espresso cost() cost() cost() cost() Beverage description milk soya milk whip getDescription() cost() hasMilk() setMilk() hasSoya() setSoya() hasWhip() setWhip() hasMocha() setMocha() //other methods

  8. PrinsipPerancangan Identify the aspects of your application that vary and separate them from what stays the same Program to an interface not and implementation Favor composition over inheritance Strive for loosely coupled designs between object that interact. Classes should open for extension, but closed for modification

  9. Decorator Pattern

  10. Menerapkan Decorator Misalnya, pelangganinginsecangkirDark RoastditambahWhipdanMocha. cost = … mocha.cost() mocha calls whip.cost() whip calls darkRoast.cost() darkRoast returns $darkRoast whip returns ($darkRoast+$whip) mocha returns ($darkRoast+$whip+ $mocha)

  11. Properti Decorator Pattern

  12. Class Diagram Decorator Pattern

  13. Latihan Terdapatduatipe Mobil yaituXenosA (155 jt) danXenosB (141 jt). Penggunamobildapatmemilihvariasiuntukdipasangpadatiaptipemobil. Variasi yang tersedia console box (175 rb), spoiler (500 rb), dan grill (280 rb). Buatlah program yang dapatmenambahkanvariasisecaradinamisketiaptipemobilsekaligusmenghitung total harganya. Gunakan Decorator Pattern untukmenyelesaikanpersoalandiatas.

More Related