For example, suppose I have a Product class that I can add to a shopping cart. I may want to be able to package it together with another item when it is also in the cart and add a 15% discount.
Should the product class be decorated with a new subclass allowing deals, or should product class be redesigned to allow the cart attach a price...
I am basically trying to implement a Strategy pattern, but I want to pass different parameters to the "interfaces" implementation (that inherit from the same object) and don't know if this is possible. Maybe I'm choosing the wrong pattern, I get an error similar to
'StrategyA' does not implement inherited abstract member 'void DoSomet...
I have a MessageProcessor class which processes xml messages of different types. A switch statement (C#) based on the message type calls the appropriate method to parse the xml and extract the data required for the type of message.
I would rather have a number of parser classes, one of which will be injected into the MessageProcessor w...
I am trying to create a web-based tool for my company that, in essence, uses geographic input to produce tabular results. Currently, three different business areas use my tool and receive three different kinds of output. Luckily, all of the outputs are based on the same idea of Master Table - Child Table, and they even share a common Mas...
The following code sample is an implementation of the Strategy pattern copied from Wikipedia. My full question follows it...
The Wiki's main method:
//StrategyExample test application
class StrategyExample {
public static void main(String[] args) {
Context context;
// Three contexts following different strategie...
Feedback summary
I will now close this thead (I think there will be no more feedback) and try to summarize what I understood
using the "Context" as a parameter for my strategy introduces a tight coupling that should be avoided and also could force me to expose properties that should perhaps remain hidden in the class.
To minimize co...
I was looking at this, http://en.wikipedia.org/wiki/Strategy_pattern and I understand the concept of the strategy pattern, but could someone explain the C# example a bit.
I dont really get the how and why of the definition of 'Strategy' in the Context class, why is it Func<T, T, T> but then just two params are passed in eg 8,9 ?
static...
Hi,
I need to develop a strategy pattern where i have a main class with other three classes where i need to refer to the objects of the other three classes using the main class object.To solve this is the strategy pattern will help me? If so please do give me the syntax in Objective-C?
...
I have a class which is going to need to use the strategy design pattern. At run time I am required to switch different algorithms in and out to see the effects on the performance of the application.
The class in question currently takes four parameters in the constructor, each representing an algorithm.
How using Ninject (or a general...
I have several Java classes which implement the strategy pattern. Each class has variable number parameters of different types:
interface Strategy {
public data execute(data);
}
class StrategyA implements Strategy {
public data execute(data);
}
class StrategyB implements Strategy {
public StrategyB(int paramA, int par...
Hi,
I have a problem that I’ve tried to get help for before, but I wasn’t able to solve it then, so I’m trying to simplify the problem now to see if I can get some more concrete help with this because it is driving me crazy…
Basically, I have a working (more complex) version of this application, which is a project cost calculator. But ...
This is a design question better explained with a Stack Overflow analogy:
Users can earn Badges. Users, Badges and Earned Badges are stored in the database. A Badge’s logic is run by a Badge Condition Strategy. I would prefer not to have to store Badge Condition Strategies in the database, because they are complex tree structure objects...
Hello,
I want to create a class that can use one of four algorithms (and the algorithm to use is only known at run-time). I was thinking that the Strategy design pattern sounds appropriate, but my problem is that each algorithm requires slightly different parameters. Would it be a bad design to use strategy, but pass in the relevant par...
Hi all,
Just as there is a naming convention for the Observer pattern (or rather, a naming convention for events in languages such as C#) using Event/Handler passing EventArgs and such, are there naming conventions that you use to easily highlight other patterns in your code?
edit: I originally wanted to ask about the Strategy pattern,...
I have the following scenario where I have different kinds of sales algorithms to calculate the sales price. FixedSaleStrategy does not need basePrice parameter while all the other strategy implementations need it. Is there a good way to avoid this redundant parameter?
public abstract class SalesStrategy
{
public abstract double Get...
I'm trying to implement the Strategy pattern using Core Data and Objective C.
To simplify, I have, say, a multilingual Text entity, which has several attributes, such as a Date for last saved, and a NSSString for author etc etc. I want to add a reference to a Language entity, which could be one of several subclasses, such as French, Ita...
Here's what I have so far:
namespace Strategy
{
interface IWeaponBehavior
{
void UseWeapon();
}
}
namespace Strategy
{
class Knife : IWeaponBehavior
{
public void UseWeapon()
{
Console.WriteLine("You used the knife to slash the enemy! SLASH SLASH!");
}
}
}
namespace S...
Hi all,
Considering a hypothetical situation where an old, legacy presentation library has been maintained over the years, and has gradually had more and more business logic coded into it through a process of hasty corrections and lack of proper architectural oversight. Alternatively, consider a business class or namespace that is not s...
Hi,
I have a base class:
class Message
And two deriving classes:
class SimpleMessage : Message
class ComplexMesssage : Message
These types are used in another part of the code as such:
void ProcessSimpleMessage(SimpleMessage m)
void ProcessComplexMessage(ComplexMessage m)
These methods are not inside the class Message, as the p...
I'm adapting Image Downloader from Google Android blog. I want ImageDownloader to be singleton since I'll be using it in multiple places in my application. I want also to be able to manipulate Bitmaps using different Strategies (eg. produce transparent bitmaps).
Context:
I want to be able to use ImageDownloader in one activity and set ...