Skip to main content

Suppose that I have the following python base class:

Classclass BaseClass(object):
 
    def Aa():
        # **this"""This method uses method Bb(), defined in the inheriting class**class"""

And also a class that inherites BaseClass:

Classclass UsedByUser(BaseClass):
 
    def Bb():
        # B"""b() is defined here, yet is used by the base classclass"""

My user would only create instances of class UsedByUser. Typical use would be:

if (__name__ __name__=='__main__'== )'__main__':
        
    # initialize the class used by the user        
    usedByUser = UsedByUser() 

    # invoke method Aa()
    usedByUser.Aa()

My questions is, is the above use problematic? is this a valid approach, or must I also define method Bb() in BaseClass() and then override it in UsedByUser(BaseClass)?

Suppose that I have the following python base class:

Class BaseClass(object):
 
    def A():
        # **this method uses method B(), defined in the inheriting class**

And also a class that inherites BaseClass:

Class UsedByUser(BaseClass):
 
    def B():
        # B() is defined here, yet is used by the base class

My user would only create instances of class UsedByUser. Typical use would be:

if ( __name__=='__main__' ):
        
    # initialize the class used by the user        
    usedByUser = UsedByUser()
    # invoke method A()
    usedByUser.A()

My questions is, is the above use problematic? is this a valid approach, or must I also define method B() in BaseClass() and then override it in UsedByUser(BaseClass)?

Suppose that I have the following python base class:

class BaseClass(object):
    def a():
        """This method uses method b(), defined in the inheriting class"""

And also a class that inherites BaseClass:

class UsedByUser(BaseClass):
    def b():
        """b() is defined here, yet is used by the base class"""

My user would only create instances of class UsedByUser. Typical use would be:

if __name__ == '__main__':
    # initialize the class used by the user        
    usedByUser = UsedByUser() 

    # invoke method a()
    usedByUser.a()

My questions is, is the above use problematic? is this a valid approach, or must I also define method b() in BaseClass and then override it in UsedByUser?

Source Link
user3262424
  • 7.5k
  • 16
  • 59
  • 86

Inheritance in Python?

Suppose that I have the following python base class:

Class BaseClass(object):

    def A():
        # **this method uses method B(), defined in the inheriting class**

And also a class that inherites BaseClass:

Class UsedByUser(BaseClass):

    def B():
        # B() is defined here, yet is used by the base class

My user would only create instances of class UsedByUser. Typical use would be:

if ( __name__=='__main__' ):
        
    # initialize the class used by the user        
    usedByUser = UsedByUser()
    # invoke method A()
    usedByUser.A()

My questions is, is the above use problematic? is this a valid approach, or must I also define method B() in BaseClass() and then override it in UsedByUser(BaseClass)?