Chapter 2. Gathering Requirements: Give Them What They Want

image with no caption

Everybody loves a satisfied customer. You already know that the first step in writing great software is making sure it does what the customer wants it to. But how do you figure out what a customer really wants? And how do you make sure that the customer even knows what they really want? That’s where good requirements come in, and in this chapter, you’re going to learn how to satisfy your customer by making sure what you deliver is actually what they asked for. By the time you’re done, all of your projects will be “satisfaction guaranteed,” and you’ll be well on your way to writing great software, every time.

You’ve got a new programming gig

You’ve just been hired as the lead programmer at a new start-up, Doug’s Dog Doors. Doug’s got a pretty high-tech door under development, and he’s decided you’re the programmer that can write all the software to make his killer hardware work.

image with no caption

Todd and Gina: your first customer

Todd and Gina want more than a “normal” doggie door. Todd has everything from his plasma TV to his surround sound stereo to his garage door operating off of a remote control, and he wants a dog door that responds to the press of a button. Not satisfied with a little plastic flap letting their dog in and out, they’ve given Doug’s Dog Doors a call... and now Doug wants you to build them the dog door of their dreams.

Let’s start with the dog door

The first thing we need is a class to represent the dog door. Let’s call this class DogDoor, and add just a few simple methods:

image with no caption

Test drive

Let’s see if everything works. Go ahead and take your new dog door for a test drive.

  1. Create a class to test the door (DogDoorSimulator.java).

    image with no caption
  2. Compile all your Java source code into classes.

    image with no caption
  3. Run the code!

    image with no caption

But when Gina tried it...

image with no caption
image with no caption

But the door doesn’t work the way Todd and Gina want it to!

Todd and Gina didn’t expect to have to close the dog door, so they pressed the button on the remote only once: to let Fido out.

Even worse, in this case, the way they used the door created new problems. Rats and rabbits started coming into their house through the open door, and you’re taking the blame.

Let’s tackle Todd and Gina’s dog door again, but this time, we’ll do things a little bit differently. Here’s our plan:

image with no caption

So what exactly is a requirement, anyway?

image with no caption

Listen to the customer

When it comes to requirements, the best thing you can do is let the customer talk. And pay attention to what the system needs to do; you can figure out how the system will do those things later.

image with no caption

Gina: And we want the door to automatically close after a few seconds. I don’t want to have to wake back up in the middle of the night to close the door.

You: Do you want a single button on the remote, or both an “Open” and “Close” button?

Todd: Well, if the door always closes automatically, we really don’t need separate “Open” and “Close” buttons, do we? Let’s just stick with a single button on the remote control.

You: Sure. So the button opens the door if it’s closed, and it can also close the door if it’s open, just in case the door gets stuck.

Note

Don’t worry about your code at this stage-just make sure you know what the system should do.

Todd: Perfect. Gina, anything else you can think of?

Gina: No, I think that’s it. That’s the dog door of our dreams.

image with no caption

Creating a requirements list

Now that we know what Todd and Gina want, let’s write down our new set of requirements. We don’t need anything too fancy...

image with no caption
image with no caption

You need to understand how the dog door will be used.

You’ve figured out one of the hardest parts about getting a customer’s requirements—sometimes even the customer doesn’t know what they really want! So you’ve got to ask the customer questions to figure out what they want before you can determine exactly what the system should do. Then, you can begin to think beyond what your customers asked for and anticipate their needs, even before they realize they have a problem.

Note

In Todd and Gina’s case, the system is the dog door and the remote control.

What does the dog door really need to do?

You know what Todd and Gina want the dog door to do, but it’s your job to make sure that the door actually works. In the process, you may even come across some things that Todd and Gina want, but didn’t think about on their own.

Let’s write down exactly what happens when Fido needs to go outside:

image with no caption

Plan for things going wrong

Below is a diagram of how Todd and Gina’s dog door should work; all the numbers match up with the steps in our list in What does the dog door really need to do?. But things aren’t always going to go according to plan, so we’ve written down some things that might go wrong along the way.

image with no caption

Alternate paths handle system problems

