¿Cómo se exponen los eventos envueltos por una clase de fachada?

Considere la siguiente estructura:

Class A: Method A - Fires Event A
Class B: Method B - Fires Event B
Class C: Method C - Fires Event C

Facade: Method ABC (calls method A, B and C), Fires Event A, B and C.

How do you expose events A, B and C? Do you bubble up the event from A, B and C? Do you create another event? Do you expose classes A, B and C and let the client code subscribe to the event?

preguntado el 08 de noviembre de 11 a las 09:11

2 Respuestas

I think you should not expose classes A, B and C, as it breaks the main point of Facade - hiding those classes behind an API, and making code using facade independent of them.

For the same reason, I don't think bubbling the events from A, B and C would be a good choice, although I would consider it if those events were on right level of abstaction and not coupled too tightly with classes A, B and C.

If the events were closely coupled with classes hidden behind a Facade, or too low-level in comparison to the facade API, I think I would roll my own events, possibly wrapping original ones.

respondido 08 nov., 11:13

I think it depends on the type of events, and were they're defined. If they are "global" events, then any listeners don't mind if they are getting the Facade or implementation class, probably.

In languages like C# you define your event signature (delegate), and you should define any relevant parameters as interfaces, so their implementation is 'irrellevant' to any listeners.

If this is impossible, or the listeners depend heavily on the "implementation", I'd go for wrapping the event rather than bubbling them.

respondido 08 nov., 11:13

By wrapping, you mean "catching" the event, "wrap" it then throw the wrapped event? - Ian

Yes. Because (only) then the implementation is hidden to any listeners. - Grad van Horck

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.