design-patterns/structural/decorator/decorator.py
Ruidy 5842cba685
Decorator Pattern (#10)
* update gitignore

* add decorator code example

Co-authored-by: Ruidy <r.nemausat@empfohlen.de>
2020-09-25 15:40:51 +02:00

23 lines
713 B
Python

from component import Component
from dataclasses import dataclass
@dataclass
class Decorator(Component):
"""
The base Decorator class follows the same interface as the other components.
The primary purpose of this class is to define the wrapping interface for
all concrete decorators. The default implementation of the wrapping code
might include a field for storing a wrapped component and the means to
initialize it.
"""
_component: Component
@property
def component(self) -> Component:
"""The Decorator delegates all work to the wrapped component."""
return self._component
def operation(self) -> str:
return self._component.operation()