Existential Consistency Principle

Existential Consistency Principle Definition

Existential Consistency Principle states that an object exists only when its consistency rules are obeyed.

Description

Each object has specific characteristics with rules that should not be broken during its lifetime. If any of these rules are not satisfied, the object is considered to be in inconsistent state, thus no reason for it to exist.

An object with an inconsistent state is a wrong object by design. Completely different object with this state must be created, inside which the state is considered as consistent.

Examples

First name

Context defined: first name is a personal name given to someone at birth. Projection in domain: Firstname object with consistency obeyed by following characteristics:

  • first name cannot be nothing (null/empty)
  • first name must contain only letters
  • first name must start with capital letter
  • first name length must be between 2 and 30 characters

An inconsistent Firstname object would allow null as its value. It’s not anymore a first name in established domain context. It does not obey its consistency rule: “cannot be null”. In this case we are not dealing with Firstname any more. This is already another object, let’s define it as StringLiteral object. StringLiteral object is consistent, because we define it as any string representation including null(nothing).

Triangle

Context defined: triangle is a polygon with three edges and three vertices. Projection in domain: Triangle object with consistency obeyed by these characteristics.

An inconsistent Triangle object would lack for example an edge. It’s not anymore a triangle in established domain context, because it does not obey one of its consistency rules: “must have three edges”. In this case we are not dealing with a Triangle any more. This is already another object, let’s define it as AlmostTriangle object. AlmostTriangle object is consistent, because we define it as having two edges and three vertices.

How To Ensure Existential Consistency Principle?

  • establish context definition (define what does the object represent inside given context)
  • project in domain the object’s protocol of characteristics that ensure its consistency
  • follow the protocol, when protocol is not obeyed – repeat these steps again

17 November 2018