0

I found the following passage in the book "Headfirst java". I don't understand the bolded part in the below passage.

Object: The point to setters (and getters, too) is that you can change your mind later, without breaking anybody else's code! Imagine if half the people in your com- pany used your class with public instance variables, and one day you suddenly realized, " Oops - there's something I didn't plan for with that value, I'm going to have to switch to a setter method." You break everyone's code. The cool thing about encapsulation is that you get to change your mind. And nobody gets hurt. The performance gains from using variables directly is so miniscule and would rarely be worth it.

zelite
  • 1,478
  • 16
  • 37
sucky_code
  • 23
  • 5

1 Answers1

0

The internal representation of that value may change and require a new type be used, which could be hidden from other code using getter/setter methods.

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101
  • aha !!! then others might falsely assign it to another type that can't can take it and not be able to compile it ?? right?? ( Sorry for late reply. Thank you !!! ) – sucky_code Apr 07 '20 at 08:39