บทที่ 26 · Part 5 — From Model to Running System
Anti-Corruption Layer and Published Language
แปล semantics ที่ boundary และออกแบบภาษาสาธารณะซึ่งมี owner, version และขอบเขตข้อมูลชัดเจน
Anti-Corruption Layer and Published Language
Provider A ใช้ captured, Provider B ใช้ completed และ internal team ใช้ posted หาก adapter
map ทั้งหมดเป็น SUCCESS ความแตกต่างระหว่าง execution กับ financial posting หาย Anti-Corruption
Layer ปกป้อง model ภายใน ส่วน Published Language ทำ contract ที่ผู้บริโภคพึ่งพาได้อย่างตั้งใจ
จบบทนี้คุณจะ
ออกแบบ semantic translation ที่ ACL แยก external/internal identity, lifecycle, Money และ failure สร้าง Published Language ที่ minimum, versioned และ owned ใช้มาตรฐานภายนอกเป็น contract input ไม่ใช่ canonical internal model
ACL แปล Meaning
ACL ใน DDD Reference สร้าง isolation layer ซึ่งแปล model ของอีก context เข้าสู่ model ของเรา
Translation table:
| External evidence | Internal outcome | ห้ามสรุป |
|---|---|---|
| request validated | RequestAccepted | funds moved |
| issuer decline | Declined | retryable transport failure |
| network timeout | Indeterminate | failed |
| provider capture | ExecutionAccepted | LedgerEntriesPosted |
| duplicate callback | Same observed fact | new business effect |
ACL รวม mapper, gateway, error classification, identifier/currency conversion และ contract tests
Identity Translation
เก็บ explicit mapping:
TransferIntentID
ExecutionAttemptID
ProviderAccountID
ProviderObjectID
IdempotencyKey
Correlation/Causation
อย่าเรียกทุกอัน transaction_id และอย่าสมมติ provider ID unique globally
ACL ไม่ได้เปลี่ยนเพียง field name แต่รักษาความแตกต่างของ evidence โดยเฉพาะ timeout ซึ่งห้าม map เป็น failed Published Language จึงเปิดเผย outcome ที่ context เจ้าของรับรองได้เท่านั้น
Published Language
ภาษาสาธารณะที่ออกแบบให้หลาย consumers เช่น API/event schema:
{
"eventType": "execution-outcome-established.v1",
"executionId": "exec_123",
"outcome": "INDETERMINATE",
"observedAt": "2026-08-11T10:05:00Z",
"sourceContractVersion": "provider-api-2026-06"
}
มันมี owner/version/deprecation/example และไม่ export internal Aggregate object
Standard เช่น ISO 20022
ISO 20022 Business Model และ catalogue เป็น Published Language ข้ามองค์กร แต่ version/message semantics ต้องแปลเข้า context เฉพาะ ไม่ดึง schema ทั้งหมดเป็น internal domain model
Data Classification และ Compliance
Published contract เปิดเผยเฉพาะ minimum necessary ตาม owner/policy ห้ามใส่ personal/card data เพราะสะดวกจาก internal object การใช้ standard/ACL ไม่ทำให้ compliant โดยอัตโนมัติ
Compatibility
กำหนด:
- additive vs breaking changes
- required/optional field semantics
- enum unknown handling
- schema/content version
- deprecation timeline และ consumer inventory
- replay/backfill behavior
Consumer ต้องไม่ crash เมื่อ enum ใหม่ถ้า contract กำหนด extensible
ACL Placement
ACL อาจอยู่:
- adapter ใน context consumer
- integration module ที่ consumer เป็นเจ้าของ
- gateway/service shared เมื่อหลาย contexts ต้อง translation เดียวและ governance คุ้ม
หลีกเลี่ยง central canonical model ที่กลายเป็น coupling hub
แบบฝึกปฏิบัติ: 2 Providers, 1 Language
สร้าง provider A/B contracts สมมติที่ lifecycle/error/idempotency ต่างกัน แล้วส่ง:
- mapping tables
- application-owned outcomes
- identity map
- unknown/duplicate/out-of-order rules
- Published Language v1 + compatibility policy
- data fields deliberately omitted
- contract test matrix
รายการตรวจสอบ
- ACL แปล semantics ไม่ใช่ rename
- Identity namespaces แยก
- Timeout/unknown ไม่ map failed
- Published Language minimum/owned/versioned
- Internal Aggregate ไม่ถูก export
- Standard/vendor model ไม่กลายเป็น canonical model
- Privacy/compatibility/deprecation ชัด
สรุปบทนี้
ACL รักษาความหมายของ context เมื่อคุยกับ model อื่น ส่วน Published Language ทำ semantics ที่ ตั้งใจเปิดเผยให้ stable ความสำเร็จไม่ได้อยู่ที่ schema เหมือนกัน แต่อยู่ที่ความแตกต่างถูกแปลและ contract evolve โดยไม่ทำ authority สูญหาย
อ่านเพิ่มเติม
- DDD Reference — ACL, Open Host Service, Published Language
- ISO 20022 Repository — external Published Language
- Stripe Advanced Error Handling — vendor-specific uncertain outcome