Home > database >  Let's talk about perceptions of encapsulation
Let's talk about perceptions of encapsulation

Time:11-09

Packaging: public must open, hide those unnecessary public
We usually hidden attributes in everyday use, public methods, there are many benefits of doing so, I think the most important thing is that it makes the state of an object determines,
State of an object and subject to change with the change of the time, but this change can be caused by the method calls itself changes, if an object without any modify the operation of the state of their own, but his condition is changed, then can only explain encapsulation has taken a knock.
A is the most intuitive example is the class to write a mutable object reference accessor methods (as shown in the figure below), if you need to return to a mutable object reference, you should use clone () method, (pictured)
  • Related