Through a combination of convention and discipline, it is possible to create immutable objects in Java, but there are no guarantees. But that is what we try to do when building systems out of mutable objects. It would be impossible to build a house using magic, mutable bricks like those. When building a house, one does not expect one brick to reach out and change the properties of another brick, which triggers that brick to change something about the brick next to it, and so on. When you pass an object to a method, you have no idea what will happen – the method may change the object's properties, or some other object's properties, perhaps through a chain of nested calls. This makes it much harder to reason about a program's behavior. In most OO languages, including Java, objects are mutable by default. But there is one major fly in the ointment: mutability.
#DEFINE FLICKERY CODE#
Now I believe that objects have improved our code in many ways. Objects would be like those bricks – easy to reason about, quick to assemble into larger composite structures, and easy to substitute one object for another, as long as the substitute observed the same contract. When building a house, you do not need to worry about the internal structure of your bricks: one brick is as good as another (assuming you have a reliable supplier). They would provide us with reusable building blocks, easy to reason about and reuse – just like LEGO blocks or bricks in a house. If you are a "programmer of a certain age," you will remember some of the initial hype surrounding OOP and objects: Objects would rescue us from the maze of procedural spaghetti code through encapsulation. given to changing constantly changing fickle or inconstant: the mutable ways of fortune // Synonyms: capricious, flickery, fluctuating, mercurial, fickle, unpredictable, unstable
#DEFINE FLICKERY SOFTWARE#
Immutability in Clojure - Part 1, Programming Without Variablesīy Steve Molitor, OCI Senior Software Engineer Immutability in Clojure - Part 1, Programming Without Variables.