Strategy Design Pattern With Spring Boot

Strategy Design Pattern

Ravinder Thirumala
3 min readFeb 17, 2020

Strategy design pattern is a behavioral design pattern that enables selecting an algorithm at run-time.

The intent of the Strategy design pattern is to:
“Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.” [GoF]

UML class and sequence diagram from wiki

From wiki page https://en.wikipedia.org/wiki/Strategy_pattern

There are quite number of articles explaining Strategy design pattern and
how to implement them in various languages. The intent of this article is to
learn how to implement strategy pattern in a spring boot application.

Spring Boot

Spring Boot has become the de facto standard for Java microservice development. It is useful to learn how to implement common design patterns in spring boot applications.

Spring introduced the @Autowired annotation for dependency injection.
Any of the Spring components can be autowired. These include, components, configurations, services and beans.

In this article we will implement Strategy Design Pattern using dependency injection.

--

--