Java Basics

Commentary: Getters and Setters are Evil

Evil. Because getters and setters reduce the encapsulation advantages of a class, and because they increase the coupling, they are often considered evil, and their use should be discouraged.

However, because they are useful, and required in many situations, they are often used. The problem is how to make them easier to use.

Properties is the buzzword that is often associated with how to think about the values that the getters and setters work on. There have been a number of proposals for properties and notation for them to reduce the mindless, error-prone, boilerplate type of getter-setter coding.

See Cay Horstmann's Arrows in the Back and Pie in the Sky Properties blog entries for a good discussion of this topic.