Chapter 4: Metaphor: Bridge to the Unfamiliar


Overview

Along the philosophical fringes of science we may find reasons to question basic conceptual structures and to grope for ways to refashion them. Old idioms are bound to fail us here, and only metaphor can begin to limn the new  order.

”Willard Van Orman Quine

Explanations without metaphor would be difficult if not impossible , for in order to describe the unknown, we must resort to concepts that we know and understand, and that is the essence of metaphor.

”Earl MacCormac

Object philosophy generates a different view of the world, one that is strange to most and especially to developers trained in conventional methods and ideas. This raises the question of how best to assist developers to understand the new world of objects. In other disciplines, metaphor is frequently used to help those new to an area of study comprehend its fundamental concepts.

Consider the Bohr model of an atom, as one example. Physicists and chemists need to explain atomic structure to lay people and to new students. One common way to do so is to employ Bohr s metaphoric model that says an atom is like a tiny solar system ”a nucleus (sun) surrounded by orbiting electrons (planets). This metaphor is technically inaccurate, of course, but it remains a useful tool for introducing atomic concepts.

Unsurprisingly, metaphors have also been used to convey object concepts. One of the earliest, coined by Brad Cox, is the software integrated circuit (IC). This metaphor juxtaposes a desirable trait for software objects with hardware components , that is, the ability to use them as standardized and interchangeable parts to mass-produce larger constructs. It s possible, for example, to shop at a number of electronics stores, buy standard components from a variety of manufacturers, and use those components to assemble a working personal computer. Construction of software in a similar manner is one goal of object orientation; hence the applicability of the metaphor.

start sidebar
Behind the Quotes ”Brad Cox

Brad Cox was one of the earliest advocates of object-oriented programming and was the developer of the Objective-C programming language, which was the core of the Next Computer operating system and development environment. ( Next was the first company started by Steve Jobs when he left Apple Computer.) Objective-C extended the standard C programming language with Smalltalk characteristics ”an attempt to realize the expressiveness and simplicity of Smalltalk while retaining the efficiency and power of C.

Dr. Cox coined an early metaphor for object components ” software ICs ” suggesting that software components should be as modular and as composable as the ICs used to build hardware. Given an appropriate set of ICs, software could be mass-produced ”cheaply and with quality ”just as guns were after Colt and Remington invented standardized parts for guns.

One of Dr. Cox s most intriguing ideas was the concept of superdistribution . The core idea of superdistribution was to make individual software modules available via the Web and charge for their use, component by component ”a concept that is evident in Microsoft s vision of Web services.

