-
Notifications
You must be signed in to change notification settings - Fork 0
Attribute accessor naming
- JavaBean naming conventions: https://learning.oreilly.com/library/view/javaserver-pages-3rd/0596005636/ch20s01s01.html
- Property names as getter, leaving out the "get" prefix
- https://openjdk.org/jeps/395
- Fowler, p. XXX
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
- TODO: Verify: Probably "java-libs" and "archie" project are using "get" prefix. So changing that would it make less likely for those projects to adapt the API components.
- "Get" is not part of the domain model
- Seems like the less modern approach
- https://www.baeldung.com/kotlin/getters-setters#java-interoperability
- https://www.codurance.com/publications/2018/03/20/getters-and-setters-considered-harmful
- https://vaadin.com/blog/ddd-part-2-tactical-domain-driven-design
- https://anderscore.com/bilder/19/DDD-JEE.pdf
- https://stackoverflow.com/questions/59981081/post-java-14-getter-setter-naming-convention
- https://levelup.gitconnected.com/are-getters-and-setters-an-anti-pattern-c8cb5625ca8c?gi=e6386d8815cf