본문 바로가기

CS BASIC/소프트웨어 설계와 방법론

[CS BASIC] 소프트웨어의 디자인 패턴

개요

오늘은 소프트웨어 개발에 사용 되는 다양한 디자인 패턴(design patterns)에 대해서 알아보도록 하겠습니다.

 

소프트웨어는 다양한 모듈과 함수, 프로퍼티, 객체 지향 프로그래밍에서는 객체 들 까지 서로 상호작용하여 하나의 기능을 제공하게 됩니다.

이러한 소프트웨어는 개발자가 어떻게 그 프로그램을 설계하고 개발 했는지에 따라서 종류를 구분할 수 있는데요.

정말 신기하게도 지구상에 존재하는 국적, 인종, 나라 별로 다양한 배경에서 프로그래밍을 하는 개발자라도

큰 틀에서 보면 그들이 만든 소프트웨어 모듈의 구조와 설계한 방식은 비슷한 경향성을 띄게 된다고 합니다.

 

그리고 이러한 소프트웨어가 설계된 방식, 사용 방법, 모듈의 구조 등을 종합적으로 평가하여 분석해보면

몇 가지 비슷한 경향성을 갖는 종류(Type)로 구분되며

이때 소프트웨어 간의 ‘분류’에 사용 되는 기준이 ‘디자인 패턴(design patterns)’이라고 할 수 있습니다.

 

또한, 디자인 패턴은 궁극적으로 개발자가 어떤 소프트웨어의 기능을 개발하기 위해 고민한 ‘문제 해결 방식’이며

조금 더 확장된 설명을 추가하자면 소프트웨어의 디자인 패턴의 구분은 

하나의 소프트웨어를 만들기 위해 개발자가 사고한 문제 해결 방식의 종류라고 볼 수 있을 것 같습니다.


소프트웨어 디자인 패턴의 구분

소프트웨어는 개발된 ‘목적’에 따라서 ‘생성’, ‘구조’, ‘행위’, ‘동시성’ 패턴으로 구분할 수 있습니다.

구분 설명
생성 패턴(Creational patterns) 객체 생성의 메커니즘을 다루는 디자인 패턴
구조적 패턴(Structural patterns) 엔티티(Entity) 간의 관계를 실현하는 간단한 방법을 식별하여 소프트웨어 설계를 쉽게 만드는 디자인 패턴
행위 패턴(Behavioral patterns) 객체 간의 일반적인 통신 패턴(common communication patterns)을 식별하는 방식의 디자인 패턴
동시성 패턴(Concurrency Patterns) 멀티 스레드 프로그래밍(Multi Thread Programming)의 패러다임(paradigm)을 위한 디자인 패턴 유형

 

그리고 이러한 소프트웨어의 디자인 패턴은 각각 자신의 타입으로 분류되는 다양한 디자인 패턴들이 존재합니다.


생성 패턴(Creational patterns)

  • 객체 생성의 메커니즘을 다루는 디자인 패턴
  • 프로그램에서 필요로하는 여러 상황에 대응하여 더 적합한 방식으로 객체(Object)를 생성하도록 지향하는 디자인 패턴 유형.
  • 객체 생성의 기본 골격은 프로그램에서 설계(디자인, Design)로 인한 문제를 일으키거나 구성의 복잡성을 가미시킬 수 있음.
  • 따라서, 생성 패턴은 이러한 문제 상황을 해결하고자 객체의 생성을 제어(Control)하여 문제를 해결할 수 있도록 함.

 

추상 팩토리(Abstract factory)

  • 구체적인 클래스에 의존하지 않고 서로 연관되거나 의존적인 객체들의 조합을 만드는 인터페이스를 제공하는 패턴
  • 이 패턴을 통해 생성된 클래스에서는 사용자에게 인터페이스(API)를 제공하고, 구체적인 구현은 Con-Create Product 클래스에서 이루어지게 하는 특징을 갖는 디자인패턴
  • Provide an interface for creating families of related or dependent objects without specifying their concrete classes.

 

