聊聊Ports and Adapters architecture

本文主要研究一下Ports and Adapters architecturegit

Ports and Adapters architecture


Ports and Adapters architecture,又叫Hexagonal architecture,其中ports層是六邊形的邊界,其中port又能夠分爲driver port及driven port,簡單理解對應輸入層及輸出層;邊界保護的是內部的app,其中app包括use cases或者叫作application services層以及domain層;adapter能夠理解爲將外部依賴進行適配,實現port層定義的接口github

示例結構

github.com/albertllousas/implementing-hexagonal-architectureapp

├── app
│   ├── domain
│   │   ├── Account.kt
│   │   ├── Ids.kt
│   │   ├── Transaction.kt
│   │   └── Transfer.kt
│   ├── port
│   │   ├── driven
│   │   │   ├── AccountBalanceChecker.kt
│   │   │   ├── AccountFinder.kt
│   │   │   └── Transactor.kt
│   │   └── driver
│   │       └── TransferMoney.kt
│   └── usecase
│       └── TransferMoneyUseCase.kt
└── infrastructure
    ├── adapter
    │   ├── driven
    │   │   ├── InMemoryAccounts.kt
    │   │   └── InMemoryTransactions.kt
    │   └── driver
    │       └── ktor
    │           └── TransferHttpRoutes.kt
    └── config
        ├── ApplicationModule.kt
        └── ApplicationRunner.kt
port層這裏定義了driven及driver兩大類的接口,而後adapter層對應driven及driver這兩大類使用外部的服務進行實現;domain層定義了domain model以及相關領域方法;usecase或者是application service層則是編排

小結

Ports and Adapters architecture,又叫Hexagonal architecture,其中ports層是六邊形的邊界,其中port又能夠分爲driver port及driven port,簡單理解對應輸入層及輸出層;邊界保護的是內部的app,其中app包括use cases或者叫作application services層以及domain層;adapter能夠理解爲將外部依賴進行適配,實現port層定義的接口。dom

doc

相關文章
相關標籤/搜索