2.3. What's in a
are important, not just for the code but also for requirements and analysis. If you don't know what you're talking about, it's hard to design for it.
Sam described how he wants to keep track of the CDs. He also desired a catalog of all the CDs that he has for rent.
"So, what is a CD?" I asked Sam.
for a moment and
at me with a questioning expression on his face. He must have thought I was crazy. "You know, one of those round things you put in a CD player," he said.
"So, when you said you want a CD catalog, do you mean you want an entry in it for every round thing you have in your store?" I asked.
He paused again. "No, I want only one for each title, regardless of how many copies I have in the store."
I suggested, "So, let's decide to use two terms, one for the CD title and one for the CD copy. This way we minimize the opportunity for misunderstanding. What do you want to call each thing?"
"Now I see what you mean," he replied. "What do you suggest?"
I replied, "Let's call the title a CDRelease, and the other a CDDisc. We could use the name CDTitle, but that would start to get confusing when we talk about the title of a CDTitle. To clarify what we mean even further, we can describe each
"Now is it possible that a CD which a customer would be looking for would be
to two different UPCs?" I asked.
"It's possible," he said. "But I don't think we need to worry about that. One would usually have the term
in its title."
"We can always
this question if things change," I said. "Let's alter your requirements and the use cases to utilize these terms."
At this point, Sam and I came up with the following list of modified requirements:
Keep track of where each CDDisc is, both when it is in the store and when someone has rented it (including who has rented it).
Report when a CDDisc is overdue.
Have a catalog so that customers can see which CDReleases are stocked, what songs are on each CDRelease, and which corresponding CDDiscs are available in the store.
Here is a modified use case:
enters the customer ID and the CDDisc ID into the system.
The system records the entry. It responds by printing a rental contract for the customer to sign.
. As long as you and the client agree on a name, it does not matter if the name makes sense to the outside world. Here are some other possibilities for names of these two concepts:
A CD identified by a UPC
A physical CD of a particular CDUPC
A CD identified by a UPC
A physical CD copy of a particular CDCatalogItem
Attributes of these classes should use the same names as the customer uses. If the customer uses a full name, avoid making up an abbreviation for it. If the customer uses an abbreviation or acronym, use that. If you have a hard time recalling what the short form means, ask the customer to supply a longer name.
A ROSE BY ANY OTHER NAME IS NOT A ROSE
Create a clearly defined name for each concept in a system.
See http://www.literateprogramming.com/ for a discussion of names.
I worked with a
responsible for developing an airline reservation system. There is a lot of interesting terminology in the airline business. Think of your concept of a "flight" as a passenger. When you fly from Boston to Peoria, do you say that you are taking a flight to Peoria? Do you say that, even if you make a connection in Chicago? In that case, would you refer to it as a "connecting flight"? If you were on Flight 80 from Boston to Chicago and on Flight 100 from Chicago to Peoria, would you say that you are on two different flights? Suppose that Flight 80 landed in Albany on the way to Chicago. Are you on three different flights?
people agreed on the following definitions:
A trip with a single
and arrival. For example:
Boston to Albany on Flight 80
Albany to Chicago on Flight 80
designated set of segments, with the departure location of the
segment the same as the arrival location of the previous segment. For example:
Flight 80 Miami to Boston to Albany to Chicago to Seattle
Flight 100 Dallas to Chicago to Peoria
A set of one or more consecutive flight segments on a flight. For example:
Flight 80 Boston to Albany to Chicago
A set of one or more legs for a passenger that takes a passenger from a departure location to an arrival location. For example:
Flight 80 Boston to Albany to Chicago and Flight 100 Chicago to Peoria
These consensus definitions made it easy to create higher-level concepts, such as "marriage." A
is a journey, for which the cancellation of one leg results in the cancellation of all legs of the journey.