One Pager Cheat Sheet
- We must start by understanding
Objects
, which are pieces of data that have unique identities, states, and behaviors, to properly discuss the difference betweenmutable
andimmutable
objects. - An immutable object's states and behaviors cannot be changed once it is created, while a mutable object's states and behaviors can be changed after its creation.
- Instances of immutable classes are unchangeable once they are created due to their restricted access and lack of
set
methods. - The constructor has an unassigned
final
variable and theprintModel()
method should bepublic
and return themodel
String
. - We have to clone the immutable object, and modify it, as there is no way to directly manipulate it.
- Immutable objects are useful for concurrent programming, mapping, and critical systems, providing consistency and safety.
- Java provides
default immutable classes
, such asString
,Boolean
, andInteger
, which are useful for ensuring that their values remain unaltered in complex programming scenarios. - Both
Redux
and mutable objects offer benefits and are used for different purposes, with Redux leveraging the concept of immutability to manage state and mutable objects allowing changes to be made without having to create a new copy. - The class
myClass
is immutable - its values are set during its initialization and cannot be modified afterwards.