From my understanding a facade is a class with the sole purpose of simplifying the use of a specific system/module behavior (its methods). It should not contain any relevant logic of the underlying system, just centralize and simplify its use.
My questions is: how to create a facade (ie. simplify and centralize) of a system/module with events?
As far as I can understand it would make perfect sense to centralize the events of the system/module too. Hence all the user of that system has to do in order to understand how to use it is analyze its facade(s)'s interface(s). What I'm suggesting is something like the following (C#) code.
public class Facade
{
// Fields
public event EventHandler event1;
public event EventHandler<string> event2;
public event EventHandler event3;
public event EventHandler<int> event4;
// ...
public Facade(SystemEventBus eventBus/*, underlying sub-systems references */)
{
// Subscribe to the sub-systems events, for instance using the system's event bus:
eventBus.Subscribe<OnSomethingHappened>(OnSomethingHappened);
}
// Facade public methods
// Internal Events Handling
private void OnSomethingHappened()
{
event1?.Invoke(this, EventArgs.Empty);
}
}
Although it feels odd to me, I can't argue against it. If we are already doing a facade with the purpose of centralizing and simplifying a system interface, it is logic to me that the events make part of that too. The goal should be the user being able to do everything related to using a system, solely through a facade.
Does that break any clean code rule? Is this even correct? Is there a better way to deal with the problem I described?