빌더(Builder)

  • 복잡한 인스턴스를 조립하여 만드는 구조로, 복합 객체를 생성할 때 객체를 생성하는 방법(과정)과 객체를 구현(표현)하는 방법을 분리함으로써 동일한 생성 절차에서 서로 다른 표현 결과를 만들 수 있는 디자인 패턴
  • 생성과 표기를 분리해서 복잡한 객체를 생성
  • Separate the construction of a complex object from its representation, allowing the same construction process to create various representations.

 

의존성 주입(Dependency Injection)

  • 직접 클래스를 생성하는 대신 그것을 필요로하는 객체에서 인젝터(Injector)를 통해 필요한 객체를 허용하는 방식
  • A class accepts the objects it requires from an injector instead of creating the objects directly.

 

팩토리 메서드(Factory method)

  • 상위 클래스에서 객체를 생성하는 인터페이스를 정의하고, 하위 클래스에서 인스턴스를 생성하도록 하는 방식으로, 상위 클래스에서는 인스턴스를 생성하도록 하는 방식
  • 상위 클래스에서는 인스턴스를 만드는 방법만 결정하고, 하위 클래스에서 그 데이터의 생성을 책임지고 조작하는 함수들을 오버라이딩 하여 인터페이스와 실제 객체를 생성하는 클래스를 분리할 수 있는 특성을 갖는 디자인 패턴
  • 생성할 객체의 클래스를 구한하지 않고 객체를 생성함
  • Define an interface for creating a single object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.

 

지연 초기화(Lazy initialization)

  • 객체의 생성, 계산 과 같이 비용이 많이 드는 프로세스에 대해서 그 작업이 필요로하는 시점까지 지연시키는 디자인 패턴.
  • 프록시 패턴의 구현 전략 중 하나인 가상 프록시(Virtual Proxy)를 통해서 실현되는 기술
  • Tactic of delaying the creation of an object, the calculation of a value, or some other expensive process until the first time it is needed. 
  • This pattern appears in the GoF catalog as "virtual proxy", an implementation strategy for the Proxy pattern.

 

멀티톤(Multiton)

  • 클래스에 명명된 인스턴스가 있는지 확인하고 이 인스턴에스 접근하기 위한 전역 액세스 포인트를 제공하는 디자인 패턴
  • Ensure a class has only named instances, and provide a global point of access to them.

 

객체 풀(Object pool)

  • 자원의 획득과 해제에 비싼 비용이 드는 작업을 수행하는 것을 더이상 사용하지 않는 객체의 재활용을 통해서 피하는 방법.
  • 데이터 베이스(DB, Database)의 커넥션 풀(Connection Pool)과 스레드 풀(Thread Pool)의 일반화된 형태로 간주할 수 있는 유형
  • Avoid expensive acquisition and release of resources by recycling objects that are no longer in use. 
  • Can be considered a generalisation of connection pool and thread pool patterns.

 

프로토타입(Prototype)

  • 처음부터 일반적인 원형을 만들어 놓고, 그것을 복사한 후 필요한 부분만 수정하여 사용하는 패턴.
  • 생성할 객체의 원형을 제공하는 인스턴스에서 생성할 객체들의 타입이 결정되도록 설정하여 객체를 생성할 떄 갖추어야할 기본 형태가 있을 때 사용 되는 디자인 패턴
  • 기존 객체를 복제함으로써 객체를 생성하는 디자인 패턴.
  • Specify the kinds of objects to create using a prototypical instance, and create new objects from the 'skeleton' of an existing object, thus boosting performance and keeping memory footprints to a minimum.

 

RAII(Resource acquisition is initialization)

  • 자원의 관리에 대해서 ‘생명 주기’를 갖는 특정한 객체에 연관 시켜 자원의 해제에 대해서 확실하게 관리될 수 있도록 하는 디자인 패턴
  • 안드로이드(Android) 프로그래밍에서 뷰모델(ViewModel)의 생명주기를 관리하기 위한 Provider 클래스 등
  • Ensure that resources are properly released by tying them to the lifespan of suitable objects.

 

싱글턴(Singleton)

  • 객체를 단 하나만 생성하고 공유하게 하는 디자인 패턴
  • 전역 변수를 사용하지 않고 객체를 하나만 생성하여 다른 클래스에서 참조하여 사용할 수 있도록 하는 디자인 패턴
  • Ensure a class has only one instance, and provide a global point of access to it.

