Conrad Weisert, August 1, 2011
Whether you're a strong supporter of the object paradign or an OOP-doubter, you probably agree that the original excitement surrounding objects was driven by a desire to simplify software development and maintenance. OOP was bringing us an elegant way of enforcing modularity.
Before long, however, we started seeing examples in which the use of objects produced programs that were longer and more complicated than the equivalent procedural module. An extreme example appeared in, of all places, the Communications of the ACM, October, 2001, under the title "Hello World Considered Harmful".
The author chided fellow instructors in elementary Computer Science for failing to exploit modern object technology in the classic first executable program. He showed an alternative in which:
We still encounter a few professional programmers and even well-known "experts" who seem to believe that the more "objects" a program creates the more object-oriented the program is, even objects that represent no entity and exhibit no behavior.
Although confusion over the object paradigm is felt among some programmers using Smalltalk®, C++, C#, and other object-oriented programming languages, it is by far most prevalent among Java programmers. It's easy to see why.
Java uses classes not only as templates for creating objects, but also as packaging artifices for independent functions that, in the other languages, aren't required to have any such relationship. In Java, therefore, there is always some class that the program can instantiate by invoking new.
Several years ago we offered a check list for creating objects. Since then the issue has grown to the point where I would offer an actual rule for Java programmers:
Weisert's Rule1 for instantiating Java objects
If there's a good reason to depart from the above, it must be explained in commentary. What does this object represent? Why is it needed?
The rule applies also, of course, to other O.O. programming languages, but they don't seem to be having quite the struggle that the Java community has been undergoing.
If we're reading Java source code and we come upon one of these:
Last modified 4 August 2011
Return to technical articles .
Return to IDI home page.