The Artima Developer Community
Sponsored Link

Design Principles and Code Ownership
A Conversation with Martin Fowler, Part II
by Bill Venners
November 11, 2002

<<  Page 2 of 4  >>


Being Explicit

Martin Fowler: Another design principle that's struck me very firmly, particularly recently, is making things explicit. Make the code very explicitly say things.

Bill Venners: What do you mean? Could you be more explicit?

Martin Fowler: You want an example. If you're going to pass a bit of data around, do you put that data in a dictionary, and pass it around the dictionary? Or do you make a class that holds the data, and pass the data around in the class?

You might argue that the dictionary is better because you don't have to write a new class. If you need to change the data, you don't have to change any code in the dictionary. You have great flexibility in terms of what you can put into the dictionary. If you want to store a new piece of data, you don't have to change any code. You just put the data into the dictionary and give it a new key.

The problem is the dictionary isn't explicit. You don't know what keys are in the dictionary. You don't know whether to call something a customer or client. You can't tell if you make a misspelling. And above all, there's no place you can look at the code and say, "What's the interface of this thing? What are the things I can ask of it?" A dictionary is not explicit. A class, even though you have to do all the work writing in the member variables and accessors, is explicit. You can just look at that source code and know what data is present.

Bill Venners: What explicitness buys me, then, is that it is easier to understand the code.

Martin Fowler: Yes. I've been doing an IEEE software column the last year or two. I've been focusing very much on trying to identify these simple principles, and I give a couple more explicitness examples in the article, To Be Explicit (see Resources).

<<  Page 2 of 4  >>

Sponsored Links

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us