CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// NOTE: The "Bad way" codes are commented so the compiler will not raise an error for redifinition of classes in both "Correct way" and "Bad way". If you want to test any of the "Bad way" codes, make sure to comment the "Correct way" code and uncomment the corresponding "Bad way" code of the same principal.
#include <iostream>
#include <vector>
using namespace std;
// What is SOLID: SOLIID is a set of five OOP(Object-Oriented Programming) design principals that help create better codes which are flexible, scalable and maintainable.
// SOLID stands for:
/*
S -> Single Responsibility Principle (SRP)
O -> Open/Closed Principle (OCP)
L -> Liskov Substitution Principle (LSP)
I -> Interface Segregation Principle (ISP)
D -> Dependency Inversion Principle (DIP)
*/
/*
1. Single Responsibility Principle (SRP):
A class should only have one reason to change, simply means it has one job or responsibility.
*/
// Bad way: The Employee class handles responsibility of both calculating salary and saving to the database, so it needs to be modified if salary calculation logic or database changes; This violates SRP.
/*
class Employee {
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run