Skip to content

8loser/DP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Design Pattern

策略模式 (Strategy Pattern)

code: Duck

觀察者模式 (Observer Pattern)

code: Weather

  • subject, observer 都是 interface
  • observer 透過 subject interface 執行註冊, subject 透過 observer interface 觸發更新

裝飾者模式 (Decorator Pattern)

code: Weather

  • 使用繼承使型態相符
  • java.io 屬於裝飾者模式
  • 缺點: 會有大量的類別(裝飾者)

工廠模式 (Factory Pattern)

code: Pizza

Note

  • @override 可寫可不寫, JVM 會自動判斷, 有寫的話 IDE 會協助驗證
  • abstract/interface
    • abstract 可以有建構式, interface 沒有
    • is a: 用 abstract
    • has a/like a: 用 interface

About

design pattern

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages