Define mother and father as child attributes, keep the two as references to the mother and father object instances (has-a relationship)
class Mother:
...
class Father:
...
class Child:
def __init__(self, mother, father):
self.mother = mother
self.father = father
...
...
# use whatever attributes/methods you want from mother or father with
# self.mother.somethod() or self.father.someattribute
mother1 = Mother() # create real objects from your classes
father1 = Father()
child1 = Child(mother1, father1) # pass them to the child `__init__`
Where you keep the Mother and Father classes is irrelevant. You might keep them in the same file or make a family.py
module and then
from family import Mother, Father
class Child:
...
defining your child in the current script.
Edit:
As per your comments you would need to inherit the Child
class from some Parent
class, from which you also inherit both Mother
and Father
classes.
That would inherit the methods and attributes but would also state that a Child
is also a Parent
, which he isn't. But they are all Persons, so you can create a Person
class with common attributes and methods, extend it with a Mother and Father class both inheriting from Person, and then alter the child class __init__
to receive a list of parents. You mantain a container-like has-a relationship, but now a child can have many parents. Maybe add a method add_parent
to append new parents to that list in self.parents
. If creating methods in Child
just to delegate (call) the corresponding methods in the parents becomes labourious, then you might consider changing the Child
class to inherit from Person class too, getting all the common Parents machinery. You'll need to adapt a bit the code in those scenarios, but I think you get it.