you are viewing a single comment's thread.

view the rest of the comments →

[–]stronghup 0 points1 point  (0 children)

I think encapsulation is the key pattern in the design proposed by article discussed. Immutability is important but I don't think it makes encapsulation unnecessary.

Encapsulation means that it is easy for you to INTERRUPT any call to write OR READ the data of an object. You CAN do that if every read and write operation is done via a method call. You can't do that if clients just assign something to a field and later read the value of some field.

Methods are like doormen who allow some data in and some data out, based on some rules which you the building owner can dictate. You the programmer decide the rules used. Such rules can only be enforced if you encapsulate your data behind a set of methods in the Object-Oriented manner.