GoF Behavioral - Strategy Pattern
To define a family of functionality, encapsulate each one, and make them interchangeable. The Strategy pattern lets the functionality vary independently from the client that use it.
- It provieds a substitute to subclassing.
- It defines each behavior within its own class, eliminating the need for conditional statements.
- It makes it easier to extend and incorporate behavior without changing the application.
- Multiple classes differ only in their behaviors. The servlet API is a classic example of this.
- Need different variations of an algorithm.
- Algorithm uses data that is unknown to the client.
[caption id="attachment_275" align="alignnone" width="539" caption="Strategy Pattern"]
[/caption]
沒有留言:
張貼留言