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
-1
votes
1 answer

When to use generic instances instead of just using "new" keyword

I've been thinking about having multiple page elements and making tabbing with a PageFactory. Then I realized it would be better to not to type all the types that I want, since I just wanna get the instance. Then I created something as follows: …
Mert
  • 113
  • 1
  • 5
-1
votes
4 answers

Strategy Pattern : strategy with the caller as attribute?

I use a Strategy pattern, so I have my Strategy abstract class, my ConcreteStrategy class and my Player class. In my ConcreteStrategy I must access my Player object. Knowing that Player has a Strategy and that, as my teacher told me, I must not…
clst
  • 111
  • 1
  • 11
-1
votes
1 answer

Switch between the tables and save data by considering a Specific field using strategy pattern

There are three Tables named as car_details, bike_details, truck_details the fields are same for all the three tables (RegistrationNo, No.ofYearsOld, OwnerName, ContactNo, VehicleType) the field VehicleType should specify type of the vehicle(car or…
-1
votes
1 answer

Ignore if-else ladder and implements strategic design pattern

I am trying to implement strategic design pattern . I have simple if-else ladder as below: if(dataKeyinresponse === 'year') { bsd = new Date(moment(new Date(item['key'])).startOf('year').format('YYYY-MM-DD')) nestedbed =…
-1
votes
3 answers

Get rid of if statements to improve code design

How can I improve the design of the code below: class Foo { public Configuration configure() { return new Configuration().withPropertyA().withPropertyB(); } } class Configuration{ private boolean propertyA = false; private…
Moonlit
  • 5,171
  • 14
  • 57
  • 95
-1
votes
1 answer

Cant figure out whats wrong with my strategy design pattern

I am using a strategy design pattern for my software engineering course but I am unsure what is wrong with it. The syntax errors I am getting saying 'Duplicate method getPath() in Route' and 'Syntax error on token public, class expected after' and…
TylerC
  • 19
  • 4
-1
votes
1 answer

Runnables Instantiation Java

I am trying to write an ExecutorService as in Executors.newFixedThreadPool with a runnable given as a parameter to method filling the ThreadPool. this is not about instantiating a inner class like proposed here How to instantiate inner class with…
Datenverlust
  • 147
  • 1
  • 8
-1
votes
1 answer

How do I implement this solution (strategy design pattern) in python? I have some rough code here

I am trying to implement this solution in python using the strategy design pattern. I am totally new to OOP, currently working with my professor on this problem. Basically the question is to have an abstract class( or rather an interface), and 2…
Huang Kai
  • 31
  • 1
  • 3
-1
votes
2 answers

Asp.Net MVC and Strategy pattern

I have an MVC application that uses Entity Framework. I am using a repository, unit of work and unity as dependency injection. The problem I have is that I have different authentication types, and each type I want a different class, so I decided…
-1
votes
1 answer

Implementing Input Class using Strategy Design Pattern

I'm quite a bit new to Object Oriented Programming. I have to implement an interface that should account for the different input types, ie. Joystick, mouse, xbox, etc. A movement controller class will use the interface, and a player class will…
GelatinFox
  • 353
  • 3
  • 6
  • 10
-1
votes
1 answer

Python Strategy Pattern: using class wrapper not function + simple_vs_easy_logic

I am trying to build a Strategy Pattern using S.Lott's response. Problem is function returns None. Am using Hickey's Simple vs Easy {what, how, who}-logic. -[WHAT] I/O class base_fnc(object): def fncExc(self,data1,data2): return -[HOW]…
syntax
  • 585
  • 1
  • 6
  • 17
-1
votes
1 answer

Differences between MVC pattern and other 2 patterns

Can you tell me if it is Factory, Strategy or MVC design pattern? public interface MainObject { void add(); T get(); } class Person1 : MainObject { public Person1(int id, string name) { // define } …
-2
votes
0 answers

pinescript V5 - error condition in strategy TradingView

I have an error message at the LongCondition statement but cannot understand why. Can you help me find proper code ? I have tried this for the LongBuy condition but returns an error message // Script inputs string GROUP_DLB = 'Config » Dynamic Level…
Dan64
  • 1
-2
votes
1 answer

How to convert pine script to strategy & generate alerts

The below script is working fine and is generating signals, but not able to convert this into strategy and generate signals study("Trend Magic", shorttitle="TM", overlay=true) CCI = 20 ATR = 5 Multiplier=1 original=true upSign = '↑' //…
pavs
  • 1
-2
votes
1 answer

What is a possible approach to write strategy pattern in a functional style in C#?

There are several approaches in another languages like What is the functional analogue of a Strategy pattern? Strategy pattern in F# But what about implementation in c#? Any ideas?
1 2 3
48
49