Questions tagged [strategy-pattern]

The Strategy pattern (also known as the policy pattern) is a design pattern whereby an algorithm's behavior can be selected at runtime. It is one of the Gang of Four's behavioral design patterns. When using this tag on implementation heavy questions - tag the code language the implementation is written in.

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 the clients that use it."

The pattern relies heavily on composition. An important advantage of this approach over inheritance and simple method overrides is that the behavior can be freely changed at run-time by changing the object implementing it.

This pattern is one of the original described in "Design Patterns" by Gamma, Helm, Johnson and Vlissides.

728 questions
-2
votes
1 answer

Instantiate proper strategy with Java and Spring Boot

I have the following situation: I have to validate a Token using (for now) 2 different strategies, they both do the same thing (check if the token is valid) but in different ways. My current way of dealing with the strategy instantiation looks like…
-2
votes
3 answers

java. Strategy design pattern with general return type

I want to make a strategy design pattern exemple in order to use it in my java application. So i have one function with tow possible value return types: int[][] getMatrix(); double[][] getMatrix(); I tried this: //the strategy interface public…
-2
votes
1 answer

C++: How to create array of interfaces inside constructor

Arduino project. Using C++ 11 compiler. I have created an "interface" class, and several implementation classes. I want to implement stategy pattern. In my strategy manager class, I want to create an array of fixed length and initialize it in the…
Mister Smith
  • 27,417
  • 21
  • 110
  • 193
-2
votes
1 answer

How to call different derived classes in constructors of classes derived from a different base class

In C++, I have two separate base classes, each of whose derived classes are somewhat coupled. Here's an example for the kind of thing I'd like to do: First define a set of classes, e.g.,: class Shape { public: double area; …
user1790399
  • 220
  • 2
  • 11
-3
votes
1 answer

Stopped - Too many triggering error Tradingview . Why is this happening?

In the strategy I created; This is how the Strategy Login and Exit alarms fail. How can I solve this problem? The strategy uses pyramiding. enter image description here enter image description here enter image description here
-3
votes
2 answers

Passing Derived Objects as Argument

I have a Constructor for a class Student like this: Student(ISubject subject, IStudy study); With ISubject and IStudy being abstract classes. I then created classes that inherited from the abstract class. (E.g Maths : ISubject and Calculus :…
Okami1301
  • 9
  • 2
-3
votes
2 answers

Confusion when using the strategy method

I am trying to implement the strategy pattern to find the middle point of arraylists that hold different types of numerical data including paired numerical data(coordinates). I am having some difficulty with the pairs and my strategy method…
lenti
  • 1
  • 1
-4
votes
1 answer

Solution(strategy) for n size Tic-Tac-Toe map

As I know TicTacToe is a solved game. I want to create a strategy for computer player on which basis he will decide where(on which) put cross. In my game the game board is: Field[][] fields; //which has size n x n, definition on fields is at the…
Yoda
  • 17,363
  • 67
  • 204
  • 344
1 2 3
48
49