Quantcast
Channel: Why use getters and setters/accessors? - Stack Overflow
Viewing all articles
Browse latest Browse all 38

Answer by Thorbjørn Ravn Andersen for Why use getters and setters/accessors?

$
0
0

I spent quite a while thinking this over for the Java case, and I believe the real reasons are:

  1. Code to the interface, not the implementation
  2. Interfaces only specify methods, not fields

In other words, the only way you can specify a field in an interface is by providing a method for writing a new value and a method for reading the current value.

Those methods are the infamous getter and setter....


Viewing all articles
Browse latest Browse all 38

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>