Modddels
HomeGithubPub.dev
v0.2
v0.2
  • Motivation
  • Setup
  • Generalities
    • Modddels Overview
    • Validations & Validation steps
    • Structure of a Modddel
    • Member parameters & Dependency parameters
    • Usage
      • Data equality & toString
      • Pattern matching
      • Reading the fields
      • Reading the failures
      • CopyWith
  • ValueObjects
    • ValueObjects Overview
    • Creating a ValueObject
  • Entities
    • Entities Overview
    • ContentValidation & ContentFailure
    • ValidationSteps in Entities
    • SimpleEntity
      • Creating a SimpleEntity
      • Special Cases
    • IterableEntity & Iterable2Entity
      • IterableEntity / Iterable2Entity kinds
      • The Type Template
      • Creating an IterableEntity / Iterable2Entity
      • InvalidMembers Description
      • Special Cases
      • Creating your own IterableEntity / Iterable2Entity kind
  • Advanced Notions
    • The NullFailure Annotation
    • Using multiple parameters annotations
    • Class Hierarchy of ValueObjects
    • Class Hierarchy of Entities
    • Models that are always valid / invalid
  • Union of Modddels
    • Union of Modddels Overview
    • Basic Usage
    • Case-modddels pattern matching
    • Default Factory Constructor
    • Shared Properties
    • The Validate Methods
    • CopyWith
  • Unit-Testing Of Modddels
    • Unit-Testing Overview
    • Available Tests
    • Customizing Tests
  • Additional Information
    • Using type aliases
    • Re-running the generator
    • All Available Modddels
    • VsCode Snippets
Powered by GitBook
On this page
  • What is a ValueObject ?
  • ValueObjects Kinds
  1. ValueObjects

ValueObjects Overview

PreviousCopyWithNextCreating a ValueObject

What is a ValueObject ?

a ValueObject is a modddel that holds a "value", which can be made up by one or multiple member parameters.

The "value" is validated by one or multiple validations, grouped in one or multiple validation steps. Each validation either passes successfully, or fails with a ValueFailure (subclass of Failure).

ValueObjects Kinds

There are two kinds of ValueObjects : SingleValueObject and MultiValueObject. The difference between the two is that SingleValueObject enforces having only one member parameter.

Generally, you'll want your ValueObjects to contain one field only, so you'll mostly be using SingleValueObjects. For example, if you want to create a Person model that has a firstName, lastName and age, you'll usually want to create a separate SingleValueObject for each field, and then create a Person entity that groups the three ValueObjects.

As explained previously,