When Will You Use Strategy Design Pattern in Java ?

Strategy pattern is very useful for implementing a family of algorithms. It is a behavioral design pattern.

With Strategy pattern we can select the algorithm at runtime. We can use it to select the sorting strategy for data. We can use it to save files in different formats like- .txt, .csv, .jpg etc.

In Strategy pattern we create an abstraction, which is an interface through which clients interact with our system. Behind the abstraction we create multiple implementation of same interface with different algorithms.

For a client, at runtime we can vary the algorithm based on the type of request we have received.

So we use Strategy pattern to hide the algorithm implementation details from client.

In Java Collections.sort() method uses strategy design pattern.



You May Interest

Java How To Find The Average Of 10 Numbers Using A While Loop

How Will You Use Other Java Files of Your Application in JSP Code ...

What are the Differences Between Collection and Collections in Ja ...

Which Class Contains Clone Method in Java ?

What are the Differences Between a Vector and an ArrayList in Jav ...