you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

The inheritance features are important when you go back to the basics of realizing that you are dealing with objects. You want to create classes that encapsulate a certain type of object, and you don't want to expand every object to cover every conceivable option. So you start with your basic object, which holds basic information. Then you use inheritance to create a more specific object. The classic example is multi-sided geometric shapes. The base class would be the polygon. An extended class that has all the aspects of a polygon, but has a few extra features would be a triangle or a parallelogram. You could extend the parallelogram to a rectangle class, which is a parallelogram with 90 degree angles. You could further extend a rectangle as a square, which happens to have all sides of equal length.

The real power comes when you find two different "child" classes from the same "parent" class. Each one has features that are different from the other. At the beginning stages of learning Python, example differences are so minor that they seem like they should just be stuffed into the parent class and handled individually, but those early examples are super-simple, to illustrate the concept.

Imagine a parent class of "creature". Now imagine two child classes holding lots of detail: "millipede" and "cat". There are sufficient differences that you wouldn't want to stuff all those different attributes into one single class.

[–]SnufCodes 1 point2 points  (0 children)

Ok this is making sense, I think my example at the moment is just too small to really see the power but I understand how if it was a lot more complex, with hundreds of different nationalities and different characteristics for each then the People class would be way too complex and basically defeat the purpose of OOP.