4 ms·
This looks really nice. I wish Java would do something about getters and setters. It's very awkward that they are not incorporated into the language but so man
by mbell 13y ago
This looks really nice.
I wish Java would do something about getters and setters. It's very awkward that they are not incorporated into the language but so many libraries assume they exist that it's a defacto requirement to generate the same boilerplate constantly. I wish the language itself would provide default 'simple' getters/setters the way Groovy does and incorporate them throughout so I could use e.g.
.set(Person::firstName) //Reference a default setter method for the firstName member if one isn't explicitly defined
instead of
.set(Person::setFirstName)
- ed_blackburn 13y agoAs a C# developer I urge caution. When getters and setters become as trivial as public int Age { get; set; } Code becomes less OO and more procedural filled with anaemic models / bags of state. Practices like Tell don't Ask, Information Hiding and Rich Models, slip away.
- yawz 13y agoVery very valid points, in my experience.
- thangalin 13y agoAccessor messages in Smalltalk, a pure Object-Oriented Programming environment, have been that trivial for a long time. See: http://www.jmcsweeney.co.uk/computing/m206/accessors.php http://www.jmcsweeney.co.uk/computing/m206/accessors.php The issue, as I see it, isn't the ease of creating accessors; the issue is that students do not seem to learn about the practices you've mentioned. I demonstrate "Tell, Don't Ask", "Information Hiding", and "Encapsulation" in the following presentation: http://whitemagicsoftware.com/encapsulation.pdf http://whitemagicsoftware.com/encapsulation.pdf
- mbell 13y ago> Code becomes less OO Frankly...good. If there is one thing Java desperately needs, it's less OO code.
- adrianmalacoda 13y agoYou might find Project Lombok [1] interesting. It's a library of annotations that can be used to generate boilerplate code. [1] http://projectlombok.org/ http://projectlombok.org/