구조적 패턴(Structural patterns)

  • 엔티티(Entity) 간의 관계를 실현하는 간단한 방법을 식별하여 소프트웨어 설계를 쉽게 만드는 디자인 패턴.

 

 

어댑터(Adapter, Wrapper, or Translator)

  • 기존에 생성된 클래스를 재 사용할 수 있도록 중간에서 맞춰주는 역할을 하는 인터페이스를 만드는 패턴.
  • 상속을 이용하는 클래스 패턴과 위임을 이용하는 인스턴스 패턴의 두 가지 형태로 사용 되는 디자인 패턴
  • 인터페이스가 호환되지 않는 클래스들을 함께 이용할 수 있도록 타 클래스의 인터페이스를 기존 인터페이스에 덧씌움
  • Convert the interface of a class into another interface clients expect. 
  • An adapter lets classes work together that could not otherwise because of incompatible interfaces. 
  • The enterprise integration pattern equivalent is the translator.

 

브릿지(Bridge)

  • 기능의 클래스 계층과 구현의 클래스 계층을 연결하고, 구현부에서 추상 계층을 분리하여 추상화된 부분과 실제 구현 부분을 독립적으로 확장할 수 있는 디자인 패턴
  • 구현 뿐만 아니라, 추상화된 부분까지 변경해야 하는 경우 활용.
  • Decouple an abstraction from its implementation allowing the two to vary independently.

 

컴포지트(Composite)

  • 객체들의 관계를 트리 구조로 구성하여 부분-전체 계층을 표현하는 패턴으로, 사용자가 단일 객체와 복합 객체 모두 동일하게 다루도록 하는 패턴
  • 복합 객체와 단일 객체를 동일하게 취급
  • Compose objects into tree structures to represent part-whole hierarchies. 
  • Composite lets clients treat individual objects and compositions of objects uniformly.

 

데코레이터(Decorator)

  • 기존에 구현되어 있는 클래스에 필요한 기능을 추가해 나가는 설계 패턴으로 기능 확장이 필요할 때 객체 간의 결합을 통해 기능을 동적으로 유연하게 확장할 수 있도록 해주어 상속의 대안으로 사용하는 디자인 패턴
  • 객체의 결합을 통하여 기능을 동적으로 유연하게 확장함
  • Attach additional responsibilities to an object dynamically keeping the same interface. 
  • Decorators provide a flexible alternative to subclassing for extending functionality.

 

위임(Delegation)

  • 하위 클래스를 생성하는 것 대신에 클래스의 합성을 통해서 확장을 하는 디자인 패턴.
  • 객체는 요청을 두 번째 객체(Second Object, The Delegate)를 통해서 요청을 위임해 처리함.
  • Extend a class by composition instead of subclassing. The object handles a request by delegating to a second object (the delegate)

 

확장 객체(Extension object)

  • 계층 구조를 변경하지 않고 계층 구조에 기능을 추가하는 전략의 디자인 패턴
  • 마틴 로버트의 Agile Software Development, Principles, Patterns, and Practices 에서 소개된 방식
  • Adding functionality to a hierarchy without changing the hierarchy.

 

Facade

  • 복잡한 시스템에 대하여 단순한 인터페이스를 제공함으로써 사용자와 시스템 간 또는 여타 시스템과의 결합도를 낮추어 시스템의 구조에 대한 파악을 쉽게하는 패턴
  • 오류에 대해서 단위별로 확인할 수 있게 하며, 사용자의 측면에서 단순한 인터페이스의 제공을 통해 접근성을 높일 수 있는 디자인 패턴.
  • 통합된 인터페이스를 제공하는 것이 특징
  • Provide a unified interface to a set of interfaces in a subsystem. 
  • Facade defines a higher-level interface that makes the subsystem easier to use.

 

Flyweight

  • 다수의 객체로 생성될 경우 모두가 갖는 본질적인 요소를 클래스화하여 공유 함으로써 메모리를 절약하고 ‘클래스의 경량화’를 목적으로 하는 디자인 패턴
  • 여러 개의 ‘가상 인스턴스’를 제공하여 메모리 절감
  • Use sharing to support large numbers of similar objects efficiently.

 

