Questions tagged [strategy-pattern]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
41 views

Combining Strategy and Decorator pattern (see GOF) to Spectrogram computation

I'm trying to design and develop a software (part of a bigger application) that should compute and render a spectrogram. The spectrogram can be rendered either from live microphone or a file (assuming ...
1 vote
0 answers
70 views

Is it bad practice to specialize template method to implement strategy pattern in C++?

I came across a class that implements a kind of "strategy pattern" with a concrete implementation defined inside the main class as a template method. #include <iostream> struct ObjA { ...
  • 357
1 vote
1 answer
83 views

Self-Selecting Variant of the Strategy Pattern?

I've found this pattern useful, and am trying to classify or name it. Basically, that: A task should be performed by different strategies, depending on the context. Each concrete strategy implements ...
  • 113
0 votes
2 answers
206 views

Coffee machine strategy pattern implementation

I came across an article about LSP https://stackify.com/solid-design-liskov-substitution-principle/ . It seems that a strategy pattern could be implemented here but I cannot see how to implement it. ...
  • 13
0 votes
3 answers
590 views

Is It Considered Good Practice to Use Dependency Injection with Strategies from a NuGet Package?

I am developing a NuGet package which contains shared code for various ASP.NET Core projects. I am planning to use the strategy pattern to solve the same problem in a few different ways. So there will ...
  • 151
2 votes
1 answer
133 views

The notion of configurable strategies

I'm designing an algorithm that matches entries based on some notion of "proximity" (for the sake of discussion, assume we're matching floats). Furthermore: The input is a scalar and a ...
  • 233
1 vote
2 answers
941 views

Difference between Strategy pattern and Repository pattern

I found the following definition of Repository Pattern: Repositories are classes or components that encapsulate the logic required to access data sources. They centralize common data access ...
  • 119
-1 votes
1 answer
102 views

How to get rid of multiple if statements in code flow related to different modes/datasets - Python? [closed]

My Python project comprises data handlers, models and can be run with different modes. Throughout my code I use statements like if mode=='mode1': # or if isinstance(model, Model1): To adapt the flow ...
0 votes
1 answer
114 views

Strategy pattern with implemented public method

New to design patterns so my question maybe silly. I want to use strategy pattern for returning data from a databases in the same format. Nevertheless it varies the query on the underlying database ...
3 votes
4 answers
357 views

Is the strategy pattern for 3 variants overuse?

I am curious about it because I talked with a friend about the strategy pattern, and we diverge about when we have to use it. Our scenario is that I have to build a view component with 3 variants. All ...
  • 139
-2 votes
1 answer
109 views

Modify method behaviour at runtime

I have a scenario where user has multiple filters in a web application and a displayed list of items. In the gui it has multiple FilterGUI that he/she can tune interacting in the browser (these are ...
  • 9
1 vote
3 answers
3k views

Advantages of strategy design pattern versus simple if-else

I am not clear on what advantage does strategy pattern offers over simple if-else. Example of poor code //poor code that we all can agree is not the way to go ----- main class ----- String ...
1 vote
1 answer
333 views

Strategy Design Pattern vs Inheritance

I have to write a code where i have send some data (call it List of cases) using one of two integration tools (Jitterbit, Mulesoft), with possibility of adding more tools in future. Integration tool ...
2 votes
1 answer
148 views

Is it allowed to include the composition in the compositor in the Strategy Pattern

I have a range of different animals in my zoo such as turtles, birds etc. As they all share a common trait such as either swimming, flying etc., I thought a strategy pattern would be appropriate to ...
  • 129
19 votes
6 answers
10k views

Strategy vs Factory design pattern

I am new to design patterns and working my way through the Factory Method and Strategy patterns. I understand that Factory is a creational pattern and Strategy is behavioral but I struggle to ...
3 votes
3 answers
285 views

How to use strategy pattern more effectively?

The problem is the following: I have to download a set of JSON files and convert them to a certain format. There are 5 output formats (Let's call them A, B, C, D, E) and all of the downloaded json ...
1 vote
1 answer
353 views

What's the difference between Strategy Pattern and IoC

In both the Strategy Pattern and in Inversion of Control you can exchange parts of an object that allows scalability and easy-to-exchange parts. I am referring to this and this Both use an interface ...
user avatar
10 votes
5 answers
4k views

Can we completely replace inheritance using strategy pattern and dependency injection?

For example: var duckBehaviors = new Duckbehavior(); duckBehaviors.quackBehavior = new Quack(); duckBehaviors.flyBehavior = new FlyWithWings(); Duck mallardDuck = new Duck(DuckTypes.MallardDuck, ...
2 votes
2 answers
492 views

Strategy pattern and different implementation

I am still learning Design Patterns and I have a situation in my hand. I am developing a simple employee management Python program. An employee can be a Developer, Senior Developer, Lead Developer, ...
  • 129
2 votes
2 answers
594 views

Strategy/domain object responsibilities

Assume we are in the world of car rental application :) Let's say that I have 3 types of cars with 2 categories of price: Car type Price category ------------------------------ Sport ...
3 votes
2 answers
2k views

DDD - delegate business rule of domain object to external service

Situation: I am implementing DDD in my first project and I would like to clarify how to correctly implement strategy pattern (in my case check if API token is active). This is a business rule of ...
  • 289
2 votes
2 answers
892 views

How to implement Strategy pattern for combined behaviours

Strategy pattern solves the necessity of applying a certain algorithm/behaviour depending on the object's type itself. So you can iterate over a bunch of similar objects and call the same function ...
1 vote
3 answers
337 views

Strategy Pattern and inheriting boilerplate functionality

I've read that when using the Strategy Pattern, you should stick to composition rather than inheritance. But does this mean that any inheritance at all is bad practice? If there is functionality to be ...
1 vote
2 answers
2k views

Implementing strategy pattern via configuration

In my current problem domain, a number of problems seem to lend themselves quite well to the strategy pattern. I have a common, high-level process - let's say it's a sales process - and regardless of ...
  • 362
2 votes
1 answer
1k views

Does my use of the strategy pattern violate the fundamental MVC pattern in iOS?

I'm about to use the 'strategy' pattern in my iOS app, but feel like my approach violates the somehow fundamental MVC pattern. My app is displaying visual "stories", and a Story consists (i.e. has @...