[Head First Design Patterns] Adapter And Facade Pattern
22 Apr 2022Adapter Pattern
-
class adapter (in language which allow to have multi-inheritance, Adapter inherite both Adaptee and Target)
-
object adapter (compose
Adaptee
object inAdapter
to implementTarget interface
)
Implementation
(github)
Facade Pattern
- to simplify interface (ie. the bundle of actions in smarthome when somebody back to home)
Design principles
Principle of least knowledge
- talk only to your immediate friends: to prevent the design have a large number of class decouple together (which create a fragtile system) -> we should only invoke methods which belong to:- the object itself
- objects passed in method as parameters
- any object the method creates or instantiated
- any component of the object
Implementation
(github)