[推薦] 少用繼承,多用 composition

Source

https://www.youtube.com/watch?v=hxGOiiR9ZKg 10:00

Summary

Inheritance’s cost is expensive when changing requirement, and will need to write methods which your subclass doesn’t needs. Use composition to write more usable code.

re-use abstraction
inheritance extending parent class
composition using interface

Unlike extending parent class, interfaces defines only the critical part of the contract, it’s coupling the codes and is adaptable with new requirements.

cmd + /