Skip to content

LiteObject/Demo.DDD.ValueObject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

DDD: What is a value object

A value object is a small object that represents a simple entity whose equality is not based on identity: i.e. two value objects are equal when they have the same value, not necessarily being the same object.

Two important characteristics of value objects

  • They have no identity
  • They are immutable

    Immutability is an important requirement. The values of a value object must be immutable once the object is created. Therefore, when the object is constructed, you must provide the required values, but you must not allow them to change during the object's lifetime.


In C# 9, you can create a value object using record type

public record Phone
{
    // init makes is immutable
    public string Number { get; init; }
    public string Type { get; init; }

    public Phone(string Number, string Type)
    {
        this.Number = Number;
        this.Type = Type;
    }
}

...

// Using public auto-implemented properties
public record Phone(string Number, string Type)

Links:

Releases

No releases published

Packages

No packages published

Languages