헥사고날 아키텍처(Hexagonal Architecture) 란?
우선, 간단하게 위키피디아에서 어떻게 헥사고날 아키텍처(Hexagonal Architecture)에 대해 설명하고 있는지 살펴보는 것이 좋을 것 같아 작성하게 되었습니다.
헥사고날 아키텍처(Hexagonal Architecture) 란?
The hexagonal architecture, or ports and adapters architecture, is an architectural pattern used in software design. It aims at creating loosely coupled application components that can be easily connected to their software environment by means of ports and adapters. This makes components exchangeable at any level and facilitates test automation.
헥사고날 아키텍처 혹은 포트&어댑터 구조는 소프트웨어 디자인에서 사용되는 아키텍처 패턴 이다. 포트와 어댑터를 통해 소프트웨어 환경에 쉽게 연결될 수 있는 느슨하게 결합된 애플리케이션 구성요소들을 만드는 것을 목표로 한다. 이것은 어떤 레벨에서든지 구성요소들을 교환가능하게 만들어주고, 테스트 자동화를 용이하게 만들어준다.
잠깐, 아키텍처 패턴이란?
An architectural pattern is a general, reusable solution to a commonly occurring problem in software architecture within a given context. The architectural patterns address various issues in software engineering, such as computer hardware performance limitations, high availability and minimization of a business risk.
아키텍처 패턴은 소프트웨어 아키텍처에서 공통적으로 일어나는 문제에 대한 일반적이고 재사용가능한 솔루션이다. 아키텍처 패턴들은 컴퓨터 하드웨어 성능 제한, 고가용성 그리고 비즈니스적 위험의 최소화와 같은 소프트웨어 엔지니어링에서 다양한 이슈들을 다룬다.
탄생 배경
The hexagonal architecture was invented by Alistair Cockburn in an attempt to avoid known structural pitfalls in object-oriented software design, such as undesired dependencies between layers and contamination of user interface code with business logic, and published in 2005.
The term "hexagonal" comes from the graphical conventions that shows the application component like a hexagonal cell. The purpose was not to suggest that there would be six borders/ports, but to leave enough space to represent the different interfaces needed between the component and the external world.
헥사고날 아키텍처는 계층 간의 원치않는 의존성 그리고 비즈니스 로직과 사용자 인터페이스 간의 오염과 같은 객체 지향 소프트웨어 디자인에서 잘 알려진 구조적인 함정들을 피하기 위한 시도에서 Alistair Cockburn에 의해 발명되었다. 그리고 2005년에 처음 발표된 개념이다.
이 'hexagonal(육각형)' 이라는 용어는 hexagonal cell(육방세포) 처럼 애플리케이션의 구성요소를 보여주는 그래프 규칙에서 유래되었다. 그 목적은 반드시 6개의 지점과 포트가 있을 거라고 제안하기 위함은 아니었고, 오히려 구성요소와 외부 세계 사이에 필요한 또다른 인터페이스들을 충분히 보여주도록 하기 위함이었다.
원칙
The hexagonal architecture divides a system into several loosely-coupled interchangeable components, such as the application core, the database, the user interface, test scripts and interfaces with other systems. This approach is an alternative to the traditional layered architecture.
헥사고날 아키텍처는 시스템을 애플리케이션 코어, 데이터베이스, 유저 인터페이스, 테스트 스크립트, 다른 시스템들과의 인터페이스와 같이 느슨하게 결합된 여러개의 상호 교환가능한 구성요소들로 나눈다. 그리고 이 접근법은 전통적인 계층 구조(layered architecture)의 대안이다.
Each component is connected to the others through a number of exposed "ports". Communication through these ports follow a given protocol depending on their purpose. Ports and protocols define an abstract API that can be implemented by any suitable technical means (e.g. method invocation in an object-oriented language, remote procedure calls, or Web services).
각 구성요소는 다수의 노출된 포트들에 의해 서로 연결된다. 이 포트들을 통한 커뮤니케이션은 그들의 목적에 따라 주어진 프로토콜(규칙)을 따른다. 포트와 프로토콜은 임의의 적절한 기술적 수단(객체 지향 언어에서의 메서드 호출, 원격 프로시저 호출 또는 웹 서비스 등)에 의해 구현될 수 있는 추상 API를 정의한다.
Adapters are the glue between components and the outside world. They tailor the exchanges between the external world and the ports that represent the requirements of the inside of the application component. There can be several adapters for one port, for example, data can be provided by a user through a GUI or a command-line interface, by an automated data source, or by test scripts.
어댑터는 구성요소와 외부 세계 간의 접착제다. 어댑터는 외부세계와 애플리케이션 구성요소의 내부 요구사항들을 대표하는 포트들 간의 교환을 맞춤화한다. 예를 들어, 한개의 포트에 대해서도 여러개의 어댑터들이 존재할 수 있는데, 예를 들면 데이터는 사용자에 의해서 GUI, 명령줄 인터페이스, 자동화된 데이터 소스 및 테스트 스크립트들에 의해 제공될 수 있다.
비판
According to Martin Fowler, the hexagonal architecture has the benefit of using similarities between presentation layer and data source layer to create symmetric components made of a core surrounded by interfaces, but with the drawback of hiding the inherent asymmetry between a service provider and a service consumer that would better be represented as layers.
마틴 파울러에 따르면, 헥사고날 아키텍처는 프레젠테이션 레이어(사용자 인터페이스, MVC 패턴에서 Controller / cf. Layered Architecture 참고)와 데이터 소스 레이어 사이의 유사성들을 이용해서 인터페이스에 둘러쌓인 핵심코어로 이루어진 대칭적인 구성요소들을 생성하는 것에 장점이 있지만, 반대로 레이어들로 더 잘 표현될 수 있는 서비스 프로바이더와 서비스 컨슈머 사이에 있는 본질적인 비대칭성을 숨겨버리는 단점을 갖고 있다. ( : 전통적인 아키텍처인 계층형 아키텍처의 특징이었다. 웹 계층은 도메인 계층을 의존하고, 도메인 계층은 영속성 계층을 의존하기 때문에, 서로 의존성이 비대칭적이다.)
발전
According to some authors, the hexagonal architecture is at the origin of the microservices architecture.
어떤 사람들은, 헥사고날 아키텍처가 마이크로서비스 아키텍처의 시작점에 있다고 말한다.