Intermediate level task for practice events.
Estimated time to complete the task - 1h.
The task requires .NET 6 SDK installed.
-
You need to implement the
Timer
class for simulating a countdown clock. The Timer has the ability to send out messages with the information aboutStarted
,Tick
andStopped
events to other types subscribed to the events. UseAction<>
delegates as event handler delegates. Don't use the .NET System. Timer classes for the Timer implementation. -
The
Timer
class should have the following functionality:- When an object of the
Timer
class is constructed it has to be assigned:- Name (not a null or an empty string, otherwise the exception
ArgumentException
should be thrown); - Number of ticks (the number has to be greater than 0; otherwise, the exception
ArgumentException
should be thrown).
- Name (not a null or an empty string, otherwise the exception
- After the Timer has been created it should be called to Run. In response to Run, the Timer fires the
Started
event. The event should contain the information about the Timer's Name and the Number of ticks to be fired. - After firing the
Started
event, the Timer starts firingTick
events with the information abount the Timer's name and the number of ticks left to fire. There should be delays between theTick
events. To emulate the delays between theTick
events, it is recommended to use theThread.Sleep
method. - After all
Tick
events have been fired, the Timer has to fireStopped
event, the event should contain the Timer's name information.
- When an object of the
-
You need to complete the implementation of the
CountDownNotifier
class. This class consumes events from theTimer
. The implementation logic must check that when the object ofCountDownNotifier
class is created, thenull
is not passed as a parameter insted of theTimer
object. -
Provide the implementation of the Factory methods (see Factory method theory) to create objects of the
Timer
andCountDownNotifier
classes.