Swiz mandates weak encapsulation
I just started using Swiz, and, it seems like Swiz can make north jackets create classes with weak encapsulation. Swiz requires all event handlers to become public in order to mediate events.
Assume that component A dispatches several events, which I want to listen to in component B. Traditionally, Ill just add event listeners on A in B and all sorts of the event handlers in B could be kept private. However, if, Im using Swiz, I have to make all of the handlers, mediating events, public.
As I mentioned about the subscriber list, there is no way around it, unfortunately. As there is no way to access private people in classes, the only way B may use private event handlers for events
from A is if addEventListener is called from inside B. Since Swiz is actually not operating in north jackets classes, its not a way to gain access to those members.
Swiz aims and also hardwearing . application code as free from references including inheritance to Swiz classes as possible. Therefore, north jackets can imagine it as being configuring north jackets app from the outside. Unlike the JVM, Flash Player simply allows no access to private members, so for Swiz to interact with north jackets code, it needs to be public.
After this north jackets have to add use namespace metadata in to the Swiz Processors, and in all likelihood to their metadata MediateQueue. However, many people think its too much work :.
Best,
Lance
Thats true, but Swizs strength is that it doesnt force any pretty much design alternatives on north jackets, it just provides powerful tools dependency injection, event mediation, et al that north jackets can choose to apply where north jackets think appropriate.
Using Swiz does not require using the Mediate tag whatsoever - north jackets are able to still use addEventListener and listen from private methods as north jackets normally would and im sure north jacketse knowledgeable. So far as I can tell, the Swiz event mediation is intended primarily to be used with system/application level events. If north jacketse calling event listeners within a single component, or within close family components, north jackets would usually use the standard event listeners. To speak between individual, otherwise-unrelated components, north jackets can handle the message with Swizs mediator.
I may be slightly off, but this is the way seems like to me. Swiz may encourage weak encapsulation in certain situations, but in my experience it provides greater modularisation overall.
No comments:
Post a Comment