Object Oriented
OOP has three features:
- Encapsulation
- Inheritance
- Polymorphism
Inheritance
- C++’s default inheritance is private
- It’s recommended to start with public inheritance
- There are three modes: private, public and protected
Rewrite
- Refactoring methods based on the methods defined in the base class.
- Must guarantee that the method name and parameters are exactly the same
Polymorphism and Binding
- In C++, the default binding is static binding, which is set during the compiling time
- Polymorphism uses dynamic binding
- Inheritance + Methods Refactoring + Virtual Methods + Reference to the Parent Class/Pointer pointing to the Child Class
- To convert the static binding to the dynamic binding, refactor the Parent class method into a virtual method by adding “virtual” at the beginning