strategy-pattern

Strategy Pattern replacing if/else or case statments

Why does it seem to me that using Strategy is just putting off the if/else to the Factory? Using Strategy, doesn't a Factory need to figure out which concrete class to instantiate, and doesn't it do so by if/else? Is another option to use a Map/List somehow, and have the keys be a name of the class to instantiate, and maybe have the cla...

Strategy Pattern with no 'switch' statements?

I've been doing some reading on the Strategy Pattern, and have a question. I have implemented a very basic Console Application below to explain what I'm asking. I have read that having 'switch' statements is a red flag when implementing the strategy pattern. However, I can't seem to get away from having a switch statement in this exam...

How to specify exceptions to be thrown by an implementor of an interface

I'm currently developing a solution and have designed it in a way such that it strongly implements the strategy/provider pattern. As such the solution exposes a number of interfaces and contains default implementations of these interfaces which can be replaced via a DI type methodology. Where the host application uses a number of these...

Is replacing strategies injected via a DI container a valid deployment mechanism?

I'm creating an application which uses a DI Container for injecting strategies into it. When deployed, if I require those strategies to change, is it a valid deployment strategy to deploy a new assembly with the new strategies and ammend the configuration file for instructing the DI container of which strategy to use? My concern is that...

Is this code too brittle?

I need to create a strategy pattern where a user selects four strategies from a list of twenty or thirty unique strategy objects. The list of strategies will be expanded as the project matures, and users can change their selected strategy at any time. I plan to store the strategy names they have selected as strings, and then use a meth...

Implement a better Strategy pattern

I have a Chequing account and a Saving account. I'm exploring how to implement the withdraw method using a Strategy pattern. Currently, the Chequing and Saving account both inherit from Account. For Saving account, withdrawals should not cause the balance to dip below 100 dollars. With the Chequing account, withdrawals must include ...

Objective C - Strategy Pattern ???

I understand the concept of the "strategy pattern" but i am still a little bit confused. Let'say we have a class named Dog Dog has MovementBehaviour (interface) which can be MovementBehaviourNormal & MovementBehaviourFast MovementBehaviourNormal and MovementBehaviourFast both contain a method named move QUESTION: what is the best way t...

Saving Data with the Factory Pattern?

I've been becoming more familiar with the Factory Pattern (along with Strategy Pattern) and what a great benefit the pattern can have. However, I've been struggling with the following situation: Previously, I would have done something like the following, where there's a manager class that would build and save a Car. There's no depende...