Now that you’ve figured out some of the things that can go wrong, you need to update your list of things that needs to happen to make the dog door work. Let’s write down what should happen if the door closes before Fido gets back inside.

image with no caption
image with no caption

Yes! You’ve been writing use cases all along

When you wrote down the steps in getting Fido outside to use the bathroom, you were actually writing a use case.

A use case is what people call the steps that a system takes to make something happen. In Todd and Gina’s case, the “something” that needs to happen is getting Fido outside to do his business, and then back inside.

image with no caption

(Re) introducing use cases

You’ve been writing a use case for almost 10 pages now, but let’s take a closer look at exactly what that list of steps—the use case for Todd and Gina’s dog door—is really all about:

image with no caption
image with no caption

One use case, three parts

There are three basic parts to a good use case, and you need all three if your use case is going to get the job done.

image with no caption
image with no caption

Checking your requirements against your use cases

So far, you’ve got an initial set of requirements and a good solid use case. But now you need to go back to your requirements and make sure that they’ll cover everything your system has to do. And that’s where the use case comes in:

image with no caption

Is anything missing?

Now you need to look over the use case and see if everything the system needs to do is covered by the requirements.

image with no caption

So now can we write some code?

With use case and requirements in hand, you’re ready to write code that you know will make Todd and Gina satisfied customers. Let’s check out our requirements and see exactly what we’re going to have to write code for:

image with no caption
image with no caption

Automatically closing the door

The only requirement left to code is taking care of automatically closing the door after it’s been opened. Let’s go back to our Remote class and handle that now:

image with no caption
image with no caption

We need a new simulator!

Our old simulator isn’t that useful anymore... it assumes Todd and Gina are closing the door manually, and not letting the timer do its work. Let’s update our simulator to make it work with the updated Remote class:t

image with no caption
image with no caption

Test drive, version 2.0

It’s time to see if all our hard work is going to pay off. Let’s test out the new and improved dog door.

  1. Compile all your Java source code into classes.

    image with no caption
  2. Run the code!

    image with no caption

It works! Let’s go show Todd and Gina...

image with no caption

Good catch... we need to test alternate paths as well as the main path.

Wouldn’t it be great if things worked just like you expected them to every time? Of course, in the real world, that almost never happens. Before we can show the new door off to Todd and Gina, let’s take a little extra time to make sure the door works when Fido doesn’t come right back inside after doing his business.

Your system must work in the real world...

...so plan and test for when things go wrong.

Brain Power

How would you change the DogDoorSimulator class to test for Fido staying outside longer?

Super Brain Power

Can you come up with at least one more alternate path for Todd and Gina’s dog door? Write out the use case and update the requirements list for your new alternate path, too.

Reviewing the alternate path

Let’s make sure we understand exactly what happens on the alternate path, and then we can update DogDoorSimulator to test the new path out. Here’s the original main path diagram from Plan for things going wrong, along with the alternate path we figured out and added to our use case:

image with no caption
image with no caption

Test drive, version 2.1

Make the changes to your copy of DogDoorSimulator.java, and then recompile your test class. Now you’re ready to test out the alternate path of your use case:

image with no caption

Delivering the new dog door

Good use cases, requirements, main paths, alternate paths, and a working simulator; we’re definitely on the road to great software. Let’s take the new dog door to Todd and Gina.

image with no caption

Working app, happy customers

Not only did we turn Todd and Gina into satisfied customers, we made sure their door worked when Fido did something they didn’t expect—like stay outside playing.

Exercise Solutions

image with no caption
image with no caption
image with no caption

John and Tex’s Dog Door

Primary Actor: Tex

Secondary Actor: John

Preconditions: The dog door is open for Tex to go outside.

Goal: Tex uses the bathroom and comes back inside, without getting mud inside the house.

Main Path

  1. Tex goes outside.

  2. The dog door closes automatically.

  3. Tex does his business.

  4. John presses a button.

  5. The dog door opens.

  6. Tex comes back inside.

  7. The door closes automatically.

Extensions

3.1 Tex gets muddy.

3.2 John cleans Tex up.

Answers in Use Case Magnets Solutions.

image with no caption
image with no caption
    Reset