|
|
|
|
|
|
|
One way to approach this problem is to set aside issues relating to the user interface and to focus only on the components of the problem space. |
|
|
|
|
|
|
|
|
New Term: The problem space is the set of problems and issues your program is trying to solve. The solution space is the set of possible solutions to the problems. |
|
|
|
|
|
|
|
|
As your high-level design evolves you'll want to begin thinking about the responsibilities of the objects you identifywhat they do and what information they hold. You also want to think about their collaborationswhat objects they interact with. |
|
|
|
|
|
|
|
|
For example, clearly you have sensors of various types, a central alarm system, buttons, wires, and telephones. Further thought convinces you that you must also simulate rooms, perhaps floors, and possibly groups of people such as owners and police. |
|
|
|
|
|
|
|
|
The sensors can be divided into motion detectors, trip wires, sound detectors, smoke detectors, and so forth. All these are types of sensors, although there is no such thing as a sensor per se. This is a good indication that sensor is an abstract data type (ADT). |
|
|
|
|
|
|
|
|
As an ADT, the class Sensor would provide the complete interface for all types of sensors, and each derived type would provide the implementation. Clients of the various sensors would use them without regard to which type of sensor they are, and they would each do the right thing based on their real type. |
|
|
|
|
|
|
|
|
To create a good ADT, you need to have a complete understanding of what sensors do (rather than how they work). For example, are sensors passive devices or are they active? Do they wait for some element to heat up, a wire to break, or a piece of caulk to melt, or do they probe their environment? Perhaps some sensors have only a binary state (alarm state or OK) but others have a more analog state (what is the current temperature?). The interface to the abstract data type should be sufficiently complete to handle all the anticipated needs of the myriad derived classes. |
|
|
|
|
|
|
|
|
The design continues in this way, teasing out the various other classes that will be required to meet the specification. For example, if a log is to be kept, probably a timer will be needed; should the timer poll each sensor, or should each sensor file its own report periodically? |
|
|
|
|
|
|
|
|
The user is going to need to be able to set up, disarm, and program the system, so a terminal of some sort will be required. You might want a separate object in your simulation for the alarm program itself. |
|
|
|
|
|