|Christian Sepulveda's Blog|
November 27, 2003
Scrabble and Dummy Data Objects
Lately, I've been trying to explain the reasons why dummy-data classes are a smell in software. Dummay Data classes are classes that do not have behavior, only data.
I thought of a different way to illustrate the problem, as the common arguments have not seemed sufficient lately.
Consider scrabble. When someone presents a word that is challenged, one of the first comments made is "Use 'fazooloo' in a sentence." A response such as "I was playing scrabble and I was asked to use 'fazooloo' in a sentence" is generally not appropriate. Besides being sarcastic, the sentence doesn't convey anything about the meaning of the word. The questioned term was the object of the sentence and performed no action of its own. You could substitute any term and the sentence does not lose any meaning, but doesn't improve either.
A dummy data class is like a term that can only be used as an object in a sentence. If no sentence exists in which the dummy data class performs the action, it has no purpose but to be manipulated by others. This has various implications, such as encapsulation violations, but I think the sentence analogy simplifies the reaons to avoid dummy data classes.
Martin Fowler has a bliki post about Anemic Domain Models. One characteristic that makes a domain model anemic is the lack of behavior in the objects. Furthermore, I think the domain objects must have domain behavior.
This distinction can have subtle design implications. I worked on a system where we had an elabrorate domain model (or so we thought), but the classes where really dummy data classes. When I pointed this out, others on the project claimed that since the objects knew how to persist and load themselves from the database, that this was their behavior. But from the domain perspective, the objects did nothing. Furthermore, if you then look at the implemented design, there were other smells such as violdation of the Single Responsibility Principle, as the objects where part domain, part technical infrastructure. The design of the system would be greatly improved by starting with the elimination of dummy data classes and following your nose from there.
So, when designing your classes and their collaborations, make sure each class passes the Scrabble Test.Posted by csepulv at November 27, 2003 11:55 AM
Syndicate this site (XML RSS 2.0)
ANN: Website Facelift and New Blogs
The Power of the Collective Brain
Agile 2.0 and Web 2.0: A Perfect Match
Fitness Functions and Agile Development
Agile, Waterfall and Core Assumptions
Three Important Considerations for a Candidate
Guidelines for Being a Strong Job Candidate
Browse By Category