March 2018
Intermediate to advanced
208 pages
4h 52m
English
| | class Astronaut { |
| | |
| » | String name; |
| | boolean retired; |
| | |
| » | Astronaut(String name) { |
| | this.name = name; |
| | } |
| | |
| | String getFullName() { |
| | return name; |
| | } |
| | |
| | void setFullName(String name) { |
| | this.name = name; |
| | } |
| | |
| » | boolean getRetired() { |
| | return retired; |
| | } |
| | |
| » | void setRetiredState(boolean retired) { |
| | this.retired = retired; |
| | } |
| | } |
In object-oriented programming languages, you usually try to avoid direct access to the fields of a class from the outside. That’s why you write getter and setter methods that control this access.
The structure and naming of getters and setters is so standardized that many frameworks heavily rely on it. Hibernate uses it to convert Java instances ...