What are the examples of Template method design pattern in JDK?

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

In Java Abstract Collection classes like java.util.AbstractList, java.util.AbstractSet and java.util.AbstractMap implement a template for their corresponding Collection.

javax.servlet.http.HttpServlet
: In the HttpServlet class all the doGet(), doPost() etc. methods send a HTTP 405 “Method Not Allowed” error to the response. This error response is like a Template that can be further customized for each of these methods.

In java.io package there are Stream and Writer classes like java.io.InputStream, java.io.OutputStream, java.io.Reader and java.io.Writer that provide non-abstract methods. These methods are implementation of Template method design pattern.

Read the full book at www.amazon.com
Posted in Design Pattern, Design Pattern Interview Questions

Leave a Reply

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

*