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
0
votes
2 answers

mysql database monitoring strategy in production

I m using MySQL as database for my project and in coming few weeks, we are migrating from dev to prod environment, so whats would be the plans to monitor the status of database in production environment?
Ashok Gupta
  • 2,247
  • 5
  • 28
  • 34
0
votes
1 answer

Pattern to Add Behaviour using New Methods at Runtime

I would like to be able to use a pattern to add behaviour (by virtue of additional methods/properties) to an existing class at runtime. This seems very similar to the well-known decorator pattern, however, the examples that I have been able to find…
Jinxed NZ
  • 35
  • 6
0
votes
1 answer

Refactor a code of selection a validator

I have a datatable and have to validate every field in it. I have refactor this code to this below, but a complexity is 15(!!) Should I make something like dictionary with type as Key and Func as Value? I'd be very grateful for some ideas private…
0
votes
0 answers

Multiple Buttons, 1 ClickListener using generics, Strategy Pattern - All buttons only do the same operation

I have been looking at different ways of making Listeners in Android. I encapsulated the listener in a separate class called Click. I have also used the strategy pattern to encapsulate logic and that is interfaced with the enum type BinaryOperator.…
Christopher Rucinski
  • 4,737
  • 2
  • 27
  • 58
0
votes
2 answers

Refactoring a method for specific clients

Methods specific for customers: I try to refactore a code, where are a lot of logic for specifi customer: public void SendDocumentsToCustomer(List cases) { foreach(var case in cases) { if(case.CustomerId==123) { …
0
votes
2 answers

Do I understand this Strategy Pattern correctly?

In my previous question, I've been taught that the below code is an example of the Strategy Pattern. The line _player.Draw(spriteBatch, _context); in particular. I don't see the difference between that line and the one below it, aside from the…
Taelia
  • 591
  • 3
  • 20
0
votes
1 answer

Appropriate Application of Strategy Pattern

I'm writing a provisioning application that gets user add or remove requests, then based on the specified role of the user, goes and applies specified attributes and creates them in the system or goes and removes the user from specified roles in the…
michael_clarke
  • 171
  • 1
  • 2
  • 11
0
votes
1 answer

How to make different interface for each strategy?

I have following situation. I make ad rotation and I want to have a few strategies. But how to do it, when different strategies needs different params? e.g.: LeastShowedStrategy needs only collection of ads but UserRelevantStrategy needs both…
DonPaulie
  • 2,004
  • 17
  • 26
0
votes
2 answers

Generics and concrete implementations of strategy components

I ran into a little snag with the concrete implementation of strategy components using generic types. Wondering if anyone can point me in the right direction with an example? Here is what I am working towards, but I get caught up when I declare the…
nckbrz
  • 688
  • 1
  • 6
  • 20
0
votes
2 answers

Android - Do creating many small short lived objects affect performance?

I am creating a 2D game in Android. I am confused on how to efficiently write my code or it would pose performance issues in the long run. Currently I am using strategy pattern. This is my code. public void setCharAnimDirection( …
steven0529
  • 1,513
  • 1
  • 18
  • 28
0
votes
1 answer

C++ pattern strategy initialization

I'm developing a class has decided to split it into independent strategies. Something like this: template class SomeClass : public ... { public: SomeClass() { obj1 = new Strategy1 //…
Dima00782
  • 171
  • 1
  • 3
  • 13
0
votes
1 answer

How to autoincrement non-primary key column in hibernate?

In Hibernate how do I set a non primary key column to start at a default value of 10000 and then increment it with insertion of each record? For example first entry should be 10000 then 10001,10002 so on. Note: This is not a primary key, so I am not…
Ace
  • 1,501
  • 4
  • 30
  • 49
0
votes
2 answers

What is the advantage of Strategy Pattern over explicit named methods?

What is the advantage of passing in a strategy to execute as a method argument as opposed to having the implementation in an explicit method? For example, consider this calculator class: Edited to include IOperation interface public class…
jmrah
  • 5,715
  • 3
  • 30
  • 37
0
votes
2 answers

What are the best strategies/practices for Rails upgradation from 2.3.11 to 4.0.0?

I would like to upgrade one of my application from rails -2.3.11 to 4.0.0. Before going to do anything, I just need plan for it and my application not that much of big size but got some 6/7 plugins and 5/6 gems. Existed : Ruby…
0
votes
3 answers

Strategy design pattern - populating a c++ class with an object

I'm trying to implement a Strategy design pattern in C++. I have an abstract class with no non-abstract method called ICookingStrategy: class ICookingStrategy { public: virtual int cook() = 0; }; From this abstract class inherit two…
Jivan
  • 21,522
  • 15
  • 80
  • 131