Mahipal Nehra

2 years ago · 1 min. reading time · ~10 ·

Contact the author

Like Share Comment
Blogging
>
Mahipal blog
>
Decorator design pattern in java with examples

Decorator design pattern in java with examples

What Is De efator 9)
PLY Z

The decorator design pattern is one of the classic design patterns used to overcome the recurring design problems in object-oriented software. It allows us to add functionality to an object dynamically. By dynamically, we mean modifying the behaviour of an object at run time. Although we have used the term behaviour, but decorator design pattern falls in the category of structural design pattern, because it has something to do with the way we structure our classes. There are a few bumpy areas in using inheritance to which the decorator design pattern provides an elegant solution.

Decorator design pattern in java with examples

This article will first describe what decorator design pattern is, why to use it and then we will use a simple decorator design pattern java example to demonstrate its significance.

What is decorator design pattern in java?

Decorator design pattern in java proposes a way to customise our objects dynamically during run time, instead of us having to write code to do that during compile time. You can think of it as an alternative to sub classing. When we subclass a parent class, there might be multiple combination of classes resulting in a class explosion. As you can see in the image below, the beverage class is being subclassed by multiple classes to add their own blend to it. Although it seems to follow the Single Responsibility Principle, it quite does not seem an elegant solution and obviously is hard to maintain.

Read the full story here:  https://www.decipherzone.com/blog-detail/decorator-design-pattern-java-example
Like Share Comment
Comments

More articles from Mahipal Nehra

View blog
1 year ago · 1 min. reading time

The development of technology, storage, and processing strength has caused the embodiment of cloud c ...

1 year ago · 1 min. reading time

Microservices architecture enables a system to be divided into multiple smaller, individual and inde ...

1 year ago · 1 min. reading time

Top 10 IT skills that will be in demand in 2021. Every passing year the tech world grows and transfo ...

You may be interested in these jobs

  • Jio

    FTTx Engineer

    Found in: Talent IN - 4 days ago


    Jio Ahmedabad

    Job Responsibilities · : 1. Responsible for field operations and maintenance of FTTx network · 2. OLT, ODN Network HOTO within SLA · 3. Corrective and Preventive Maintenance · 4. Plan , monitor and control spares material, TMI and Tools requirement · & availability as per design ...


  • Ralph Lauren Bengaluru

    At Ralph Lauren, we unite and inspire the communities within our company as well as those in which we serve by amplifying voices and perspectives to create a culture of belonging, ensuring inclusion, and fairness for all. We foster a culture of inclusion through: Talent, Educatio ...

  • Hr Ace

    Java Full Stack- Mumbai

    Found in: Talent IN± - 4 days ago


    Hr Ace Mumbai

    Java full-stack is basically a term used for a web developer that uses Java to develop the entire technology stack is referred to as Java full stack developer. · Creating databases and servers that are resistant to outages and work endlessly. Ensuring cross-platform compatibility ...