I have some questions regarding the immutable pattern. First of all to solve the problem we need to ensure the following :
1)Instance methods which access properties must not change instance variables.
2) Ensure that the constructor of the immutable class is the only place where the values of instance variables are set or modified. I think that by making the inctance variables as final variables , then if there exists a method that changes this variable will fail , even the constructor will not be able to change this variable , so why we need to put into considerations these two statements if we can use the final keyword ?? I know that i am missing something.
Aucun commentaire:
Enregistrer un commentaire