8) EventCollector and MVC

When you are designing an object-oriented application, it is not advisable to share functionalities across several different modules. The direct consequence is that sharing an EventCollector instance, between two or more classes, is not good practice.

However, it is always possible to implement a shared EventCollector instance in the MVC pattern. But to be efficient, you must follow some basic rules to design the structure of the pattern:

  • The EventCollector instance must be a singleton.
  • The MVC pattern should be considered as a module itself. It means that EventCollector singleton must not be used by an object which does not belong to this module. (Principle of Retention of Information.)
  • The removeAllEvents() method must be the first action called within the destroying method implemented by the model. So, the structure of events management inside each object must be designed to respect this rule. (This is based on the principle of Modular Composability.)

Even if it is technically possible to do that, it seems wise to discourage the use of such practices! Unfortunately, the MVC pattern is not the best way to simplify the management of memory leaks. Thus, whatever the considered solution, it will not be easy to implement it.

In any case, you should implement a destroying method each time the rules introduced in Chapter 7 are confirmed.

9) Where to go from here

In this article, we learned how to use the EventCollector to simplify and improve the management of event handling in ActionScript 3.0. By now, you should be able to implement the EventCollector API in your existing and new projects by using the concepts explained in Chapter 7.

A Javascript portage of this class is available on the EventCollector page.

To be informed of new releases, latest information and documents about the collector API, or support SPAS 3.0 projects, follow us on the SPAS 3.0 Facebook page at: http://www.facebook.com/flashapi

We need your feedback to add functionalities to the collector API, so feel free to post your comments on the page devoted to this article, on the SPAS website at: ActionScript 3.0 Best Practices: Using the EventCollector Class

10) Bibliography

[MEYER, 1997] Bertrand MEYER, Object-Oriented Software Construction, second edition, Prentice Hall, 1296 pages, January 1997.