-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
Improvements
- Unified Method Naming: Instead of having separate methods gdisplay, pdisplay, and cdisplay, I’ve unified them into a single method named display. This change simplifies the method structure and allows for easier and more logical calls to display at each level of inheritance.
- Using super() for Method Overriding: The super() function calls the display method of the superclass in each class. This helps in displaying the entire hierarchy in one call and reduces redundancy, making the code more maintainable.
- Clear Class Naming: Renamed classes to follow the CamelCase convention (e.g., GrandParent instead of grandparent), adhering to Python naming conventions for classes.
Benefits of the Improvements
• Code Readability: Using consistent method names (display) and following naming conventions improves readability.
• Reduced Redundancy: By using super(), there is no need to call each method separately from the child class instance.
Description
This code demonstrates the concept of Multilevel Inheritance in Python, where a class inherits from a parent class, and this parent class is itself derived from another class. In this example, the grandparent class is inherited by the parent class, which is further inherited by the child class. This kind of inheritance helps in creating a clear hierarchy and allows classes to reuse code from their ancestor classes.
Metadata
Metadata
Assignees
Labels
No labels