1. Principles of OOP #
Created Wednesday 08 January 2020
What is OOP #
- OOP is just a programming paradigm.
- OOP solves some major problems that arise in procedural programming.
- As OOP is a reaction to the procedural style, its principles are nothing but solutions.
Principles of OOP #
There are 4:
- Encapsulation - practice of combining variables(data) and relevant functions into a single unit.
- Solution - Minimizes parameters, consequently minimizing arguments.
- Context in C++ - class
- Abstraction - process of hiding parts of the program for maintainability purposes.
- Solution - Simplifies the interface. Reduces the impact of change, i.e we can have a complex and flexible web of helper functions, but the interface remains the same.
- Context in C++ - Access control, viz public, private and protected, enforce ‘data hiding’, which is the ‘tool’ used to achieve abstraction.
- Inheritance
- Solution - Eliminates redundant code.
- Context in C++ - Parent class are specified when defining a class, using the ‘:’ symbol.
- Polymorphism
- Solution - Eliminates if/else and switch statements. Code context based functions.
- Context in C++ - The compiler chooses the relevant version of the function. We don’t have to specify while calling.
Visibility - Abstraction #
Visibility(access of members using object) is controlled using three keywords:
- Public
- Private
- Protected
FIXME: Modifers