strategy-pattern

C++ Strategy Design Pattern, making an interface array

After having implemented the strategy pattern, I wanted to make an array of the interface-type, to which I can then add any concrete type. For those who don't know the strategy pattern: http://en.wikipedia.org/wiki/Strategy_pattern In this particular example I would want to make a StrategyInterface array, which I can then fill with con...

Where is the benefit in using the Strategy Pattern?

I've looked at this explanation on Wikipedia, specifically the C++ sample, and fail to recognize the difference between just defining 3 classes, creating instances and calling them, and that example. What I saw was just placing two other classes into the process and cannot see where there would be a benefit. Now I'm sure I'm missing some...

Real World Example of the Strategy Pattern

Hi All, I've been reading about the OCP principal and how to use the strategy pattern to accomplish this. I was going to try and explain this to a couple of people, but the only example I can think of is using different validation classes based on what status an "order" is. I've read a couple of articles online, but these don't usuall...

Can anyone explain how the Strategy Pattern relates to Inversion of Control?

Can anyone explain exactly how the Strategy Pattern relates to Inversion of Control? ...

Implementing a strategy for the constructor

What is the best way to implement a strategy for the constructor of a template/abstract class in C#? I have several classes which are all based on parsing a string inside the constructor. The parsing is done in a static method which creates list of key value pairs and is common for all classes, but some fields are also common for all cla...

Help with strategy pattern

I've been going through Head First Design Patterns (just came in recently) and I was reading about the strategy pattern, and it occurred to me that it might be a great way to implement a common way of calculating taxes etc. on all of the particular objects I use at work, but I had a question about it. Here's what I was thinking: public...

How to properly implement the Strategy pattern in a web MVC framework?

In my Django app, I have a model (lets call it Foo) with a field called "type". I'd like to use Foo.type to indicate what type the specific instance of Foo is (possible choices are "Number", "Date", "Single Line of Text", "Multiple Lines of Text", and a few others). There are two things I'd like the "type" field to end up affecting; the...

Implementing the Strategy Pattern

When implementing the Strategy Pattern, where does one put the code that determines which strategy to use? Some sample pseudo-code would help. ...

Emailer in Java using Strategy Pattern

UPDATED: Added one more question (Question #4). Hi all, I'm building myself a custom emailing utility. Now, to obey Single Responsibility Principle, I want to have the following classes: MailerSender, MailProvider and EmailObject. The MailSender is more of a delegate, check it out below: public class MailSender { private IMailPr...

Composite Strategy pattern - java - How bad is this code?

This question is kind of continuation to my earlier post: http://stackoverflow.com/questions/944824/visitor-pattern-implementation-in-java-how-does-this-look I got a bit confused while refactoring my code. I am trying to convert my visitor pattern (explained in the prior post) into a composite strategy pattern. I am trying to do somethi...

Design Patterns - Strategy Pattern

I am a beginner in Design Patterns. Suppose I am developing a C# application to track the development works performed by various members in development team (i.e. a Project Tracker). I am trying to be inspired by Strategy Pattern. So I am designing my classes and interfaces as follows: interface IEmployee { void Retires(); vo...

refactor help - strategy pattern

The object here is to update the UI. I normally do this on the client however this application uses the code behind. Anyways my question is I am trying to clean up these if else statements and I thought the strategy pattern may be appropriate. I don't need everything done for me but if you could give me a couple pointers to get going. Do...

Different algorithm for different inputs

In the application I am developing I am facing a situation; I want to know if there is a design pattern for this. It's as follows User is presented on a web interface with different algorithms for a process User selection is stored in the database. Now, the application should perform computations differently depending on the algorithm...

Is it possible to use a Strategy pattern for data structure with no common ancestor?

I have two data structure classes (this is a simplified version of my code) Animal: Has one property “int Age” Person: Has one property “DateTime Birthday” What I am trying to accomplish is to compile “Uploading” (persisting to database), which is common across all different data structure classes. So mainly my goal is to have a s...

String to Stategy in Strategy Pattern

I'm working in AS3, but I guess this could be a general question, so I'll frame it more vaguely... I'm using an XML file to define parameters for a particular class of object that implements the Strategy Pattern. There will be large variety of objects, and this works for us as a designer friendly solution to customizing these objects. A...

How to persist Strategy Pattern (behavoir) with LINQ 2 SQL?

I am designing an app that will be using LINQ2SQL to persist the data in a database. I often use the Strategy pattern. For instance, I may have a ClubMember object which can use different cost strategies like the following: class ClubMember { public String name { get; set; } public String email { get; set; } private IMembe...

C# Strategy pattern and database access

I am new to design patterns and now I want to implement the Strategy patern. Here's my code: namespace StrategyPattern { public interface ISendBehavior { void Send(); } public class SendAppointment : ISendBehavior { public void Send() { // send item } } public cla...

What is the difference between Strategy Design pattern and State Design pattern?

What is the difference between Strategy Design pattern and State Design pattern? I was going through quite a few articles on the web but could not make out the difference clearly. Can somebody please explain in layman's terms? ...

Strategy Pattern and Dependency Injection using Unity

I am finally getting my feet wet with Dependency Injection (long overdue); I got started playing with Unity and run into an issue with the strategy pattern. I can use the container to return to me specific implementations of a strategy based on a name, but what I don't see is how I am supposed to get the right strategy in the context. Le...

When and why should the Strategy Pattern be used?

When would the Strategy Pattern be used? I see client code snippets like this: class StrategyExample { public static void main(String[] args) { Context context; // Three contexts following different strategies context = new Context(new ConcreteStrategyAdd()); int resultA = context.executeStrateg...