Impact of unintended change of order in inheritance
In this section, we will be looking at examples that demonstrate how important the order of inheritance is to resolve the methods in the case of multilevel inheritance, and what happens when the order changes in one of the parent or superclasses unintentionally.
This is how it works:
- Let’s start by creating a class named
CommonCounter
that initializes with two attributes,items
andname
. Let’s also add two methods to this class,return_cart
(which returns the items in the cart) andgoto_counter
(which returns the name of the counter). This is how the code looks:class CommonCounter(): def __init__(self,items,name): self.items = items self.name = name def return_cart(self): cartItems = [] ...