Design Pattern Used In JDK

Connect with

Flyweight : use sharing to support a large number of objects that have part of their internal state in common where the other part of state can vary. Examples –

  • java.lang.Integer#valueOf(int) (also on Boolean, Byte, Character, Short, Long, Float and Double)
  • Java String creation.

Proxy : provide a placeholder for an object to control references to it. If you use spring framework, you should be very well acquainted with Proxy.

Used in jdk:

  • Java RMI
  • All libraries which use Java proxy , Reflection proxy and CGLIB proxy
  • Spring AOP creates proxies for supplied objects

Decorator: add additional responsibilities dynamically to an object. Examples –

Used in jdk:

  • All sub-classes of java.io.InputStream, OutputStream, Reader and Writer have a constructor taking an instance of same type.
  • Almost all implementations of java.util.List, Set and Map have a constructor taking an instance of same type.
    java.util.Collections, the checkedXXX(), synchronizedXXX() and unmodifiableXXX() methods.
  • javax.servlet.http.HttpServletRequestWrapper and HttpServletResponseWrapper
  • Display tag custom tag library proved option to decorator for rendering of tables in JSP.
  • Any client side JavaScript library which has render-er or parser like Yahoo UI datatable, JQuery grid

  • Connect with

Leave a Comment

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