Dependency Inversion Principle

Previously, we learned about OCP (Open/Closed Principle) and LSP (Liskov Substitution Principle). OCP is the principle of allowing changes but preventing modifications, and LSP is the principle that a base class can be replaced by its subclass. Here, I will talk about the structure that arises from strictly applying these two principles. This structure itself becomes a principle, and its name is the Dependency Inversion Principle. What’s Wrong with Software? As developers, we often drive ourselves into bad design. Why does this happen? The core of the problem is that we haven’t defined what bad design is. ...

October 11, 2020

Interface Segregation Principle

Interface Segregation Principle Introduction Terminology client, user: An object, function, or class that uses a specific class or object. What is ISP? ISP stands for Interface Segregation Principle, which means interfaces should be separated. Problem If this principle is not followed, you end up with a fat (or polluted) interface. Such interfaces usually have poor cohesion. In other words, unrelated functions are grouped together in a single interface. Goal According to ISP, these fat interfaces should be split. Clients using these interfaces should not see them as a single class, but rather as abstract base classes with cohesive interfaces. ...

October 11, 2020

Liskov Substitution Principle

Liskov Substitution Principle References Liskov Substitution Principle (Wikipedia) LSP article (Uncle Bob) Design by Contract (Wikipedia) Introduction Previously, the core mechanism of OCP (Open/Closed Principle) was to use abstraction and polymorphism. By using inheritance, you could create derived classes from an abstract base class. So, what design rules govern this kind of special inheritance? What are the characteristics of the best inheritance hierarchies? What causes hierarchies that do not conform to OCP? ...

October 11, 2020

Open Closed Principle

Open-Closed Principle Classes, modules, and functions should be open for extension but closed for modification. - MEYER Bertrand(1988) Object-Oriented Software Construction Allow extension, but do not allow modification. In other words, a class should be extensible without modification. How to Implement the Principle There are two methods. Both use generalization, but differ in their goals, techniques, and results. 1. Meyer’s Open-Closed Principle Method Implement using inheritance. Explanation By using inheritance, the parent class can be implemented through inheritance, so it is open for extension. Since the parent class is accessed through the child class, the parent class can be hidden and thus closed for modification. ...

October 11, 2020

Single Responsibility Principle

Single Responsibility Principle Source https://blog.cleancoder.com/uncle-bob/2014/05/08/SingleReponsibilityPrinciple.html Question What exactly is a reason to change? How people interpret “reason to change” Bug fix? Refactoring? Core Idea Relate “reason to change” with “responsibility”. The above two are the programmer’s responsibility. => Who should the program’s design respond to?! Example 1. CEO Reporting to the CEO is a C-Level decision (CFO, COO, CTO). 2. CFO Responsible for controlling finance. 3. COO Responsible for operating the company. ...

October 11, 2020