Front controller

  • 웹 어플리케이션의 디자인과 관련 있는 디자인 패턴,
  • 요청에 대한 처리를 위해 중앙 집중적 진입점을 제공하는 디자인 패턴.
  • 웹 어플리케이션에서 MVC 디자인 패턴과 연관지어 사용자의 요청을 받는 컨트롤러 부분에서 많이 채택 되는 디자인 패턴
  • The pattern relates to the design of Web applications. It provides a centralized entry point for handling requests.

 

마커(Marker)

  • 메타 데이터와 클래스를 연결하는 빈 인터페이스
  • Empty interface to associate metadata with a class.

 

모듈(Module)

  • 전역적으로 사용되는 클래스, 싱글턴 인스턴스, 메서드 등 여러 요소들을 하나의 개념화 된 엔티티로 그룹화하는 디자인 패턴
  • Group several related elements, such as classes, singletons, methods, globally used, into a single conceptual entity.

 

프록시(Proxy)

  • ‘실체 객체에 대한 대리 객체’로 실체 객체에 대한 접근 이전에 필요한 행동을 취할 수 있도록 만드는 디자인 패턴
  • 이점을 활용해서 미리 할당하지 않아도 상관없는 것들에 대해 실제 이용할 때 할당하게 하여 메모리 용량을 아낄 수 있으며, 실제 객체를 드러나지 않게 하여 정보 은닉의 역할도 수행하는 디자인 패턴
  • 특정 객체로의 접근을 유도하기 위한 용도로 사용
  • Provide a surrogate or placeholder for another object to control access to it.

 

트윈(Twin)

  • 다중 상속 모델링을 지원하지 않는 프로그래밍 언어에서 다중 상속 모델링이 가능하도록 지원하는 디자인 패턴
  • Twin allows modeling of multiple inheritance in programming languages that do not support this feature.

행위 패턴(Behavioral patterns)

  • 객체 간의 일반적인 통신 패턴(common communication patterns)을 식별하는 방식의 디자인 패턴
  • 프로그램 간의 통신에서 유연성을 증가시킴. (increase flexibility in carrying out communication)

 

Blackboard(칠판)

  • 서로 다른 데이터 소스를 결합하기 위한 인공지능 패턴
  • Artificial intelligence pattern for combining disparate sources of data

 

Chain of responsibility

  • 정적으로 어떤 기능에 대한 처리의 연결이 하드 코딩 되어 있을 때 기능 처리의 연결 변경이 불가능하다.
  • 이를 동적으로 연결되어 있는 경우에 따라 다르게 처리될 수 있도록 연결한 디자인 패턴
  • 한 요청을 2개 이상의 객체에서 처리함.
  • Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. 
  • Chain the receiving objects and pass the request along the chain until an object handles it.

 

커멘드(Command)

  • 실행될 기능을 캡슐화함으로써 주어진 여러 기능을 실행할 수 있는 재사용성이 높은 클래스를 설계하는 패턴
  • 하나의 추상 클래스에 메서드를 만들어 각 명령이 들어오면 그에 맞는 서브클래스가 선택되어 실행되는 특징을 갖는 디자인 패턴
  • 요구사항을 객체로 캡슐화 함.
  • Encapsulate a request as an object, thereby allowing for the parameterization of clients with different requests, and the queuing or logging of requests. 
  • It also allows for the support of undoable operations.

 

Fluent interface

  • 도메인 특화 언어(DSL, Domain-Specific Languages)처럼 읽혀지도록 API를 메서드 체인으로 설계하는 디자인 패턴
  • 각 메서드 호출은 다음 논리적 메서드 호출을 사용할 수 있도록 컨텍스트(*Context)를 반환하는 방식
  • Design an API to be method chained so that it reads like a DSL.
  • Each method call returns a context through which the next logical method call(s) are made available.

*Context : 어떤 작업을 하기 위해 필요로 하는 환경 정보

 

인터프리터(Interpreter)

  • 어떤 프로그래밍 언어가 주어지면 해당 언어의 문장(sentences)을 해석하기 위한 인터프리터(통역사, Interpreter)와 함께 해당 문법에 대한 표현을 정의하는 방식의 디자인 패턴
  • Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.

 

