[Tutor] class-inheritence

shubham sinha upwkwd at gmail.com
Mon May 18 10:34:18 EDT 2020


Hi,
we have" package" class that represents a software package which could be
installed on machine on our network.
"Repository" class that represent all the packages we have available for
installation internally.
In this case "Repository" is not a "package" and vice-versa. Instead of
this 'Repository' contains "Packages"

Below given is the repository class  ->

class Repository:
def __init__(self):
     self.packages = {}
def add_packages(self, package):
     self.packages[package.name] = package
def rem_packages(self, package):
    del self.packages[package.name]
def total_size(self):
    result = 0
    for package in self.packages.values():
        result += package.size
    return result

My problem:
I am unable to define or call package class by which repository class will
contain package class.
Please help me through this as this is the example given to me by those who
taught me class inheritance in which one class have relation with other but
one class is not child/inherit to other.
Guide me through this so that i can think clearly regarding to object
oriented programming problems.
----------------------------------------
Thanks in advance!

----------------------------------------
Regards,
Shubham Kumar sinha


More information about the Tutor mailing list