This issue has come up dozens of times.

First, it's clearly absurd to fill source code with boilerplate getter/
setter code. Even if IDEs can auto-generate, it still has to be
manually read/maintained.

What I don't understand is why language changes are needed to avoid
that.

Libraries and frameworks like JPA/Facelets/Spring/etc should use
explicit getter/setter methods if they exist and otherwise fallback on
raw exposed instance variables. Some Java libraries already do that.

That way for the 99% case, you just use a plain instance variable and
for the 1% case where you need non-trivial getter/setter logic you can
write them. Also, you can change your code at any time without
breaking compatibility.

class SomeClass {
        // No getters/setters. Libraries like JPA/Facelets/Spring/etc can
        // access directly in the absence of getters/setters
        public int simpleProperty;

        // Example where explicit getter/setter logic is actually needed.
        private int complicatedProperty;
        public int getComplicatedProperty() {
                // Do something non-trivial
        }
        public void setComplicatedProperty(int value) {
                // Do something non-trivial
        }
}

BTW, JavaFX has a very elegant solution to the issue with binding.

Also, great Cay Horstmann interview

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to javaposse@googlegroups.com
To unsubscribe from this group, send email to 
javaposse+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to