Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Show Posts

* | |

  Show Posts
Pages: [1]
1  Announcements and General Discussion / Architecture / Re: Command vs. Notification on: September 15, 2008, 03:12:35
Yes, that's pretty much my question. :) Thanks, that makes sense.

I think when it comes down to it, I was just trying to get my head around what commands should be used for. I guess working on a non-sandbox project might make this clearer...
2  Announcements and General Discussion / Architecture / Re: Multicore for AS2? Is that even what I want? on: September 14, 2008, 10:20:40
Wow. No messing around there. :)
3  Announcements and General Discussion / Architecture / Command vs. Notification on: September 14, 2008, 10:18:45
Hi,

I just started refactoring a small as3 application with pmvc a few days ago, and I'm really damn impressed with the framework so far. It's quite easy to insert into an existing application, though I can't wait to build a new app from scratch with it. Kudos to the pmvc team!

Anyway, I have an architecture question about the differences between Notifications and Commands, since there seems to be many instances where both could be used for the same purpose, especially where user-interfaces are involved.

I've had a quick search on the forum and through some of the examples but I can't find any definitive recommendations.

As a contrived example, say I have a ControlPanelMediator which listens for specific clicks on a control panel interface. These clicks should toggle visibilities of other Sprites, such as a sidebar. I see at least two ways to do this:
1) ControlPanelMediator sends a TOGGLE_SIDEBAR_COMMAND notification, which solely causes execution of the ToggleSidebarCommand. This command retrieves the SidebarMediator from the façade, and calls its toggleVisibility() method directly. That method toggles the actual sidebar Sprite's visibilty.
2) ControlPanelMediator sends a SIDEBAR_TOGGLE_BUTTON_CLICKED notification. The SidebarMediator is listening for this Notification, and toggles the sidebar Sprite's visibility in response to this.

In short, #1 is more "command oriented", and #2 is "interface oriented".

My hunch was to go with #1 because it keeps the details of the user interface (clicking, etc) out of the core application code, but is slightly more complicated to implement and maintain. It generally requires the creation of a command name string and a command class for each operation. Similar Commands could perhaps be coalesced into a single class by acting on the body of the Notification, I guess, but #2 is definitely a simpler way to go because it only requires a couple of lines of code.

So basically, is there any recommendation or rule of thumb when deciding whether to use commands vs. notifications? Should commands generally be reserved for changing state? Perhaps things that you want to be 'undoable' should be commands?

Any thoughts, or links, anyone? (Sorry if this post is a bit jumbled!)
Pages: [1]