[Tutor] class-inheritence
Alan Gauld
alan.gauld at yahoo.co.uk
Mon May 18 16:24:00 EDT 2020
On 18/05/2020 15:34, shubham sinha wrote:
> I am unable to define or call package class by which repository class will
> contain package class.
Since you haven't shown us your package class or how you
are trying to use it, its hard for us to know what might be wrong.
Alex has shown what we'd normally expect. If you are doing
something different you will need to let us see some code
plus any error messages.
> 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.
I'm not sure where you think inheritance fits in here?
Inheritance is a mechanism to reduce code duplication.
(and in some languages, although not in Python, it is
also the mechanism that enables polymorphism)
The relationship is defined as an "is-a" relationship.
The relationship in your example is a "has-a" relationship,
also known as aggregation or containment. No inheritance
needed.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list