尤川豪   ·  4年前
445 貼文  ·  275 留言

Composition over Inheritance

https://medium.com/humans-create-software/composition-over-inheritance-cb6f88070205

  • Gorilla/Banana problem — you request a banana, but you end up with a gorilla holding the banana and the entire jungle with it.
  • inheritance is when you design your types around what they are, and composition is when you design types around what they do.
  • the really big problem with inheritance is that you’re encouraged to predict the future.

對了,以 php 來說,透過 constructor 進行 DI 注入多個類別比較好?

還是直接用 trait 輕鬆尻一尻比較好?

  分享   共 958 次點閱
按了喜歡:
共有 0 則留言
還沒有人留言。歡迎分享您的觀點、或是疑問。
您的留言
尤川豪
445 貼文  ·  275 留言

Devs.tw 是讓工程師寫筆記、網誌的平台。隨手紀錄、寫作,方便日後搜尋!

歡迎您一起加入寫作與分享的行列!

查看所有文章