The Depths of Immutable Class Design — 2

Why the fields should be marked as final

In the previous article, we have looked at the rules like preventing the subclass, taking care of getters returning the references to non-immutable objects, etc. In this article, we will look at the most important rule — Making the fields final and the reasons behind it.

While designing the immutable classes we need to ensure that at all costs the state will not be changed once the object is published.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store

Full Stack Developer, Software Consultant, Technical Content Writer, Free Lancer