Object-oriented programming can be seen as focusing on the creation of objects which contain both data and functionalit. These object defintions can coresspond to real world objects or concepts and the functions that operate on these objects represent the way that real world object interact.
By week 3, we have jumped into topics on inheritance. At first the concepts did seem quite confusing at first but after going over notes and readings, understanding why inheritance is important and why it is used was key to understanding the concept. Some of the things i learned are:
- if one wanted to modify an existing class to change or add functionality, one cannot just directly make changes as it would break the existing clients.
- one of the solution would be to create a subclass of the base class (i.e. class Parent(object): would be the base class while class Child(Parent): would be the subclass).
- by default, the Child class will inherit all the methods from the Parent class and therefore the Child like is exactly the same as Parent class except with the desired changes applied such as adding or modifying behaviour.
- adding or modifying behaviour in the Child class can result in overrides. This means that whatever desired changes to methods and behaviour in the Parent class can be applied to the Child class by naming the method with the same name in which the Child class will override the Parent class.
No comments:
Post a Comment