Chapter 3. Requirements Change: I Love You, You’re Perfect... Now Change

image with no caption

Think you’ve got just what the customer wanted? Not so fast... So you’ve talked to your customer, gathered requirements, written out your use cases, and delivered a killer application. It’s time for a nice relaxing cocktail, right? Right... until your customer decides that they really wanted something different than what they told you. They love what you’ve done, really, but it’s not quite good enough anymore. In the real world, requirements are always changing, and it’s up to you to roll with these changes and keep your customer satisfied.

You’re a hero!

A nice piña colada to sip on, the sun shining down on you, a roll of hundred dollar bills stuffed into your swim trunks... this is the life of a programmer who’s just made Doug’s Dog Doors a successful venture. The door you built for Todd and Gina was a huge success, and now Doug’s selling it to customers all across the world.

image with no caption

But then came a phone call...

image with no caption

You: Oh, has something gone wrong?

Todd and Gina: No, not at all. The door works just like you said it would.

You: But there must be a problem, right? Is the door not closing quickly enough? Is the button on the remote not functioning?

Todd and Gina: No, really... it’s working just as well as the day you installed it and showed everything to us.

You: Is Fido not barking to be let out anymore? Oh, have you checked the batteries in the remote?

Todd and Gina: No, we swear, the door is great. We just have a few ideas about some changes we’d like you to make...

You: But if everything is working, then what’s the problem?

image with no caption

Back to the drawing board

Time to get working on fixing up Todd and Gina’s dog door again. We need to figure out a way to open the door whenever Fido barks. Let’s start out by...

image with no caption

The customer is always right

Even when requirements change, you’ve got to be ready to update your application and make sure it works like your customers expect. When your customer has a new need, it’s up to you to change your applications to meet those new needs.

Note

Doug loves it when this happens, since he gets to charge Todd and Gina for the changes you make.

Brain Power

You’ve just discovered the one constant in software analysis and design. What do you think that constant is?

The one constant in software analysis and design[1]

Okay, what’s the one thing you can always count on in writing software?

No matter where you work, what you’re building, or what language you are programming in, what’s the one true constant that will always be with you?

image with no caption

(use a mirror to see the answer)

No matter how well you design an application, over time the application will always grow and change. You’ll discover new solutions to problems, programming languages will evolve, or your friendly customers will come up with crazy new requirements that force you to “fix” working applications.

Requirements always change. If you’ve got good use cases, though, you can usually change your software quickly to adjust to those new requirements.

image with no caption

Optional Path? Alternate Path? Who can tell?

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

Use cases have to make sense to you

If a use case is confusing to you, you can simply rewrite it. There are tons of different ways that people write use cases, but the important thing is that it makes sense to you, your team, and the people you have to explain it to. So let’s rewrite the use case from page 121 so it’s not so confusing.

image with no caption
image with no caption

Excellent idea!

The main path should be what you want to have happen most of the time. Since Todd and Gina probably want the bark recognizer to handle Fido more than they want to use the remote, let’s put those steps on the main path:

image with no caption

Start to finish: a single scenario

With all the alternate paths in the new use case, there are lots of different ways to get Fido outside to use the bathroom, and then back in again. Here’s one particular path through the use case:

image with no caption

Let’s get ready to code...

Now that our use case is finished up, and we’ve figured out all the possible scenarios for using the dog door, we’re ready to write code to handle Todd and Gina’s new requirements. Let’s figure out what we need to do...

image with no caption

Any time you change your use case, you need to go back and check your requirements.

Remember, the whole point of a good use case is to get good requirements. If your use case changes, that may mean that your requirements change, too. Let’s review the requirements and see if we need to add anything to them.

Todd and Gina’s Dog Door, version 2.2

Requirements List

  1. The dog door opening must be at least 12” tall.

  2. A button on the remote control opens the dog door if the door is closed, and closes the dog door if the door is open.

  3. Once the dog door has opened, it should close automatically if the door isn’t already closed.

Note

Go ahead and write in any additional requirements that you’ve discovered working through the scenarios for the new dog door in Sharpen your pencil answers.

Finishing up the requirements list

So we need to handle the two new alternate paths by adding a couple extra requirements to our requirements list. We’ve gone ahead and crossed off the steps that our requirements already handle, and it looks like we need a few additions to our requirements list:

image with no caption

Now we can start coding the dog door again

With new requirements comes new code. We need some barking, a bark recognizer to listen for barking, and then a dog door to open up:

image with no caption

Was that a “woof” I heard?

We need some software to run when Doug’s hardware “hears” a bark. Let’s create a BarkRecognizer class, and write a method that we can use to respond to barks:

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

First, let’s make sure we’ve taken care of Todd and Gina’s new requirements for their door:

image with no caption

Power up the new dog door

Use cases, requirements, and code have all led up to this. Let’s see if everything works like it should.

  1. Update the DogDoorSimulator source code:

    image with no caption
    image with no caption

    Note

    * The authors of this book sincerely wanted to include hardware that could hear dogs barking... but marketing insists that nobody would buy a book priced at $299.95. Go figure!

  2. Recompile all your Java source code into classes.

    image with no caption
  3. Run the code and watch the humanless dog door go into action.

    image with no caption

Brain Power

There’s a big problem with our code, and it shows up in the simulator. Can you figure out what the problem is? What would you do to fix it?

Brain Power

There’s a big problem with our code, and it shows up in the simulator. Can you figure out what the problem is? What would you do to fix it?

Note

Did you figure out what was wrong with our latest version of the dog door?

In our new version of the dog door, the door doesn’t automatically close!

In the scenarios where Todd and Gina press the button on the remote control, here’s the code that runs:

image with no caption

But in BarkRecognizer, we open the door, and never close it:

image with no caption
image with no caption

What do YOU think about Doug’s idea?

image with no caption

Duplicate code is a bad idea. But where should the code that closes the door go?

image with no caption

Let’s have the dog door close automatically all the time.

Since Gina never wants the dog door left open, the dog door should always close automatically. So we can move the code to close the door automatically into the DogDoor class. Then, no matter what opens the door, it will always close itself.

Note

Even though this is a design decision, it’s part of getting the software to work like the customer wants it to. Remember, it’s OK to use good design as you’re working on your system’s functionality.

Updating the dog door

Let’s take the code that closed the door from the Remote class, and put it into our DogDoor code:

image with no caption
image with no caption

Simplifying the remote control

You’ll need to take this same code out of Remote now, since the dog door handles automatically closing itself:

image with no caption

A final test drive

You’ve made a lot of changes to Todd and Gina’s dog door since they first called you up. Let’s test things out and see if everything works. Make the changes to Remote.java and DogDoor.java so that the door closes itself, compile all your classes again, and run the simulator:

image with no caption

Brain Power

What would happen if Todd and Gina decided they wanted the door to stay open longer? Or to close more quickly? See if you can think of a way to change the DogDoor so that the amount of time that passes before the door automatically closes can be set by the customer.

Sometimes a change in requirements reveals problems with your system that you didn’t even know were there.

Change is constant, and your system should always improve every time you work on it.

More Tools for your OOA&D Toolbox

You’ve learned a lot in this chapter, and now it’s time to add what you’ve picked up to your OOA&D toolbox. Review what you’ve learned on this page, and then get ready to put it all to use in the OOA&D cross on the next page.

image with no caption


[1] If you’ve read Head First Design Patterns, this page might look a bit familiar. They did such a good job describing change that we decided to just rip off their ideas, and just CHANGE a few things here and there. Thanks, Beth and Eric!

    Reset