반복자(Iterator)

  • 컬렉션 구현 방법을 노출 시키지 않으면서도 그 집합체 안에 들어있는 모든 항목에 접근할 방법을 제공하는 디자인 패턴
  • 내부 구조를 노출하지 않고, 복잡한 객체의 원소를 순차적으로 접근 가능하게 해주는 행위 패턴
  • Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.

 

중재자(Mediator)

  • 객체의 집합(set)이 상호 작용하는 방식을 캡슐화하는 객체를 정의하는 디자인 패턴
  • 객체가 서로 명시적으로 참조하는 것을 방지하여 느슨한 결합(loose coupling)을 할 수 있도록 촉진해서 궁극적으로 객체 간의 상호작용이 독립적이 될 수 있도록 함. 
  • Define an object that encapsulates how a set of objects interact. 
  • Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it allows their interaction to vary independently.

 

메멘토(Memento)

  • 객체지향 프로그래밍에서 캡슐화(encapsulation)를 위반하지 않는 선에서 내부 상태를 기억해두고 외부로 노출시켜서 나중에 객체를 동일한 상태로 복원할 수 있도록 하는 디자인 패턴
  • 클래스 설계 관점에서 객체의 정보를 저장할 필요가 있을 때 적용하는 디자인 패턴으로 Undo 기능을 개발할 때 사용하는 디자인 패턴
  • 객체를 이전 상태로 복구시켜야 하는 경우 작업취소(Undo) 요청 가능
  • Without violating encapsulation, capture and externalize an object's internal state allowing the object to be restored to this state later.

 

Null object

  • 객체지향 프로그래밍 언어에서 널 참조(null references)를 방지하기 위해 기본 객체(default object)를 제공하는 방식의 디자인 패턴
  • 대표적으로 코틀린(Kotlin)과 같은 언어에서 널 참조 안정성(Null safety)를 지원하기 위한 방법으로 제공하고 있는 기술
  • Avoid null references by providing a default object.

 

옵저버(Observer or Publish/subscribe)

  • 한 객체의 상태가 바뀌면 그 객체에 의존하는 다른 객체들에 연락이 가고 자동으로 내용이 갱신되는 방법으로 일대 다의 의존성을 가지며 상호작용하는 객체 사이에서는 가능하면 느슨하게 결합하는 디자인 패턴
  • 객체의 상태 변화에 따라 다른 객체의 상태도 연동, 일대다 의존성을 가짐
  • Define a one-to-many dependency between objects where a state change in one object results in all its dependents being notified and updated automatically.

 

서번트(Servant)

  • 클래스 그룹에 대한 공통적인 기능을 정의하는 디자인 패턴
  • 서번트 패턴은 주어진 객체의 집합에 대하여 헬퍼(Helper) 클래스나 유틸리티(Utility) 클래스의 구현이라고도 불림.
  • 핼퍼(Helper) 클래스는 일반적으로 객체가 없으므로 다양한 종류의 클래스 객체에 대해서 동작할 수 있는 정적(static) 메서드가 있음.
  • Define common functionality for a group of classes. 
  • The servant pattern is also frequently called helper class or utility class implementation for a given set of classes. 
  • The helper classes generally have no objects hence they have all static methods that act upon different kinds of class objects.

 

Specification

  • 어떤 불리언(Boolean) 값을 기준으로 비즈니스 로직의 재조합(recombinable) 여부를 결정하는 방식의 디자인 패턴
  • Recombinable business logic in a Boolean fashion.

 

상태(State)

  • 객체 상태를 캡슐화하여 클래스화 함으로써 그것을 참조하게 하는 방식의 디자인 패턴
  • 객체의 상태에 따라 다르게 처리할 수 있도록 행위 내용을 변경하는 방식
  • 변경 시 원시 코드의 수정을 최소화할 수 있고, 유지보수의 편의성도 갖는 디자인 패턴
  • 객체의 상태에 따라 행위 내용을 변경함
  • Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.

 

Strategy

  • 알고리즘 군을 정의하고(추상 클래스) 같은 알고리즘을 각각 하나의 클래스로 캡슐화한 다음, 필요할 때 서로 교환해서 사용할 수 있게 하는 디자인 패턴
  • 행위를 클래스로 캡슐화 하여 동적으로 행위를 자유롭게 바꿀 수 있도록 함.
  • 행위 객체를 클래스로 캡슐화 하여 동적으로 행위를 자유롭게 변환함.
  • Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

 

