Skip to content
This repository was archived by the owner on Oct 3, 2025. It is now read-only.

Attribute accessor naming

Jan Mewes edited this page May 26, 2023 · 1 revision

In Java code bases one can often find "getter" and "setter" methods. Methods with "get" prefix. If boolean "is" prefix. This pattern was established by the JavaBeans Naming conventions (https://en.wikibooks.org/wiki/Java_Programming/JavaBeans).

It is very commonly used in tooling (https://www.baeldung.com/kotlin/getters-setters#java-interoperability), IDE, and common design pattern (https://learning.oreilly.com/library/view/java-design-patterns/9781484279717/html/395506_3_En_7_Chapter.xhtml)

While setter methods are considered an anti-pattern in DDD, getter methods seem still to be prevalent.

However, there is another trend where the "get" prefix is left out.

While the second approach might be more modern it still might make sense to stick to the good old getter methods.

Pros

  • Commonly used pattern.
  • Clear distinction between attributes and methods.
  • Using this seems approach might be less controversial than the other approach.

Cons

Clone this wiki locally