2.3. What s in a Name?

 <  Day Day Up  >  

2.3. What's in a Name ?

Names 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.

He paused for a moment and looked 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 term with a sentence :

"Now is it possible that a CD which a customer would be looking for would be related 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 rerelease in its title."

"We can always revisit 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:



Checkout_a_CDDisc

  1. The user enters the customer ID and the CDDisc ID into the system.

  2. The system records the entry. It responds by printing a rental contract for the customer to sign.

Names are subjective . 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:



CDUPC

A CD identified by a UPC



CDPhysical

A physical CD of a particular CDUPC



CDCatalogItem

A CD identified by a UPC



CDRentalItem

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.

AIRLINE FLIGHTS

I worked with a group 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?

The reservations people agreed on the following definitions:



Segment

A trip with a single departure and arrival. For example:

Boston to Albany on Flight 80

Albany to Chicago on Flight 80



Flight

A numerically designated set of segments, with the departure location of the subsequent 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



Leg

A set of one or more consecutive flight segments on a flight. For example:

Flight 80 Boston to Albany to Chicago



Journey

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 marriage is a journey, for which the cancellation of one leg results in the cancellation of all legs of the journey.


 <  Day Day Up  >  


Prefactoring
Prefactoring: Extreme Abstraction, Extreme Separation, Extreme Readability
ISBN: 0596008740
EAN: 2147483647
Year: 2005
Pages: 175
Authors: Ken Pugh

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