Template Method

  • 어떤 작업을 처리하는 일부분을 서브 클래스로 캡슐화해 전체 일을 수행하는 구조는 바꾸지 않으면서 특정 단계에서 수행하는 내역을 바꾸는 패턴으로 일반적으로 상위 클래스(추상 클래스)에는 추상 메서드를 통해 기능의 골격을 제공하고, 하위 클래스(구체 클래스)의 메서드에는 세부 처리를 구체화하는 방식으로 사용하며 코드 양을 줄이고 유지보수를 용이하게 만드는 특징을 갖는 디자인 패턴
  • 상위 작업의 구조를 바꾸지 않으면서 서브 클래스로 작업의 일부분을 수행
  • Template method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.

 

Visitor

  • 각 클래스 데이터의 구조로 부터 처리 기능을 분리하여 별도의 클래스를 만든 후 해당 클래스의 메서드가 각 클래스를 돌아다니며 특정 작업을 수행하도록 만드는 디자인 패턴
  • 객체의 구조는 변경하지 않으면서 기능만 따로 추가하거나 확장할 때 사용하는 디자인 패턴
  • 특정 구조를 이루는 복합 객체의 원소 특성에 따라 동작을 수행할 수 있도록 지원하는 행위
  • Represent an operation to be performed on instances of a set of classes. Visitor lets a new operation be defined without changing the classes of the elements on which it operates.

동시성 패턴(Concurrency patterns)

  • 소프트웨어 공학(Software Engineering)에서 멀티 스레드 프로그래밍(Multi Thread Programming)의 패러다임(paradigm)을 위한 디자인 패턴 유형

 

Active Object

  • 자체 제어 스레드에 있는 메서드의 호출에서 메서드의 실행을 분리하는 방식의 디자인 패턴.
  • 비동기 메스드의 호출과 요청 처리를 위한 스케줄러를 사용해서 동시성을 도입할 수 있도록 목적하는 디자인 패턴
  • Decouples method execution from method invocation that reside in their own thread of control. 
  • The goal is to introduce concurrency, by using asynchronous method invocation and a scheduler for handling requests.

 

Balking

  • 객체가 특정 상태에 놓였을 때에만 특정 작업을 수행할 수 있도록 설계하는 디자인 패턴
  • Only execute an action on an object when the object is in a particular state.

 

Binding properties

  • 여러 관찰자를 결합하여 서로 다른 객체의 속성을 어떤 방식으로든 동기화 시키거나 조정할 수 있도록 하는 디자인 패턴
  • Combining multiple observers to force properties in different objects to be synchronized or coordinated in some way.

 

Compute kernel

  • GPU 최적화 매트릭스(Matrix) 곱셈 연산 또는 합성곱 신경망(CNN, Convolutional neural network)과 같은 공유 배열에 대한 비분기(non-branching) 포인터 연산과 함께 사용될 정수(Integer) 매개 변수에 대해서 동일한 계산이 병렬로 여러번 수행될 수 있도록하는 디자인 패턴
  • The same calculation many times in parallel, differing by integer parameters used with non-branching pointer math into shared arrays, such as GPU-optimized Matrix multiplication or Convolutional neural network.

 

Double-checked locking

  • 잠김(locking)의 기준인 ‘lock hint’를 안전하지 않는 방식으로 테스트하여 잠김 할당에 대한 오버헤드(overhead)를 줄일 수 있도록 설계된 디자인 패턴
  • 성공하는 경우에만 실제 잠김(locking) 로직 프로세스가 수행됨.
  • 일부 프로그래밍 언어와 하드웨어의 조합에서 구현할 경우 안전하지 않을 수 있기 때문에, 때로는 안티 디자인 패턴(anti-pattern)으로 간주될 수 있는 유형.
  • Reduce the overhead of acquiring a lock by first testing the locking criterion (the 'lock hint') in an unsafe manner; only if that succeeds does the actual locking logic proceed.
  • Can be unsafe when implemented in some language/hardware combinations. It can therefore sometimes be considered an anti-pattern.

 

