Access to the same function from two different classes

I have two classes, suppose A and B. Inside B, I create A.

I have a function func()that is required by both classes.

How should I do it? I thought about this:

class A:
   func()

class B:
   x = A()
   func()

def func():

And then I can access func () from A or B. Is this approach used in order or is there a better way to do this (maybe using the OO approach)

Note that I'm new to OO programming, so I'm interested in whether I can apply any OO design to it.

Edit: a function may differ in the arguments it takes.

+3
source share
2 answers

func, - , .

+1

func

class Base(object):
    def func():
        #...
class A(Base):
    #...
class B(Base):
    #...
0

Source: https://habr.com/ru/post/1759574/


All Articles