Desde hace unas semanas me cacho pensando en la ropa que hubiera usado para ir a verte bailar algo cursi en la celebración del día de las madres de tu escuelita. Lo tengo clarísimo: me habría puesto…
What does Strategy mean?
“a plan of action designed to achieve a long-term or overall aim.”
Lets think in terms of Software design !!
Questions to consider before thinking about this pattern
If the answer is yes for any of the above questions, Strategy Pattern might be a good option for you.
Definition: The strategy pattern is a behavioral pattern that enables selecting an algorithm at runtime. Instead of implementing a single algorithm directly, we can pass the algorithm at runtime from a family of algorithms.
For Instance, an application that uses REST to call APIs might need to choose from different REST Templates(Ex: Proxy Enabled, SSL Configured) based on the build env( dev, test, prod). This might not be known until runtime.
Strategy design pattern lets you choose the correct Rest Template based on the env during run time without any changes in the code. Another classic example is when you have set of validation algorithms that need to be selected based on inputs.
The strategy uses Composition instead of Inheritance.It is also compatible with OCP, which states that class should be open for extension but closed for modification.
Steps
2. Implement different strategies
3. Create a class which composes the Strategy Interface
4. Use the above class and pass the correct algorithm at runtime
Code Example:
In the middle of the night I often wake up thinking of “last words” as the stuff of fiction and fate. Death is always a thigh-slapper, even at two in the morning. I am thinking about being at sea…
The rise of your mouth mischievous, delicious smile. Your eyes know how to talk, soul searching for delight, always ready to laugh. Hands soft, strong, knowing… Your playful touch pulls shivers to…
2. The cropped faces are sent to a model called VGGFace. This model provides encoding for the faces in the form of an array of size 2048. 3. The encoding are stored and indexed using a library called…