0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

軟體架構 - Helper 物件常用替代命名

Last updated at Posted at 2025-09-26
替代名稱 適用情境 範例 常見放置位置
Validator 驗證領域規則(domain invariants)、輸入資料檢查 OrderValidator 驗證訂單是否可建立 Domain Layer(domain/service 或 domain/validation)
Factory 建立複雜 Aggregate 或 Entity,避免建構子過重 OrderFactory 負責建立 Order 與關聯的 OrderLine Domain Layer(domain/factory)
Translator / Mapper 負責 DTO ↔ Entity ↔ Domain Object 轉換 OrderTranslatorUserMapper Application Layer(application/mapper 或 application/translator)
Converter 格式或型別轉換(非業務邏輯) CurrencyConverter Infrastructure Layer(infra/converter)
Assembler 將多個物件組裝成 DTO 或 ViewModel OrderDtoAssembler Application Layer(application/assembler)
Adapter 對接外部系統或 API PaymentGatewayAdapter Infrastructure Layer(infra/adapter)
Policy 表達可替換的業務規則 DiscountPolicy Domain Layer(domain/policy)
Specification 複雜查詢或條件的封裝 ActiveCustomerSpecification Domain Layer(domain/specification)
Strategy 行為可替換的演算法 ShippingCostStrategy Domain Layer(domain/strategy)
Service 跨 Aggregate 的領域操作,或應用服務邏輯 PaymentService Domain Service → Domain Layer / Application Service → Application Layer
src/main/java/com/example/project
│
├── domain
│   ├── model         # Aggregate, Entity, Value Object
│   ├── service       # Domain Service
│   ├── factory       # Factory
│   ├── validation    # Validator
│   ├── policy        # Policy
│   ├── specification # Specification
│   └── strategy      # Strategy
│
├── application
│   ├── service       # Application Service
│   ├── dto           # DTOs
│   ├── assembler     # Assembler
│   └── mapper        # Translator/Mapper
│
├── infrastructure
│   ├── repository    # Repository 實作
│   ├── adapter       # 外部服務對接
│   └── converter     # 基礎轉換器
│
└── interfaces
    ├── web           # Controller / REST API
    └── cli           # Command Line Interface
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?