in Design Patterns by
Q:
Give an example of decorator design pattern?

1 Answer

0 votes
by

The decorator pattern, also known as a structural pattern is used to add additional functionality to a particular object at runtime. It wraps the original object through decorator object. For example, when you are buying a burger, you can customize it by adding extra filling and sauces, now the cost of these items have to be added to the final price. The customization will differ from customer to customer and offer from a shop. Creating different classes of burger with different fillings will end up creating a lot of classes. Decorator solves this problem by extending the functionality of single Burger class at runtime based on customer request.

Related questions

0 votes
asked Oct 16, 2019 in Design Patterns by DavidAnderson
0 votes
asked Oct 17, 2019 in Design Patterns by Robin
0 votes
asked Oct 17, 2019 in Design Patterns by Robin
0 votes
asked Oct 16, 2019 in Design Patterns by DavidAnderson
...