mirror of
https://github.com/rjNemo/design-patterns
synced 2026-06-06 02:26:40 +00:00
* update gitignore * add decorator code example Co-authored-by: Ruidy <r.nemausat@empfohlen.de>
23 lines
713 B
Python
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()
|