Decorator Design Pattern

It is used when you:

  1. Need to add additional functionality/responsibility to an object dynamically.
  2. Need to remove functionality/responsibility from an object.
  3. Want to avoid too many sub-classes for adding additional functionality/responsibility.
Pizza.java
OnionPizza.java
SweetCornPizza.java
CapsicumPizza.java
PizzaShop.java
Output
CondimentDecorator.java
Cheese.java
Sauce.java

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store