La quinta fuerza del universo

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…


独家优惠奖金 100% 高达 1 BTC + 180 免费旋转

Strategy Design Pattern

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.

Strategy Pattern


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:

Add a comment

Related posts:

Last Words

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 Only Thing I Can Do

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…

Celebrity recognition using VGGFace and Annoy

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…