Factory Method Pattern

References https://refactoring.guru/design-patterns/factory-method What is the Factory Method? Creational design pattern Provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created. Situation There is an existing logistics app that uses trucks. As the business grows, you want to add ships to support maritime logistics services. However, Truck is tightly coupled to the entire system, making it difficult to add Ship. Solution The main point of the problem 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

Prototype Pattern

What is the Prototype Pattern? The Prototype Pattern is a creational design pattern. It enables the creation of new objects by copying an existing object, rather than creating them from scratch via their class constructors. This helps decouple code from specific classes. Prototype: Common vs Software Usage When I first encountered the Prototype Pattern, I was confused. The word “prototype” in daily use has a slightly different meaning, so let’s clarify that first. ...

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

Singletone Pattern

References: Refactoring Guru - Singleton Pattern Wikipedia - Singleton Pattern jeong-pro 블로그 What is the Singleton Pattern? The Singleton Pattern is a creational design pattern that ensures a class has only one instance and provides a global point of access to it. When is it used? It’s useful in situations where exactly one object is needed to coordinate actions across the system—like: Database connection A shared configuration object A centralized logging service These are cases where a single, globally accessible instance makes sense. ...

October 11, 2020