It's said that circular dependencies are bad and anti-patterns. So my question is what's wrong with the code below? Is it an example of circular dependency at all? The code is in python pseudocode but should be understood.
class Manager:
_handlers = []
def on_config(self):
# do something...
# and notify about "event"
for handler in self._handlers:
handler()
def add_change_handler(self, handler):
self._handlers.append(handler)
def get_value(self):
return some_value
class Consumer:
def __init__(self, manager):
self._manager = manager
self._manager.add_change_handler(self._on_event)
def _on_change(self):
print('Got event')
def do_something(self):
self._manager.get_value()
So: Consumer gets manager to:
- get_value from it
- to register for litening on change event
The argument from guys that are against that solution is that it's better to create other class, that will:
- know about manager and consumer
- listen on config event
- call consumer's on_change handler
- Consumer will use manager only to get_value