What are the examples of Strategy design pattern in JDK?

In JDK there are many places where Strategy design pattern is used. Some of these are as follows:

  • java.util.Comparator: In a Comparator we can use compare() method to change the strategy used by Collections.sort() method.
  • javax.servlet.http.HttpServlet: In a HttpServlet class service() and doGet(), doPost() etc. methods take HttpServletRequest and HttpServletResponse and the implementor of Servlet processes it based on the strategy it selects.

Leave a Reply

Your email address will not be published. Required fields are marked *