Design Pattern 4

[DesignPattern] Singleton in TypeScript

TypeScript로 작성한 싱글턴 class Singleton { private static instance: Singleton | null = null; // private 생성자로 외부에서의 인스턴스 생성을 막음 private constructor() {} // 정적 메서드를 통해 인스턴스에 접근 public static getInstance(): Singleton { if (!Singleton.instance) { Singleton.instance = new Singleton(); } return Singleton.instance; } // 다른 메서드들... public doSomething(): void { console.log('Doing something...'); } } const ins..

Design Pattern 2024.03.16

[DesignPattern] State Pattern in TypeScript

TypeScript로 작성한 스테이트 패턴 예제 // 상태를 나타내는 인터페이스 interface State { handle(): void; } // StateA 클래스 class StateA implements State { handle(): void { console.log('A상태'); } } // StateB 클래스 class StateB implements State { handle(): void { console.log('B상태'); } } // Context 클래스 class Context { private state: State; constructor(state: State) { this.state = state; } // 상태 변경 메서드 setState(state: State): voi..

Design Pattern 2024.03.16

[DesignPattern] 디자인 패턴 종류

Gang of Four(GoF) 디자인 패턴은 총 23가지 생성 패턴 (Creational Patterns): 객체 생성에 관련된 패턴으로, 객체를 생성하고 초기화하는 방법을 다룹니다. 팩토리 메서드 (Factory Method) 추상 팩토리 (Abstract Factory) 빌더 (Builder) 프로토타입 (Prototype) 싱글턴 (Singleton) 구조 패턴 (Structural Patterns): 클래스나 객체의 구조를 설계하는 데 사용되는 패턴으로, 클래스와 객체들이 서로 더 유연하게 작동할 수 있도록 도와줍니다. 어댑터 (Adapter) 브리지 (Bridge) 컴포지트 (Composite) 데코레이터 (Decorator) 퍼사드 (Facade) 플라이웨이트 (Flyweight) 프록시 (..

Design Pattern 2023.10.13