Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider three alternative designs for a simple program called EggTimer. This pr

ID: 3730124 • Letter: C

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 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 observer’s 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()

Explanation / Answer

1a) Evaluate each of the EggTimer design alternatives with respect to the Design Concepts

Alternate A

Abstraction

1. This design pattern doesnot provide any anstraction since all the entities(classes) are directly exposed to each other.

So any change in 1 or more classes can cause a potential change in all other classes.

Seperation of Concerns

1. This pattern is OK for the separation of cocerns.

The job of EggTimer is to maintain the seconds and maion method.

The job of TimeDisplay is to show the time

The job if pulse is to give the ticks

Here The task of showing time and ringing beep can again be distributed.

Modularity

Here, the classes are moduler. Ofcourse,we can modify the contents of each class but can not modify or append more functionality

without changing all codes.

Hence it can be more modular

Information Hiding

The classes does not hides any information from any other class. Hence it is poor in this design principle.

Coupling

The classes are tightly copouled as same property is being used by all three classes. Hence any change in property in 1 of the classes can affect all classes.

Hence the classes are tightly copouled.

Rating(Good, OK and Bad )

Overall between BAD and OK, Not BAD but Not OK also.

Overall BAD can be considered.

Alternate B

Abstraction

1. This design pattern provides some level of abstraction as it uses an inbuilt java library, which can not change

and other classes have to take this contract and work on the contract basis.If anything changes in the contract then the things

affecting this will need to be changed.

Seperation of Concerns

1. This pattern is also good in terms of separation of cocerns patterns

The job of EggTimer is to maintain the seconds and maion method.

The job of TimeDisplay is to show the time

To get the ticks it uses java:util: TimerTask whose concern is to get the ticks done

Here also The task of showing time and ringing beep can again be distributed.

Modularity

The class TimerTask can be modified separately, without affecting the code. Hence the code is somewhat better in terms of modularity.

But again, TimeDisplay class can not be modified without affecting main class

Information Hiding

The information in Util class is hidden properly but the code in TimeDisplay class are not hidden, Main class can access the code of TimeDisplay and modify it.

Coupling

This design pattern si moderate in terms of coupling as it is not tightly coupled with Java:util library so that can be easily detached

and some other class can be used but when it comes to TimeDisplay class, it is again tightly coupled.

Rating(Good, OK and Bad )

Overall Design can be marked OK based on the above discussed points.

Alternate C

Abstraction

1. This design pattern provides more level of abstraction since all classes are connected by the abstraction.

EggTimer uses abstration of TimerTask and uses Suject to detect the change.

Hence it is more advantageous

Seperation of Concerns

1. This pattern is also good in terms of separation of cocerns patterns

The job of EggTimer is to maintain the seconds and maion method.

The subject class is used to observe the changes which is again a good design technique.

To get the ticks it uses java:util: TimerTask whose concern is to get the ticks done.

TimeDisplay utilieses observer to display the time

Hence the concerns are properly separated.

Modularity

Here, in this design pattern, all 3 classes are modular as none of them are dependent on each other.

Java:Util:TimerTask is lirbary which can be modified separately.

Again TimeDisplay is also not connected directly to main EggTimer class so it can again be modified separately.

Information Hiding

The information of each class is properly hidden and cannot be directly accessible to other class which is good design principle.

Coupling

The 3 classes are loosely coupled as none of them are dependent on each other can be replaced by other component

Rating(Good, OK and Bad )

Based on the above mentioned design principles, it is GOOD example of utilising design pattern.

1b) What are the relative strengths and weaknesses of these alternatives in comparison with one another?

Alternate A

Strength :

1. Simple Deisgn - Easy to understand and implement.

2. Can be designed as single component.

Weakness :

1. Tightly coupled and non modular : Cannot be modified or maintained easliy. Each time entire design has to be analysed for small change.

2. Information Hiding : The classes doesnot hide the information from other class, hence can be modified easily which is not good.

Alternate B :

Strength :

1. Moderate Deisgn - Easy to understand and implement and yet following most of the design principles.

2. Can be managed properly. External component can be integrated upto some extent.

Weakness :

1. Tightly coupled with TimeDisplay class : Every Change in TimeDisplay class can bring a lot of change in main class as they are tightly coupled.

2. Can be modified for Separation of concerns : TimeDisplay can be modifed to display the time only and change in time can be clacluated by other class that needs to be implemented.

Alternate C :

Strength :

1. Modular Design, Loosely coupled - Good example of modular design and the pattern is loosely coupled as mentioned above.

2. Information Hiding : The observer class is used to detect any change in main class which does not need to be shown to TimeDisplay class.

Weakness :

1. Deisgn becomes a bit complex.

2. Can be deisgned completely based on cotracts(following abstraction pattern)

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////