Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Strategy pattern
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== UML class and sequence diagram === [[File:w3sDesign Strategy Design Pattern UML.jpg|frame|none|A sample UML class and sequence diagram for the Strategy design pattern.<ref>{{cite web|title=The Strategy design pattern - Structure and Collaboration|url=http://w3sdesign.com/?gr=b09&ugr=struct|website=w3sDesign.com|access-date=2017-08-12}}</ref>]] In the above [[Unified Modeling Language|UML]] [[class diagram]], the <code>Context</code> class does not implement an algorithm directly. Instead, <code>Context</code> refers to the <code>Strategy</code> interface for performing an algorithm (<code>strategy.algorithm()</code>), which makes <code>Context</code> independent of how an algorithm is implemented. The <code>Strategy1</code> and <code>Strategy2</code> classes implement the <code>Strategy</code> interface, that is, implement (encapsulate) an algorithm. <br> The [[Unified Modeling Language|UML]] [[sequence diagram]] shows the runtime interactions: The <code>Context</code> object delegates an algorithm to different <code>Strategy</code> objects. First, <code>Context</code> calls <code>algorithm()</code> on a <code>Strategy1</code> object, which performs the algorithm and returns the result to <code>Context</code>. Thereafter, <code>Context</code> changes its strategy and calls <code>algorithm()</code> on a <code>Strategy2</code> object, which performs the algorithm and returns the result to <code>Context</code>.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)