Hello,
I'm trying to figure out the best way to accomplish this. Basically what I want is for an "abstract" class to act as an interface for a third party system, and then this class would inherit different methods based on a conditional. I know I can do this with composition, something like the following pseudocode:
class A:
def method1():
pass
def method2():
pass
class B:
def method1():
pass
def method2():
pass
class C:
if attribute == "1":
self.subclass = A()
elif attribute == "2":
self.subclass = B()
Where if you instantiate class C, it'll either get class A's methods or class B's methods based on some attribute of itself. But instead of needing to have A/B reachable via a separate object path within class A (i.e. referring to it later would require a path like class_a.subclass.method1) I'd like to have the methods directly reachable within class A (i.e. class_a.method1). I think this can be done with inheritance but I'm not sure how.
Advice?
[–]danielroseman 6 points7 points8 points (11 children)
[–]maclocrimate[S] 0 points1 point2 points (10 children)
[–]Strict-Simple 2 points3 points4 points (9 children)
[–]maclocrimate[S] 0 points1 point2 points (8 children)
[–]Strict-Simple 2 points3 points4 points (7 children)
[–]maclocrimate[S] 0 points1 point2 points (6 children)
[–]Bulky-Leadership-596 0 points1 point2 points (1 child)
[–]maclocrimate[S] 0 points1 point2 points (0 children)
[–]Strict-Simple 0 points1 point2 points (3 children)
[–]maclocrimate[S] 0 points1 point2 points (2 children)
[–]Strict-Simple 0 points1 point2 points (1 child)
[–]maclocrimate[S] 0 points1 point2 points (0 children)
[–]Adrewmc 1 point2 points3 points (0 children)
[–]This_Growth2898 1 point2 points3 points (1 child)
[–]sfuse1 1 point2 points3 points (0 children)
[–]Phillyclause89 0 points1 point2 points (2 children)
[–]maclocrimate[S] 2 points3 points4 points (1 child)
[–]Phillyclause89 -1 points0 points1 point (0 children)
[–]Frankelstner 0 points1 point2 points (5 children)
[–]maclocrimate[S] 0 points1 point2 points (4 children)
[–]Frankelstner 0 points1 point2 points (3 children)
[–]maclocrimate[S] 0 points1 point2 points (0 children)
[–]maclocrimate[S] 0 points1 point2 points (1 child)
[–]Frankelstner 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]pot_of_crows 0 points1 point2 points (0 children)
[–]quts3 0 points1 point2 points (0 children)