4 ms·
In Java, exposing public instance variables of a class is risky because any changes to the internal operation of that class requires modification to the callers
by LogicHoleFlaw 18y ago
In Java, exposing public instance variables of a class is risky because any changes to the internal operation of that class requires modification to the callers of that class. If you write your accessor methods up front then you can add additional behavior to those accesses at a later point in time. That is largely a syntactical issue.
A similar reasoning causes the proliferation of interfaces and factories. The inability to dynamically create objects at run-time leads to a great deal of indirection created at write-time and compile time. That's a semantic issue which creates tons of complexity for little gain. Beans are a direct response to these limitations. For instance with most dependency injection frameworks you can alter an XML file to rewire Bean creation without having to recompile or modify the source of your Java codebase. It's a hack emulating a subset of the capabilities of dynamic metaprogramming.
The Bean style of operation greatly encourages all of these verbose design styles. Some of it can be avoided through introspection, aspects, and annotations, but that is very clumsy in Java. Java practices have indeed changed a lot since 2000 but the increase in incidental complexity is just stunning.
(major edits: expound upon my points.)