jvirico / pizza_decorator

Examples of Decorator design pattern implemented in Java and Python.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pizza and Decorator pattern

Examples of Decorator design pattern implemented in Java and Python [2]. The Java example uses the concept of pizza and pizza toppings to exemplify this pattern [3].

Decorator pattern

In object-oriented programming, decorator pattern is a flexible alternative to subclassing for extending funcionality. It allows to attach additional responsabilities to an object dynamically, without affecting the behaviour of other objects from the same class. It is often useful for adhering to the Single Responsibility Principle, as it allows functionality to be divided between classes with unique areas of concern. Decorator use can be more efficient than subclassing, because an object's behavior can be augmented without defining an entirely new object [1].


Fig. 1 - UML class design of Decorator pattern.

Cite this work

J. Rico, (2019) Decorator pattern examples in Java and Python.
[Source code](https://github.com/jvirico/pizza_decorator)

References

[1] - Decorator Pattern Wikipedia
[2] - SHVETS, Alexander. Dive Into Design Patterns. Refactoring. Guru, 2018.
[3] - PPCU, Budapest. Design Patterns

About

Examples of Decorator design pattern implemented in Java and Python.

License:MIT License


Languages

Language:Python 53.9%Language:Java 46.1%