PlantUML クラス図: ドメインモデリング
PlantUMLクラス図でDDDプロジェクト用のドメインモデルを作成。集約、エンティティ、値オブジェクト、ドメインイベントを適切なUML表記で定義。
Class Diagrams
詳細な説明
PlantUMLでのドメイン駆動設計モデル
ドメインモデリングはクラス図が最も力を発揮する分野です。PlantUMLのステレオタイプとパッケージ機能はDDD戦術パターンに直接マッピングされます。
集約の定義
@startuml
package "Order Aggregate" <<Rectangle>> {
class Order <<Aggregate Root>> {
-orderId: OrderId
-status: OrderStatus
-items: List<OrderItem>
+addItem(product, qty): void
+submit(): void
+cancel(): void
}
class OrderItem <<Entity>> {
-lineId: LineId
-productId: ProductId
-quantity: int
-unitPrice: Money
+subtotal(): Money
}
class Money <<Value Object>> {
-amount: BigDecimal
-currency: Currency
+add(other: Money): Money
}
Order *-- OrderItem
OrderItem *-- Money
}
@enduml
ステレオタイプ
<<Aggregate Root>>、<<Entity>>、<<Value Object>>、<<Domain Event>>ステレオタイプを使用してDDDビルディングブロックにラベルを付けます。
ドメインイベント
class OrderSubmitted <<Domain Event>> {
-orderId: OrderId
-submittedAt: DateTime
-totalAmount: Money
}
Order ..> OrderSubmitted : publishes
境界付きコンテキストの境界
package "Order Context" {
class Order
class OrderItem
}
package "Inventory Context" {
class Product
class StockLevel
}
Order ..> Product : IDのみで参照
パッケージ境界は境界付きコンテキストの分離を視覚化します。コンテキスト間の参照はIDのみを使用し、直接的なオブジェクト参照は使用しません。
カラーコーディング
skinparam class {
BackgroundColor<<Aggregate Root>> LightBlue
BackgroundColor<<Entity>> LightGreen
BackgroundColor<<Value Object>> LightYellow
}
DDDビルディングブロックをカラーコードすると、大きなドメインモデルがはるかにスキャンしやすくなります。
ユースケース
イベントストーミングワークショップでのドメインモデリングセッションの開始、マイクロサービス境界決定のための境界付きコンテキストのドキュメント、共有チーム語彙アーティファクトの作成、実装前の集約設計の検証。