In reference to this previous post, which was inspired by a java patterns book, Holub on Patterns: Learning Design Patterns by Looking at Code, I was again looking for the grail.
Holub uses a builder pattern approach to avoid exposing each private
field through a getter and setter. This approach is interesting
but it quickly becomes complicated in the implementation as a series of
interfaces and implementations become necessary and this leaves the
casual observer wondering if the getter/setter method might be much
simpler to understand.
Holub's assertion is that accessors are used mostly for visual
designer created UI's. This may be true to a large extent but the
alternative seems pretty convoluted. Holub also argues that
accessors are very procedural which may also be true and that object
oriented progroms become procedural at the margins where they must
communicate with procedural systems like UI and database access.
However, in the OO middle the program should be objects which consist
of an almost service stack like service object which provides methods
in which to accomplish tasks (isn't this procedural?).
Conclusion: I have headed the warning of not to go crazy with
accessors and mutators but the alternatives don't have a good
smell.