Strategy pattern with spring beans

Since a concrete strategy is very often determined at run time based on the provided parameters or so, I would suggest something as follows. @Component public class BurgerStrategy implements MealStrategy { … } @Component public class SausageStrategy implements MealStrategy { … } Then inject all such strategies into a map (with bean name as a … Read more

What is the difference between Strategy pattern and Dependency Injection?

DI and Strategy work in the same way, but Strategy is used for more fine-grained and short-lived dependencies. When an object is configured with a “fixed” Strategy, for example when the object is constructed, the distinction between Strategy and DI blurs. But in a DI scenario it is more unusual that the dependencies of objects … Read more

Strategy Pattern with no ‘switch’ statements?

Strategy isn’t a magic anti-switch solution. What it does do is give modularise your code so that instead of a big switch and business logic all mixed up in a maintenance nightmare your business logic is isolated and open for extension you have options as for how you create your concrete classes (see Factory patterns … Read more

Strategy Pattern V/S Decorator Pattern

The strategy pattern allows you to change the implementation of something used at runtime. The decorator pattern allows you augment (or add to) existing functionality with additional functionality at run time. The key difference is in the change vs augment In one of the questions you linked to it also points out that with the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)