Event-based asynchronous

  • 멀티 스레드(multithreaded) 환경에서의 비동기 문제를 해결하기 위하여 고안된 디자인 패턴
  • Addresses problems with the asynchronous pattern that occur in multithreaded programs.

 

Guarded suspension

  • 작업을 실행하기 전에 잠김(locking)을 획득한 후 전제 조건을 충족해야하는 작업에 대해 관리하는 방식의 디자인 패턴
  • Manages operations that require both a lock to be acquired and a precondition to be satisfied before the operation can be executed.

 

Join

  • 메세지 전달(message passing)을 통해 동시성(concurrency), 병렬(parallel), 분산(Dispersion) 프로그램 환경에서 프로그램을 작성하는 방법을 제공하는 디자인 패턴
  • 스레드(thread)나 잠김(locking)과 비교하면 고급 프로그래밍 모델에 속하는 방식.
  • Join-pattern provides a way to write concurrent, parallel and distributed programs by message passing. 
  • Compared to the use of threads and locks, this is a high-level programming model.

 

Lock

  • 스레드가 ‘잠금(lock)’을 통해서 다른 스레드에서 해당 리소스에 대한 접근이나 수정을 못하도록 방지하는 방식의 디자인 패턴
  • One thread puts a "lock" on a resource, preventing other threads from accessing or modifying it.

 

MDP (Messaging design pattern)

  • 메세지(‘message’)와 같은 매개체를 통해서 정보의 교환을 가능하게 하는 디자인 패턴.
  • 애플리케이션과 컴포넌트 간의 정보 교환에 활용됨.
  • Allows the interchange of information (i.e. messages) between components and applications.

 

Monitor object

  • 매서드가 상호 배제되는 객체로, 여러 객체가 동시에 해당 메서드를 사용하는 실수를 방지하는 디자인 패턴.
  • 가령 A 메서드와 B메서드가 상호 배제 관계라면, A 메서드를 사용중에는 B 메서드를 사용할 수 없는 일종의 억제 작용을 함.
  • An object whose methods are subject to mutual exclusion, thus preventing multiple objects from erroneously trying to use it at the same time.

 

Reactor

  • 리액터 객체(reactor object)라는 것을 통해 동기적으로(synchronously) 처리되어야 하는 자원(resources)에 대하여 비동기적인(asynchronous) 인터페이스를 제공하는 방식의 디자인 패턴
  • A reactor object provides an asynchronous interface to resources that must be handled synchronously.

 

Read-write lock

  • 객체에 대한 동시 읽기 액세스(concurrent read access)를 허용하지만 쓰기(write) 작업에 대해서는 단독 액세스를 필요로 하는 방식의 디자인 패턴.
  • 기본 적으로 세마포어(semaphore)는 쓰기에 사용될 수 있으며, 쓰기 작업 중의 복사 메커니즘은 사용 되거나 사용 되지 않을 수 있음.
  • Allows concurrent read access to an object, but requires exclusive access for write operations. 
  • An underlying semaphore might be used for writing, and a Copy-on-write mechanism may or may not be used.

 

스케줄러(Scheduler)

  • 스레드(thread)가 단일 스레드 코드를 실행할 수 있는 시기를 명시적으로 제어하는 것을 지원하는 방식의 디자인 패턴
  • 안드로이드(Android) 프로그래밍에서 UI 스레드 내에서 특정 작업을 필요로 하는 경우
  • Explicitly control when threads may execute single-threaded code.

 

Service handler pattern

  • 각 요청에 대하여 서버는 요청을 처리하기 위한 전용 클라이언트 핸들러(dedicated client handler)를 생성하는 방식의 디자인 패턴.
  • 새션 당 스레드(thread-per-session)라고도 불림.
  • For each request, a server spawns a dedicated client handler to handle a request.
  • Also referred to as thread-per-session.

 

