topleft
topright

OReilly PureMVC Book

PureMVC Book

PureMVC TV

PureMVC TV

PureMVC on the Web

PureMVC Blog-o-Sphere
PureMVC on LinkedIn
 
Image
 
Is it ok to call Proxy methods from a Mediator?
Monday, 30 June 2008

QUESTION: 

From 'PureMVC Argument' by Jonathan Rowny

 

So me and the other people in my team got in a small argument over the proper use of PureMVC's mediators. We've read in various blogs that it is not a good practice to call a Proxy directly from a mediator. If you're going to call a proxy, it needs to be done from a command.

In this particular case, we're asking for the proxy to refresh some data. That's it... one call. someProxy.refresh(). The refresh will send it's notification and our mediator will update. So one of my coworkers wanted to register a command that called someProxy.refresh() and then send a notification from the mediator. If there was some business logic that needed to happen, I'd be all for it! But there isn't, we're just refreshing an array collection. So someone please tell me why should I register a command to call a proxy in this case?

 

ANSWER:

From "Best Practices and Implmentation Idioms ":

Coupling of Mediators to Proxies and other Mediators

Since the View is ultimately charged with representing the data model in a graphical, interactive way, a relatively tight one-way coupling to the application’s Proxies is to be expected. The View must know about the Model, but the Model has no need to know any aspect of the View.

Mediators may freely retrieve Proxies from the Model, and read or manipulate the Data Object via any API exposed by the Proxy. However, doing the work in a Command will loosen the coupling between the View and the Model.

 

Jonathan's complaint is justified. In this case, it is increased complexity and not called for. The relationship between the Mediator and Proxy is established and accepted within the framework best practices. The real benefit of the Mediator is that it decouples the View Components from knowledge of the Model and visa versa, which is where spaghetti code begins.

 

The need to decouple Mediators from Proxies is minimal, but the need to keep business logic in Commands is more defensible.

 

If there are more than 2 lines of code involved and those same lines need to be executed by multiple Mediators, then pushing those two lines into a Command and replacing them with a single line to send the Notification *might* be justified if it reduces the number of actors that the various Mediators need to know by placing the collaboration responsibility on a single Command. If those 2 lines ever need to change, at least it's in one place.

 

However, other requirements pressures in your app, such as the extra cycles to do the Notification processing and instantiate the Command can effect such a decision in certain problem domains such as 3D, Gaming, Audio, Video or Image processing.

 

-=Cliff>

Delicious
Technorati
Reddit
Furl it!
NewsVine
YahooMyWeb
Stumble
blogmarks
Digg
co.mments
connotea
 

PureMVC on the Web

João Pescada has produced a nice PureMVC / AS3 demo - a searchable image gallery. 
 
Photo Search with PureMVC - Article  -  Code  -  Demo

 

 
Jonathan Campos has put together a nice introductory PureMVC article with an example built around the Netflix API.
 
Netflix API with PureMVC Article

 
The guys over at Pyjamas (a Python port of GWT) have made their compiler so efficient that it can take virtually any Python library and it will compile to Javascript. They loved the look of PureMVC Python, and decided to do a couple of demos that use it.
 

Pyjamas Project

• EmployeeAdmin Demo: Original / Pyjamas  

Pyjamas PureMVC Timesheet Demo

 
Chandima Cumaranatunge, co-author of the O'Rielly book AS3 Design Patterns, and long-time PureMVC community member recently created a simple Flash/AS3 MultiCore demonstration application accompanied by an informative article that's an excellent introduction to the benefits of working with MultiCore.
 
Who Moved the Cheese? - Demo / Source / Article

ActionScript 3 Design Patterns

 

Ahmed Nuaman has published a well conceived and received AS3/PureMVC tutorial at FlashTuts.com. It's a good place for the learner to get their feet wet, and goes into the difference between using PureMVC with Flex as opposed to Flash or pure AS3.

 

Understanding the PureMVC Open Source Framework

FlashTuts Website
Ahmed's Website

 

 

Recent Project Activity

The PureMVC MultiCore framework for  Native JavaScript is now available. It has no dependency on other frameworks and provides its own optional namespace and class simulation.

 

 

 

PureMVC Standard Version for Perl 1.0  has been released, complete with unit tests and online documentation.

 

PureMVC Standard Framework for Perl

 

Release 1.3 of the AIR DesktopCitizen Utility which allows applications to remember their window size, position and maximized/minimized state each time it is launched. It also provides a facility for requiring confirmation (or executing some shutdown process) before the application window closes.

 

AS3 / AIR Desktop Citizen Utility

CodePeek Demo

 

The classic PureMVC EmployeeAdmin Demo has been ported to yet another language! Although PHP is usually thought of as a server language, using PHP-GTK, Sasa Tarbuk recreates th a desktop app. 

 

 
Version 1.0.8 of the PureMVC Java MultiCore port is now available. It supports JavaFX and handles threading properly.

 

 
Copyright (c) 2006-2012 Futurescale, Inc.