Flylib.com

Books Software

 
 
 

2.2. Reinvention Avoidance

 <  Day Day Up  >  

2.2. Reinvention Avoidance

Once Tim and I understand Sam's system requirements, our first step is to determine whether an existing program provides the features that we need. There is no sense in re-creating the wheel if an existing wheel works the way we want. Our goal as developers is to solve the client's problem, not to just write code.

Sam had searched for a commercial program and did not find anything. It appears that he is in a unique business, so nothing has been written, which is not surprising. [*]

[*] Finding existing solutions can be problematic . Sometimes it can be hard to describe the solution you seek in such a way that Google? can find a match.

We suggested to him that the process of renting a CD is similar to the process of renting a videotape or DVD. He could purchase one of those programs and it would already have many of the features that he wanted. He decided that he would rather have his own custom program instead of dealing with the terminology and handling differences among CDs and DVDs. We recommended that if he decides to expand into selling CDs, we should investigate retail sales systems. A lot of functionality already exists in those systems that should not be re-created. If a preexisting solution fits into the overall system, at least that part of the wheel need not be recreated. [ ]

[ ] See Software Tools by Brian W. Kernighan (Addison-Wesley Professional, 1976) for the earliest discussion I have found on the issue of using tools to create solutions.

DON'T REINVENT THE WHEEL

Look for existing solutions to problems before creating new solutions.


Since Sam wants us to develop a custom system, Tim and I start to analyze the problem. We need to outline the concepts involved in the problem and clarify our understanding of what needs to be solved .

 <  Day Day Up  >  
 <  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  >