Put down my questions and researches on design pattern here
State pattern vs Strategy pattern
- State pattern deals with what state / type an object is/in
- Encapsulate state dependent behaviour
- It create and hold the state object
- Strategy pattern deals with how an object performs a certain
- Encapsulates an algorithm
- Strategy object passed from outside
Facade vs Proxy vs Decorator
- Facade is a simple gateway to a compicated set of functionality
- Proxy provide the same interface as the proxied-for class
- Typically does some housekeeping stuff on its own
- Hide some internal task which does not need/want to expose to user
- Typically does some housekeeping stuff on its own
- Decorator add extra ability to your object
- Added feature is expose to user
Chain of responsibility & Express.js middleware
Express.js middleware is a chain of responsibility pattern, but from time to time, I feel it is quite difficult to maintain.
In Java, we cannot add a field dynamically to an object. In Javascript, we can add or delete any field of the object. The object passing in CoR pattern can have structure changes, which introduce implicit coupling between middlewares.
Express.js middleware can be unmaintainable if we changing objects being chained in an implicit way.