I have a composite class A
that contains some component classes like B
. To elegantly call the methods contained within component classes, I added some wrapper functions like foo
where the component method is called in a single line. However, I want to know if there is any way to dynamically add the methods of class B
to class A
using a decorator without having to manually include these methods inside the composite.
class A: # composite
def __init__(self):
self.B = B()
def foo(self):
# Instead of calling self.B.foo(...)
# I want to simply call self.foo(...)
# Then this method will not be needed
self.B.foo()
class B: # component
def foo(self):
print("foo")