Class Invariant - Examples - Native Support - D

D

D programming language has native support of class invariants, as well as other contract programming techniques. Here is an example from the official documentation.

class Date { int day; int hour; invariant { assert(1 <= day && day <= 31); assert(0 <= hour && hour < 24); } }

Read more about this topic:  Class Invariant, Examples, Native Support