Strategy Design Pattern
Why Stack Overflow recommends it
Stack Overflow users link it when someone needs a quick, readable introduction to the strategy pattern for changing behavior at runtime.
Recommended by 1 people across 1 different months, 2013 to 2018.
What it is
A short tutorial by Derek Banas on the Strategy design pattern, which lets an object swap the algorithm it uses at run time. He walks through code (in Java) and shows how the pattern removes duplicated behavior from superclasses and subclasses.
What people said
Recommends vsoftco · 2014-07 · Stack Overflow · on “Creating Objects of same Class with different Functions at Compiletime”
There is a famous software design pattern called the "strategy pattern", which is probably what you want: changing behaviour at runtime. A nice tutorial (although for java, but immediately translatable to C++ ) is here [this video]
Cites Gordon · 2013-07 · Stack Overflow · on “Advantages of using strategy pattern in php”
The intent of the Strategy pattern is to: Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it. [GoF:349] To understand what this means, you have to (emphasis mine) Consider what should be variable in your design. This approach is the opposite of focusing on the cause of redesign. Instead of considering what might force a change to a design, consider what you want to be able to change without redesign . The focus here is on encapsulating the concept that varies, a theme of many design patterns. [GoF:29] In other words, strategies are related pieces of code you can plug into a client (anothe
Cites Daniel · 2018-05 · Stack Overflow · on “What is the difference between the bridge pattern and the strategy pattern?”
Design pattern types Behavioural: patterns characterise the ways in which classes or objects interact and distribute responsibility Structural: patterns deal with the composition of classes or objects. Creational : patterns are concerned about the process of object creation. Bridge [LINK] (Structural) Decouple an abstraction from its implementation so that each may vary. independently. [LINK] Take a remote. The remote has buttons 1-6. This is the concrete class in the diagram above. Each button will work different depending on if the remote is used for a TV or DVD. The functionality for each button is abstracted from the implementation by the implementer interface. This allows us to change h