mardi 16 juillet 2013

Decorator Design Pattern in Java - Real life Example

Decorator Pattern is one of the famous Gang of Four (GOF) structural design pattern, which provides an alternative way  of extending an object's functionality. It's different than the traditional way of adding new functionality into an object using Inheritance, since it's based on Composition and provides additional functionality at the run time, as opposite to Inheritance, which adds new functionality at compile time. Decorator design pattern is introduced by famous Gang of Four design pattern book, almost 2 decades ago. It's a time-tested way of adding new functionalities into an object. In this Java design pattern tutorial, we will learn Decorator design pattern by using it in a Java example. This is the best way of learning design pattern, followed you try it yourself to apply in similar scenarios. Decorator pattern is one of the popular design patterns along with Factory method pattern and Singleton Pattern, and you can see it's usage even in JDK itself. Couple of classes from java.io package e.g. BufferedInputStream, LineNumberInputStream are good example of Decorator design pattern in Java.
Read more »
Share:

0 commentaires:

Enregistrer un commentaire