Say, I have some MainClass which at some point in its methods has instantiation of an object of a OtherClass as an attribute of the MainClass.
mainobj = MainClass()
isinstance(mainobj.otherclassobj, OtherClass) == True
Now, I want to extend the OtherClass, and then use the MainClass with new extended class.
Do I have more convenient options, other than extending MainClass and redefining all of its methods which instantiate self.otherclassobj to do it from ExtendedOtherClass?
If you can change the implementation of
MainClassslightly, you don’t need to inherit from it. Just have something likeThen
MainClasswill by default useOtherClass, but you can pass inExtendedOtherClassas a keyword argument.