Giving up procedural idioms is neither easy nor comfortable. Too many things that are "right" in a procedural context are "wrong" in an OO context. I've heard many lame excuses for staying in the procedural comfort zone. One of the contributors to the previous article's discussion, for example, claimed that hard-core data abstraction such as I've described was worthless in situations where maintenance was not important, which he infers, is often the case. I can't personally imagine any situation where maintenance is not important, however. First of all, throw-away programs never seem to be thrown away. I've worked on 20-year-old "throw-away" code. More importantly, my code hits maintenance roughly two seconds after I finish writing it. Whenever I look at code I wrote yesterday, I'm in maintenance mode. I imagine that the writer of that comment is just a much better programmer than me. He writes perfect code right off the bat and never looks back at his code once it's written. Though I can aspire to that level of perfection, I'm not there yet. I'm constantly refactoring my code to improve it. Every time a business rule changes—and this often happens while the program is under construction—the existing code is effectively in maintenance.
Giving up "procedural thinking" isn't easy, but it's worth doing.
Learn more about this topic
- Download this article's complete source code
http://www.holub.com/publications/articles - "Why Getter and Setter Methods Are Evil," Allen Holub (JavaWorld, September 2003)
http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html - Builder is discussed on p. 97f of the Gang of Four book, Design Patterns, Eric Gamma, Richard Helm, Ralph Johnson, John Vlissides (Addison-Wesley Publishing Co., 1995; ISBN0201633612) http://www.amazon.com/exec/obidos/ASIN/0201633612/alleiholuasso
- David Geary's Java Design Patterns column about the Strategy pattern, "Strategy For Success" (JavaWorld, April 2002)
http://www.javaworld.com/javaworld/jw-04-2002/jw-0426-designpatterns.html - Another UI architecture that doesn't require get/set methods is described in Allen Holub's past article, "Build User Interfaces For Object-Oriented Systems, Part 2The Visual-Proxy Architecture" (JavaWorld, September 1999)
http://www.javaworld.com/javaworld/jw-09-1999/jw-09-toolbox.html - Allen Holub's forthcoming book Holub on PatternsLearning Design Patterns by Looking at Code (Apress, summer 2004) presents another example of using Builder for I/O, but in the context of importing and exporting database tables. In particular, all knowledge of the format used to store the data on the disk is encapsulated in the Builder rather than the database classes. This way the database can export tables to multiple formats, even ones that didn't exist when the classes were written.
- Justin Kruger and David Dunning's spectacular article "Unskilled and Unaware of ItHow Difficulties in Recognizing One's Own Incompetence Lead to Inflated Self-Assessments" goes a long way to explaining why concepts such as implementation encapsulation are so hard for procedural programmers to grasp. This article should be required reading for all computer programmers. Find it at
http://www.apa.org/journals/psp/psp7761121.html - See all of Allen Holub's Java Toolbox columns
http://www.javaworld.com/columns/jw-toolbox-index.shtml - View David Geary's Java Design Patterns columns
http://www.javaworld.com/columns/jw-java-design-patterns-index.shtml - Browse the Design Patterns section of JavaWorld's Topical Index
http://www.javaworld.com/channel_content/jw-patterns-index.shtml - Browse the User Interface Design section of JavaWorld's Topical Index
http://www.javaworld.com/channel_content/jw-ui-index.shtml - Browse the Object-Oriented Design and Programming section of JavaWorld's Topical Index
http://www.javaworld.com/channel_content/jw-oop-index.shtml - Visit the Programming Theory & Practice discussion
http://www.javaworld.com/javaforums/postlist.php?Cat=&Board=TheoryPractice - Sign up for JavaWorld's free weekly newsletters
http://www.javaworld.com/subscribe



