Getters
TLDR: Getters are methods in object-oriented programming used to retrieve the value of private field or protected fields in a class. They provide controlled access to an object’s properties while maintaining encapsulation and protecting the integrity of its internal state. Getters are widely used in languages like Java, CPP, and C Sharp to expose data safely without allowing direct field modification.
https://en.wikipedia.org/wiki/Mutator_method
In Java, getters follow a standard naming convention, typically starting with `get` followed by the capitalized field name (e.g., `getName()` for a field `name`). These methods are used in combination with private fields to enforce encapsulation, ensuring that field values can be accessed but not altered directly. Getters can also include additional logic, such as formatting or validation, before returning a value, enhancing their functionality.
https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
Getters are integral to creating robust APIs and immutable objects. By restricting direct field access, they enable developers to maintain control over an object’s behavior and ensure consistent data manipulation. For instance, in immutable classes, getters allow access to properties without compromising immutability. Their use aligns with software design principles like abstraction and encapsulation, promoting cleaner and more maintainable code.
https://docs.oracle.com/javase/specs/jls/se20/html/jls-8.html