[A]n object's instance variables (member fields that aren't constants), should always be private. Period. No exceptions. Ever. I mean it. (You can occasionally use protected methods effectively, but protected instance variables are an abomination.) You should never use get/set functions for the same reason—they're just overly complicated ways to make a field public (though access functions that return full-blown objects rather than a basic-type value are reasonable in situations where the returned object's class is a key abstraction in the design).http://www.javaworld.com/javaworld/jw-08-2003/jw-0801-toolbox.html?page=2
Saturday, August 11, 2012
Protected instance variables are an abomination
Labels:
OOP
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment