Lab: Refactoring the Talking Robot

Making the Robot More Object-Oriented



Responsibility, Design, and State

Introduction

One of the most important tasks in designing and implementing object-oriented programs is deciding which classes or objects are responsible for executing which behavior.

In the Talking Robot lab and programming project, you created two programs that simulated a talking robot. The first interacted with a clock object, while the second interacted with a speech-to-text listener. In this lab, you will combine these two programs, creating a Talking Robot class that has a clock and a random number generator as part of its included features (as part of its state), and that has three methods, getTimestamp, sayAPhrase, and respondTo, that implement much of the functionality of your first two programs. You will also create a single main class that will construct the key objects and run various tests.

This process of improving a program's design without changing its functionality is called refactoring. To verify that the functionality is unchanged, you should do regression testing, running the same tests that you ran on the program originally to check that the results are the same.

As in previous labs and projects, develop your changes incrementally as you go.

Creating a Talking Robot class

Refactoring: moving the functionality of Lab 2

More Refactoring: Adding the functionality of the Programming Project



Copyright Alyce Faulstich Brady, 2009, 2016.