This post originated from an RSS feed registered with Java Buzz
by Javin Paul.
Original Post: Decorator Design Pattern in Java - Real life Example
Feed Title: Java67
Feed URL: http://www.java67.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
Decorator Pattern is one of the famous Gang of Four (GOF) structural
design pattern, which provides an alternative wayof extending an object's functionality. It's
different than traditional way of adding new functionality into object using
Inheritance, since it's based on Composition
and provides additional functionality at runtime, as opposite to Inheritance, which
adds new functionalities 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 object. In this Java design pattern tutorial, we will
learn Decorator design pattern by using it in a Java example. This is a best
way of learning design pattern, followed you try it yourself to apply in
similar scenarios. Decorator pattern is one of the popular design pattern 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, LineNumberInputStreamare good
example of Decorator design pattern in Java.