javascript - Law of Demeter/single responsibility when events are involved -
I am trying to resolve the law of dementors for programming environments where incidents are involved - I used this JavaScript and OBJ- C is tagged in Coca's NSNotificationCenter) because both events allow for.
In such an environment, you can only tap them and tie up / subscribe events. Instead of going through the context of that object in OBJ-C, it may be easy to do this, on which you need to apply a method. I'm thinking that maybe it's not always good to use: On the display's perspective, you miss on optimization for a dispatch of the method (possibly unless it is not a big app). A programmer for readability may want to make it clear that one object is dependent on another, which is not clear when an object only throws events.
I should have some idea about the role of events in software architecture: how do you want to balance the cost of event binding and direct method?
Be careful, your terminology "Event" in the GUI context often means that users were generated Events, such as mouse clicks, tap, key press, etc., and these types of incidents are usually not used that you are referring to. In cocoa and coco-touch, the user is handled using events.
Both patterns promote loose coupling between objects, but coupling in the supervisor is definitely weak. Objects participating in a series of responsibilities generally pass by all common base classes or otherwise correspond to some common interfaces, and each object in the series is usually aware of its neighbors in the series. With the supervisor, sending an object message (such as a notification in cocoa) is not known how a message can be received by objects, and the object receiving the message usually does not know where it came from. Especially in the Cocoa and NS Annotification Center, there is also not a common interface - each "supervisor" registers a notification handler to receive the object notification.
You can make a lot of confusion with the supervisor pattern if you overuse it, it can be very difficult to debug the confusion of messages, even worse if the messages are supervised by the synchronous (and they usually ), Then the message to send is no way of knowing how to send this message, and the object receiving the message has no meaning. That is, they can affect your performing remaining apps fact that makes it easy to create real performance issues with the number of observers to any message is usually limitless, making mistakes. Demeter advocates' laws on their tongue, they say, "I said to you," but that does not mean that you should avoid the supervisor. With proper understanding and understanding that supervisors should not take too much weight in response to any message, patterns are a powerful way to give information on those places where it is needed, and it eliminates the need for many people by eliminating the need for code Relationships between objects can be easy to make.
Comments
Post a Comment