I have two classes, suppose A and B. Within B, I instantiate A.
I have a function func() that is required by both the classes.
How should I go about it? I had thought of this approach:
class A:
func()
class B:
x = A()
func()
def func():
And then I can access func() from within A or B. Is this approach OK or is there a better way to do this (perhaps using an OO approach)
Note that I am new to OO programming and that is why I am interested in knowing whether I can apply any OO design to this.
Edit: The function can differ in the arguments it takes.
Define func before you define either class, and it will be available to both.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With