michael Hannigan wrote:in the book it says that... well what if the code gets into the wrong hand and someone writes something like one.setSize(0) then you would get a dog with size 0 which is essentially illogical. but then again, i'm the programmer, and i am the person who writes the code and passing the right integer... why would i pass something that doesn't make sense lol
Giovanni Montano wrote:Michael,
i understand your point, the book you study is great, but one month ago i was stuck on the same problem, as does not make clear what is the real purpose of.
I am understanding encapsulation now that i am starting to think object oriented.
Imagine, what would happen if you do the next google car and the user put how fast the car have to go with a setter... it would not be really safe and cool having a class with a setter with a private variable, and a condition inside that he will use the instructions given by the user only if the car goes less than 180 km/h???
I assume if you google "getters and setters java" or " encapsulation java" or you look these keywords on the tube after few tutorials will be real clear in your mind.
enjoy your coding time.