👨‍💻
Software Engineering
Implementing Domain Driven Design
Implementing Domain Driven Design
  • Intro
  • 1. Getting Started with DDD
    • The Business Value of DDD
  • 4: Architecture
  • 5: Entities
    • Why We Use Entities
    • Unique Identity
  • 6: Value Objects
    • Value Object Characteristics
    • Integrate with Minimalism
    • Standard Types Expressed as Values
    • Resources
  • 10: Aggregates
  • 8: Domain Events
    • The When & Why of Domain Events
    • Modeling Events
    • Publishing Events from the Domain Model
  • 13: Factories
  • Resources
Powered by GitBook
On this page
  • Value Objects
  • Identity Creation Strategies
  • User Provides Identity
  • Application Generates Identity
  • Persistence Mechanism Generates Identity
  • Another Bounded Context Assigns Identity
  1. 5: Entities

Unique Identity

Value Objects

  • Value Objects can serve as holders of unique identity.

  • They are immutable which ensures identity stability and centralize any behavior.

  • They also provide the benefit of being a Strongly Typed Identifier.

Identity Creation Strategies

User Provides Identity

  • A simple approach with complications.

  • Can users be relied upon to produce both unique and correct, long-lasting identifies?

  • We always have the option of user-provided values as Entity properties available for matching but NOT used for unique identity.

Application Generates Identity

  • Highly reliable

  • A GUID or UUID is a common approach to identity creation that can produce a completely unique identity.

  • We don't normally want to display a UUID in a UI. UUID is appropriate when it can be hidden from users and human-readable reference techniques can be used.

  • Parts of a the generated UUID can be used with other attributes to generate a human-readable identifier.

    • TIP: Encapsulate this logic in a custom identity Value Object.

Persistence Mechanism Generates Identity

  • Provides unique advantages

  • Calling the database for a sequence or incrementing value ensures uniqueness.

  • Downside: Performance

    • Takes longer to go to the database to get each value vs. an application-generated Identity.

    • Can potentially be mitigated through caching, but that requires more implementation and potential gaps between identities.

Another Bounded Context Assigns Identity

  • An exact match between the local Entity and the remote Entity is the most desirable.

  • If the local context uses state from the remote context, we need to synchronize.

    • This is solved using Event Driven Architecture + Domain Events.

    • This leads to more autonomous systems.

    • Important: This is not about caching foreign objects locally. Instead, it involves translating foreign concepts into those of the local Bounded Context.

    • Use this approach conservatively.

PreviousWhy We Use EntitiesNext6: Value Objects

Last updated 1 year ago