Decorator pattern allow a user to add new functionality to an existing object without changing its structure. This kind of design pattern comes in structural pattern as this pattern acts as a wrapper to live class.
This pattern creates a decorator class which wraps the original class and provide additional functionality keeping class method signature intact.
We are demonstrating the use of decorator pattern via following instance in which we will adorn a shape with some colour without modify shape class.
We're going to form a Shape interface and actual classes implementing the Shape interface. We will then create an abstract decorator class Shape Decorator implementing the Shape interface and having Shape entity as its example inconsistent.
RedShapeDecorator is insubstantial class implementing Shape Decorator.
DecoratorPatternDemo, our presentation class will use RedShapeDecorator to adorn Shape objects.
Create an interface.
Create concrete classes implementing the similar interface.
Construct abstract decorator class implementing the Shape interface.
Build concrete decorator class extending the Shape Decorator class.
Make use of the RedShapeDecorator to decorate Shape objects.
Verify the output.
Design Patterns Related Interview Questions
|Java Script Interview Questions||AJAX Interview Questions|
|Graphic Design Interview Questions||Adobe Indesign Interview Questions|
|Java-Multithreading Interview Questions||Database Design Interview Questions|
|Compiler Design Interview Questions||CSS Advanced Interview Questions|
|Java Design Patterns Interview Questions||Hardware design Interview Questions|
|Material Design Lite Interview Questions||Object Oriented Analysis and Design Interview Questions|
|Standard Template Library (STL) Interview Questions|
Design Patterns Tutorial
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.