Question: Consider three alternative designs for a simple program called EggTimer. This program counts down seconds given to it as a parameter and dings or beeps
Consider three alternative designs for a simple program called EggTimer. This program counts down seconds given to it as a parameter and dings or beeps when time is up. More specifically, the EggTimer program must take a single integer value on the command line. It must interpret this value as the number of seconds to count down until dinging or beeping the computer. The EggTimer program must display the number of seconds left as it counts down. The first version of the program must display its output on the command line. Later versions must open a GUI window and display the countdown there.
The following figure shows three alternative designs for EggTimer. The diagrams are UML class diagrams.
Alternative A uses a Pulse class to notify (or tick) the EggTimer class every second. The EggTimer calls TimeDisplay.show() to display the number of seconds left. The TimeDisplay dings or beeps the computer when seconds reach 0.
Alternative B replaces the Pulse class with the java.util.Timer class. Instances of this class call the run() operation in a java.util.TimerTask object at regular time intervals (like every second). In this design, the run() operation in EggTimer calls TimeDisplay.show() to display the time.
Alternative C retains the java.util classes from alternative B but changes the way that the TimeDisplay class works. In this alternative The EggTimer is a subclass of Subject. A Subject class keeps a list of observing objects. Every time its notifyObservers() operation is called it calls every observers update() operation. When EggTimer begins, it creates a TimeDisplay object and adds it as an observer of EggTimer. When EggTimer.run() executes, it calls notifyObservers(), which in turn calls TimeDisplay.update(). This operation calls EggTimer.getSecond() to get the time left and display it.

1a) Evaluate each of the EggTimer design alternatives with respect to the Design Concepts of Abstraction, Seperation of Concerns, Modularity, Information Hiding, Coupling and Cohesion. Rate each alternative as good, bad, or ok for each concept.
1b) What are the relative strengths and weaknesses of these alternatives in comparison with one another?
Alternative A EggTimer TimeDisplay | displays | seconds : int = 0 | ticks show(sec int) Pulse main() tick(l Alternative B java::util: TimerTask run) EggTimer | seconds : int = 0 TimeDisplay | displays notifies java:util::Timer show(sec: int) main() Alternative C java:util: :TimerTask notifies java::util: Timer run(0 EggTimer seconds : int 0 main() getSeconds(): int TimeDisplay Observer notifies observers update() Subject addObserver Observer o) notifyObservers()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
