O'Reilly logo

Implementing Domain-Driven Design by Vaughn Vernon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Value Objects

As discussed thoroughly in Value Objects (6), this is a pattern that can greatly simplify development and the evolution of rich domain models. Using Value Objects, we compose cohesive primitive types into an explicitly named immutable type. For instance, instead of declaring the identity of a project as a long, we would model an explicit ProjectId:

public struct ProjectId {   public readonly long Id { get; private set; }   public ProjectId(long id)   {     Id = id   }   public override ToString() {     return string.Format("Project-{0}", Id);   } }

We still use a long type to hold the actual identity number, but we use the ProjectId type to distinguish it from all others. Value types are certainly ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required