Instead of subclassing ContinuousWorker (e.g. EventStreamWatcher and ChallengeStreamWatcher), have ContinuousWorker require a WorkBehavior instance that is then called inside the ContinuousWorker.run() function, resulting in:
def __init__(self, work_behavior):
self.work_behavior = work_behavior
def run(self):
while not self.terminate_flag.is_set():
self.work_behavior.work()
where WorkBehavior is an abstract class acting as an interface, and then subclass this class as new behaviors prop up for continuous workers. So we would have a EventStreamWorkBehavior and a ChallengeStreamWorkBehavior, which implement the WorkBehavior interface, and these behaviors get passed into ContinuousWorker.
This is opposed to what we currently do where EventStreamWorker and ChallengeStreamWorker are children of ContinuousWorker. This new approach will adhere better to SOLID principles sine we're favoring composition (and therefore dependency injection) over inheritance.
Instead of subclassing
ContinuousWorker
(e.g.EventStreamWatcher
andChallengeStreamWatcher
), haveContinuousWorker
require aWorkBehavior
instance that is then called inside theContinuousWorker.run()
function, resulting in:where
WorkBehavior
is an abstract class acting as an interface, and then subclass this class as new behaviors prop up for continuous workers. So we would have aEventStreamWorkBehavior
and aChallengeStreamWorkBehavior
, which implement theWorkBehavior
interface, and these behaviors get passed intoContinuousWorker
.This is opposed to what we currently do where
EventStreamWorker
andChallengeStreamWorker
are children ofContinuousWorker
. This new approach will adhere better to SOLID principles sine we're favoring composition (and therefore dependency injection) over inheritance.