so please bear with me on this.
I struggle some in understanding certain aspects of the concept of inheritance.
As such, I was wondering, what would be the difference between implementing one class, say "Child", as the child of another, say "Parent", versus simply making "Child" create and utilize a "Parent" object within itself?
For example, given the parent class as:
class Parent:
def __init__(self, arg):
self.arg = arg
def parent_method(self):
print(self.arg)
What would be the difference between making and implementing a child class:
class Child(Parent):
def __init__(self, arg):
super().__init__(arg)
Child('foo').parent_method()
Versus:
class Child:
def __init__(self, arg):
self.parent = Parent(arg)
def call_method(self):
self.parent.parent_method()
Child('foo').call_method()
Both of which simply print:
foo
Is the only difference here syntactical? I mean, it definitely seems more efficient to use inheritance here, but is there something else I'm missing?
Thanks!