Classes Without Oo

[From ClassicOoAntiPatterns]

Even if the language forces you to put all code in classes, it can't force you to do real object oriented programming: Some OO beginners will cram all their functions into one big massive class (typically a singleton). What they end up with might be a good modular or functional design, but it's not OO.

"My," I said, "that's a pretty good ModularProgramming design you have there, but you've kinda' missed the boat on the object thing."

I've also seen the use of method classes that pass around and operate on data classes. Of course this violates the LawOfDemeter, but the programmers creating these classes don't know this law.

I've done this many times, and I do know LawOfDemeter. I just think LawOfDemeter isn't a good rule for every case. (I'm a FunctionalWeenie.)


They can also abuse this by making all the methods static. Then the class is, essentially, just a NameSpace.

In some languages, like Java, you really have no choice. You can't define functions within packages; static functions within otherwise empty classes is as close as you can come.--ScottJohnson

Even many OO fans agree that OO may not be the best approach for all situations. Thus, it follows that a language should allow one to have functions and modules without being forced into OO syntax or OO-style namespacing.


See FearOfAddingClasses for discussion as to why people would put too much functionality into existing classes, or fail to see the benefits of adding new classes.

ProducingSingletonGarbage comes at it from the memory management angle. -- JeffGrigg


See also: PrimaryNoun


EditText of this page (last edited January 23, 2006) or FindPage with title or text search