A Sample Visual Class—Stopwatch

Objects model the real world. Before we can create a stop watch object, we need to determine what the object is and what it does.

Consider a stop watch. If you happen to have one, take it out and look at it. Note that it has a display (usually showing the time elapsed in HH:MM:SS.SS format. The stop watch has buttons that allow you to start it, stop it, pause it (lap time) and reset the display.

Naturally, a stop watch has the ability to track time from when it is started until it is stopped.

This gives us a good list of the functionality a stop watch class would have.

Once you have the required behavior of the object, you can then work on designing the implementation of the class.

Many factors can affect how a class is implemented ranging from how the class is intended to be used to personal preference of the developer.

In this case, when designing the implementation of the Stop Watch class, the functionality is divided into two parts. The first is the engine (the portion of the stop watch that has the functionality for calculating the time, starting, stopping and pausing the stopwatch. The second class combines the engine with the display to create a full stop watch.