본문 바로가기

디자인패턴20

[디자인패턴] 각 패턴의 특징과 핵심 요약 Strategy Pattern(전략패턴) [디자인패턴] Strategy Pattern(전략패턴) Purpose of Strategy Pattern (전략패턴의 목적) - Defines a set of encapsulated algorithms that can be swapped to carry out a specific behavior. - 특정 동작을 수행하기 위해 스왑 할 수 있는 캡슐화.. wisdomtic.cf - 이 패턴은 컨텍스트(context) 개체 코드 내에 있는 많은 조건문들(conditional statements)에 대안을 제공한다. 해당 패턴과 관련된 객체들 내부에 다양한 행위(behavior)들을 캡슐화(encapsulation)함으로써, context 객체가 행위를 바꾸고자 할 .. 2022. 9. 26.
[디자인패턴] Design Pattern의 종류와 활용하기 Design Pattern 은 언제 사용하는가? - Design patterns help to ensure that a system can change in specific ways → easier to change - 디자인 패턴은 시스템이 특정 방식으로 변경될 수 있도록 보장합니다 → 변경하기 더 쉽습니다. - 앞으로 일어날 변화에 대한 대비책으로도 Pattern을 적용할 수 있고 - 문제를 해결하기 위해서 Patern을 적용할 수도 있습니다. GoF Patterns 분류 Design Pattern 적용하는 상황과 패턴의 종류 - Creating an Object by Specifying a Class Explicitly (클래스를 명시적으로 지정하여 개체 만들기) → Factory Method Pa.. 2022. 8. 29.
MVC pattern MVC Pattern 이란 - MVC 패턴은 두 개 이상의 패턴을 결합해서 문제를 해결하는 솔루션으로 만든 Compound Pattern(복합패턴) - 사용하는 패턴 : Strategy pattern / Observer pattern /Composite pattern - MVC를 구성하는 세 가지 객체 • Model : Application 객체 (Observer 객체) → makes use of the Observer pattern so that it can keep observers updated, yet stay decoupled from them. → observer를 업데이트하면서도 observer와 분리 상태를 유지할 수 있음 • Controller : UI가 사용자 입력에 반응하는 방식을 정.. 2022. 8. 29.
[디자인패턴] Bridge pattern (브릿지 패턴) Purpose of Bridge Pattern (브릿지 패턴의 목적) - Defines an abstract object structure independently of the implementation object structure in order to limit coupling. - 구현 객체와 추상 객체 (개념)를 독립적으로 분리하는 구조로 정의 Bridge pattern (브릿지 패턴) - bridge는 '무엇인가를 연결한다'는 의미 → bridge 패턴도 두 장소를 연결하는 역할이 있음 - lets you split a large class or a set of closely related classes into two separate hierarchies —abstraction and impl.. 2022. 8. 28.
[디자인패턴] Composite Pattern (컴포지트 패턴) Purpose of Composite Pattern (컴포지트 패턴의 목적) - Facilitates the creation of object hierarchies where each object can be treated independently or as a set of nested objects through the same interface. - 각 개체를 독립적으로 처리하거나 동일한 인터페이스를 통해 중첩된 개체 집합으로 처리할 수 있는 개체 계층 구조를 쉽게 만듭니다. Composite pattern (컴포지트 패턴) - composite의 의미는 '합성의', '합성물', '혼합 양식'이다. →뭔가 합쳐진 형태이겠지..! - composes objects into tree structures .. 2022. 8. 28.
[디자인패턴] Adapter pattern (어댑터 패턴) Purpose of Adapter Pattern (어댑터 패턴의 목적) aka) Wrapper - Permits classes with different interfaces to work together by creating a common object by which they may communicate and interact. - 서로 다른 인터페이스를 가진 클래스가 통신하고 상호 작용할 수 있는 공통 개체를 만들어 함께 작동하도록 Adapter pattern (어댑터 패턴) - Converts the interface of a class into another interface clients expect. - 클래스의 인터페이스를 클라이언트가 기대하는 다른 인터페이스로 변환 - Mechanism →.. 2022. 8. 28.
[디자인패턴] Decorator pattern (데코레이터 패턴) Purpose of Decorator Pattern (데코레이터 패턴의 목적) - Allows for the dynamic wrapping of objects in order to modify their existing responsibilities and behaviors. - 객체를 동적으로 래핑하여 기존 책임과 동작을 수정할 수 있습니다. Design Principle (디자인원칙) - OCP (Open-Closed Principle) : easily extended to incorporate new behavior without modifying existing code Decorator pattern (데코레이터 패턴) - decoration은 '장식(포장)'이란 뜻 - The Decorator.. 2022. 8. 28.
[디자인패턴] Singleton pattern (싱글톤 패턴) Singleton Pattern (싱글톤 패턴) - Ensures that only one instance of a class is allowed within a system. - multi-threaded issue해결을 위해, 시스템 내에서 클래스의 인스턴스 하나만 허용 → instance는 외부에서 바꿀 수 없게 private으로 선언 →public static으로 제공 uniqueInstace를 null check 후, 없을 때만 생성해서 return → '하나'의 인스턴스만 생성하여, 한 번만 메모리에 올리고 사용하는 디자인 패턴 → 인스턴스가 필요할 때, 똑같은 인스턴스를 만들지 않고 기존의 인스턴스를 활용 → 단점: 싱글톤 인스턴스가 혼자 너무 많은 일을 하거나, 많은 데이터를 공유시키면 다.. 2022. 8. 28.
[디자인패턴] Builder pattern (빌더 패턴) Purpose of Builder Pattern (빌더 패턴의 목적) - Allows for the dynamic creation of objects based upon easily interchangeable algorithms. - 쉽게 교환할 수 있는 알고리즘을 기반으로 개체를 동적으로 만들 수 있다. Builder pattern (빌더 패턴) - 생성 패턴의 한 종류로 전략 패턴의 특화된 형태 - Composite는 Builder가 만드는 것 - Director와 Builder 구조 → Director knows what parts are needed for the final product. (Director는 어떤 부품이 필요한지 알고 있고) → Concrete builder knows how .. 2022. 8. 28.