스레드 풀(Thread pool)

  • 특정 작업을 수행하기 위해 스레드를 미리 생성해두고 이를 활용하여 요청에 대한 처리를 할 수 있도록 하는 방식의 디자인 패턴
  • 일반적으로 대기열(queue)에 존재하는 여러 작업을 수행하기 위해서는 여러 스레드가 생성되는데,
  • 보편적으로 스레드의 개수보다는 작업의 개수가 더 많은 양적 불균형이 존재함.
  • 따라서, 이러한 양적 불균형을 해소하고 컴퓨터 자원의 효율적인 사용을 위해 미리 작업을 위한 일종의 ‘도구’를 미리 생성해두어 대응하는 방식
  • 객체 플 패턴(Object Pool Pattern)의 특별한 경우로 간주되기도 함.
  • A number of threads are created to perform a number of tasks, which are usually organized in a queue. 
  • Typically, there are many more tasks than threads. Can be considered a special case of the object pool pattern.

 

Thread-specific storage

  • 스레드 수준에서 지역성(local)을 갖는 정적(static) 또는 전역(global) 메모리를 사용하는 방식의 디자인 패턴
  • Static or "global" memory local to a thread.

 

소유권 독점을 통한 동시성 안정성 (Safe Concurrency with Exclusive Ownership)

  • 독점 소유권을 보장하므로 런타임(runtime) 시에 동시성을 위한 메커니즘(concurrent mechanisms)을 필요로 하지 않는 디자인 패턴.
  • RUST라는 언어의 특징적인 기능이나, 이 언어의 컴파일 순간에만 종속되어 독점 소유권을 보장하는 것은 아님.
  • 프로그래머는 종종 필요에 따라 소유권 독점에 대한 패턴을 직접 코드로 설계하는데, 이 때문에 주어진 변수에  대해서 절대 동시적으로 접근되지 않음을 신뢰할 수 있고,  따라서 동시성 제어를 위한 잠김(locking) 메커니즘 사용을 생략할 수 있음.
  • Avoiding the need for runtime concurrent mechanisms, because exclusive ownership can be proven. 
  • This is a notable capability of the Rust language, but compile-time checking isn't the only means, a programmer will often manually design such patterns into code - omitting the use of locking mechanism because the programmer assesses that a given variable is never going to be concurrently accessed.

 

CPU atomic operation

  • x86을 포함한 기타 중앙 처리 장치(CPU) 아키텍처에서  기본 값(Integer)을 수정하고 액세스 하기 위한 메모리 안정성을 보장하는 다양한 종류의 원자성 명령어(atomic operation)를 지원하는 디자인 패턴.
  • 예를 들어 동시성 제어에서 많이 채택되는 카운터(Counter) 프로그램의 경우에도 병렬 스레드로 카운트를 처리하더라도 모두 안전하게 카운트 계수를 안전하기 증산 할 수 있음.
  • 이러한 기능은 위에서 소개된 다른 동시성 패턴에서 필요로하는 매커니즘을 구현하는데에도 활용될 수 있음.
  • 예를 들어, C#에서는 이러한 기능을 지원하기 위해 Interlocked 클래스를 사용함.
  • x86 and other CPU architectures support a range of atomic instructions that guarantee memory safety for modifying and accessing primitive values (integers). 
  • For example, two threads may both increment a counter safely. 
  • These capabilities can also be used to implement the mechanisms for other concurrency patterns as above. 
  • The C# language uses the Interlocked class for these capabilities.

참고자료

https://en.wikipedia.org/wiki/Software_design_pattern

 

Software design pattern - Wikipedia

From Wikipedia, the free encyclopedia Reusable solution to a commonly occurring software problem In software engineering, a software design pattern is a general, reusable solution to a commonly occurring problem within a given context in software design. I

en.wikipedia.org

https://en.wikipedia.org/wiki/Creational_pattern

 

Creational pattern - Wikipedia

From Wikipedia, the free encyclopedia Software design pattern dealing with object creation In software engineering, creational design patterns are design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to t

en.wikipedia.org

https://en.wikipedia.org/wiki/Structural_pattern

 

Structural pattern - Wikipedia

From Wikipedia, the free encyclopedia

en.wikipedia.org

https://en.wikipedia.org/wiki/Behavioral_pattern

 

Behavioral pattern - Wikipedia

From Wikipedia, the free encyclopedia Type of software design pattern In software engineering, behavioral design patterns are design patterns that identify common communication patterns among objects. By doing so, these patterns increase flexibility in car

en.wikipedia.org

https://en.wikipedia.org/wiki/Concurrency_pattern

 

Concurrency pattern - Wikipedia

From Wikipedia, the free encyclopedia

en.wikipedia.org