Up or down?
I'm a very visual person. I'm thinking of my application as a hierarchy, where the top is the root and the bottom is a leaf.
I'm also under the understanding that, in DI systems, containers are ignorant of their contained objects' responsibilities/functions. Instead, the contained objects know about their context because the context (a dependency) is injected in.
UP: (The non-DI way?)
Should my events be dispatched from the bottom of my hierarchy and bubble upwards to their parents? E.g. a button in my GUI dispatches a CLICKED
event, which is caught by a listening container that responds by carrying out the appropriate action.
DOWN: (The DI way?)
Should my events be dispatched from the top of my hierarchy by a parent that its children listen to? E.g. --... ok, i'm having trouble coming up with this. I'm thinking along the lines of a Mediator that dispatches events for contained objects.
'Up' seems natural to me, but since DI has a container being unaware of its contained objects' behavior, I wouldn't want to respond to their events.
EDIT (to clarify):
I realize it's POSSIBLE to have nearly any part of a system listen to an event, but I want to understand the fundamental relationship between DI participants, so I can structure them properly. I'm assuming people don't usually just scatter events about their program without regard to structural relationships, dependencies, etc.
My question arises from the responsibility placement in a DI system -- it's the injected object's responsibility to make calls on the injector and the injector's reponsibility to provide services to its dependent objects (which inverts the non-DI paradigm -- hence synonyms like "Inversion of Control" and "Dependency Inversion"). This seems to be a very important, fundamental component of DI -- a shifting of responsibilities. I consider calling an object's functions or listening to its events to BOTH be examples of depending on another object. When an object defines its own behavior based on another object, I call that a dependency because one object KNOWS of the other and also KNOWS what the other does. It has defined itself within the context of the other object. As I understand, DI is set up so that the injected object is dependent on the injector, so it should be the injected object's responsiblity to know all about the injector. And it should NOT be the injector's responsiblity to know about the injected object. So, for the injector to be listening to events on the CONTAINED injected object seems to me like like a misplacement of responsibilities because that means it knows something about its contents.
Please tell me if and how this is wrong.