public interface Invariants
Utility interface providing static checks for domain invariants.
Invariants are business rules that must hold true throughout the lifetime of an
aggregate. Use requireNull(Object, String) to assert that a field has not yet
been assigned a value when a one-time, immutable assignment is required.
- See Also:
-
Method Summary
Static Methods
-
Method Details
-
requireNull
Asserts thatobjectisnull, throwing anIllegalStateExceptionwith the givenmessageif it is not.Typical use is to guard a field that must only be set once:
Invariants.requireNull(this.publicId, "publicId must not change once set"); this.publicId = publicId;- Type Parameters:
T- the type of the object being checked- Parameters:
object- the value to check; the assertion passes only when this isnullmessage- the detail message for the exception if the assertion fails- Throws:
IllegalStateException- ifobjectis notnull
-