-
-
Notifications
You must be signed in to change notification settings - Fork 125
/
decorator_concept.py
38 lines (27 loc) · 885 Bytes
/
decorator_concept.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# pylint: disable=too-few-public-methods
# pylint: disable=arguments-differ
"Decorator Concept Sample Code"
from abc import ABCMeta, abstractmethod
class IComponent(metaclass=ABCMeta):
"Methods the component must implement"
@staticmethod
@abstractmethod
def method():
"A method to implement"
class Component(IComponent):
"A component that can be decorated or not"
def method(self):
"An example method"
return "Component Method"
class Decorator(IComponent):
"The Decorator also implements the IComponent"
def __init__(self, obj):
"Set a reference to the decorated object"
self.object = obj
def method(self):
"A method to implement"
return f"Decorator Method({self.object.method()})"
# The Client
COMPONENT = Component()
print(COMPONENT.method())
print(Decorator(COMPONENT).method())