Dr. Cox recently resigned from George Mason University to concentrate on a company that will make superdistribution a reality. He has many other interests, and his Middle Of Nowhere ( http://www.virtualschool.edu/mon ) is well worth a visit.

end sidebar
 

The software IC metaphor is less helpful, however, when our concern is object discovery and specification because it tells us only of a desirable trait for the finished product. Alan Kay, Adele Goldberg, Ken Rubin, and Philippe Kahn, among many others, employ the metaphor of a person when engaged in the process of discovery and analysis. An object is like a person. This metaphor is sufficiently important to object thinking that it warrants its own special term ”anthropomorphization. And of course, the more syllables a word has, the more important it must be. We will return to this metaphor later.

Metaphors are not just a tool to explore the unfamiliar. Metaphor is essential to everyday thinking as well. The full importance of metaphor in shaping our thoughts has received a lot of attention in recent years , notably in the work of George Lakoff.

start sidebar
Behind the Quotes ”George Lakoff

Professor Lakoff teaches and researches linguistics , cognitive science, and cognitive philosophy at the University of California, Berkeley. His books most likely to be of interest to readers of this book include Metaphors We Live By; Women, Fire, and Dangerous Things; and Philosophy in the Flesh . Lakoff s work is frequently cited by those criticizing traditional approaches to software development ”especially the kind of set-based category theory underlying traditional approaches to data and data modeling ”as well as by those advocating a more human-centric approach to computing and the software development process.

Dr. Lakoff s research reveals the central role of metaphor in all human cognition and provides a foundation for Kent Beck s ideas about metaphor in extreme programming ”everything from the value of a system metaphor (in lieu of architecture) to the need for metaphorical awareness when creating object and method naming conventions.

end sidebar
 

Metaphor shapes our thinking in many different ways.

  • It helps in discovery.     If our system is like an X , this component is probably like a Y .

  • It helps us make design decisions.     When a person is asked for ID, she usually hands over some sort of document (such as a driver s license), so our Person probably should store identifying information in a similar kind of object instead of as a sequence of instance variables containing single values."

  • It provides handy ways to remember principles of object thinking.     Objects are naturally lazy, and this is starting to look hard. We had better refactor our design and split this work up among several objects.

  • It helps us avoid old ways of thinking by avoiding the metaphors that are associated with those kinds of thinking.     Instead of ˜next the machine needs to do this, we use, ˜Just ask object X to do  that.

Metaphor plays a critical role in XP as well as in object thinking. Kent Beck used his keynote address at OOPSLA 2002 to explore all the ways that metaphor affects all aspects of XP. One of the 12 practices in XP is the system metaphor, which is deemed powerful enough to eliminate the need for detailed up-front architectural design to guide development. In Kent s book on test-driven development, [1] he talks about how different metaphors led to several different designs and implementations of multicurrency money.

start sidebar
Forward Thinking ”A Vignette

Roger and Suroor are working on the accumulate money story, the user story about how the vending machine accepts coins and currency and reports back a total. They have test cases based on random selection from among all the possible denominations of coins and paper money from all three target currencies (euros, yen, and dollars) and are starting to code the Accumulator class.

I guess we will need a method to determine what kind of currency we have and what its value is, suggests Roger, and one to convert the currencies into some kind of common value ”all dollars, or yen, or euros. A method to report the total amount in the accumulator and one to actually add each instance of inserted money to the current accumulation, he continued .

Don t forget some kind of reset-to-zero method, added Suroor. Two of these methods are really easy. Suroor is talking while typing code for two methods: reset     total = 0; and total , which just returns the amount in the instance variable named total .

Determining the kind and value of the currency looks like it might be complicated, says Roger, reaching for the keyboard, some kind of case statement probably.

No, no, interjected Suroor. Remember, object code shouldn t need case statements ”we need to rethink which object is responsible for identifying currency type and value. When I was pairing yesterday on the credit card story, we created a Money class that identified its value and its currency. We should use that.

You re right; some way or another, every bit of money put in the machine identifies itself with a currency type and a value, Roger agreed, nodding. After all, that is what happens now ”somehow money uses inertia and shape to tell the machine what it is. Maybe someday there will be a chip in coins and currency that does the job easier ”but whatever, it is the money s responsibility.

That makes the add method real easy, said Suroor as she typed the new method: amount in total, add amount inserted .

But wait, what about currency conversion? Suroor was talking out loud to herself.

Money should do that too, suggested Roger. All money objects should have methods to convert themselves into other currencies ”something like asEuro or asDollar .

The team creating the Money object is doing that ”using a currency conversion lookup table for the actual exchange rate ”a collaborator for the money object.

How do we know what currency to convert to?

Ask the VendingMachine object ”it will be a global object that can be used to store bits of information that all the other objects in the vending machine application might need to access. It can have a variable named localCurrency or defaultCurrency . Make a note.

What does the code look like now?

Well, we only have three methods ” reportTotal , resetTotal , and addToAccumulation . The first two are just one line of code each. The last one is more complicated, but not much. The method name is addToTotal , and it has an argument, moneyInserted . The actual method has three levels ”see how it is nested:

 totaladdToTotal(moneyInsertedas(vendingMachine.localCurrency)). 

Looks like we kept our object appropriately lazy ”making the money object do all the work of identifying itself, conversion, and addition.

Yeah, but those methods are easy for money to do for itself ”we actually simplified the system by doing this.

end sidebar
 

Metaphors are very powerful. Object thinking is absolutely dependent on selecting and employing the right metaphors. Each metaphor ”whether general or specific to design details ”must be consistent with the philosophy behind objects as discussed in previous chapters. In this chapter, we will introduce several key metaphors.

[1] Beck, Kent. Test Driven Development by Example . Boston Addison-Wesley, 2003. ISBN 0-321-14653-0.




Microsoft Object Thinking
Object Thinking (DV-Microsoft Professional)
ISBN: 0735619654
EAN: 2147483647
Year: 2004
Pages: 88
Authors: David West

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net