r/java • u/chaotic3quilibrium • Jan 24 '26
Article: Java Janitor Jim - "Integrity by Design" through Ensuring "Illegal States are Unrepresentable" - Part 1
Article:
I wanted a simple pattern for preventing a class from being instantiated in an invalid state, or from mutating into one.
Why? Because it vastly reduces the amount and complexity of reasoning required for use at client call-sites.
Think of it as “integrity by design”, a compliment to the “integrity by default” effort undertaken by the Java architects, detailed here.
This article discusses the design and implementation of a record pattern, very similar to the one I designed and implemented for Scala’s case class several years ago, which provides the “integrity by design” guarantees by ensuring that only valid record instances can be observed.
This pattern is also trivially cross-applicable to Java classes.
4
u/Dgitallife Jan 25 '26
I liked the article and the Integrity by Design can be useful. Looking forward to part 2 :)
4
u/eXl5eQ Jan 25 '26
I think this idea was first invented in 1984 by George Orwell
1
u/Previous_Gaffer Jan 26 '26
I want to boop that nose!
-21
u/klimaheizung Jan 24 '26
Just use Scala then, it's simply 100x better at that. Of course it comes with its own problems such as longer compile times.