Modddels Overview

What is a Modddel ?

Modddels are "self-validated" objects that can have two states : Valid or Invalid.

For each modddel, you can specify a number of "validationSteps", each one containing a number of "validations". Each validation can either be successful or fail with a Failure. If the modddel passes all the validationSteps, then it is Valid. Otherwise, it is Invalid and holds the failure(s). The Invalid state is further subdivided into multiple states, each one representing a failed validationStep.

The generated Modddel is a Sealed class which union-cases represent the different states it can have. This allows dealing with the different states of the Modddel in a compile-safe way, making impossible states impossible.

InvalidModddel is an abstract union-case, while the other union-cases are concrete.

Modddel kinds

There are two main kinds of modddels : ValueObjects & Entities.

A ValueObject is a modddel that holds a "value". This "value" can be made up by one or multiple fields. For example : Name would have a single string field 'name', while GeoPoint would have two integer fields 'latitude' and 'longitude'.

An Entity is a modddel that holds other modddels (ValueObjects or Entities). More about them later.

Both ValueObjects and Entities are validated by one or multiple validations, grouped in one or multiple validationSteps. Each validation either passes successfully, or fails with a Failure.

You might be familiar with ValueObjects and Entities from DDD (Domain-Driven-Design). However, in this package, the definition of ValueObjects and Entities is very broad and doesn't enforce DDD concepts, so you can use them even when not practicing DDD.

Last updated