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

Pages: [1]
Print
Author Topic: Implementing Command which can perform multiple tasks  (Read 11030 times)
99miles
Jr. Member
**
Posts: 14


View Profile WWW Email
« on: March 18, 2008, 02:23:15 »

Project Overview:
I have a project with a TileList containing images.

I also have a List of tag names and each tag name has a checkbox next to it.

When one or more images are selected, then a tag checkbox is clicked, I need to apply the tag to the selected image(s) if the checkbox is checked (or remove the tag from the image if the checkbox is now unchecked.)

On to the implementation:
There are a couple things I need to do this. I need to grab the selectedIndices of the TileList (so I know which ArrayCollection items to add the tag to), and I need the tag name. I then push the selected tag name into the ArrayCollection of the  selectedIndices for the collection of images.
I also have a ‘state’ property on each tagVO which I set to ‘STATE_CHECKED’ for any tag that is checked.
Obviously to remove a tag this would all be reversed.

I started out with an ApplyTagCommand, a RemoveTagCommand, etc to handle these actions. But I also do a similar thing for ‘Sets’, and ‘Groups’ which behave very similar to the Tags list. So I combined the ApplyTagCommand and RemoveTagCommand into one TagCommand to keep down the number of commands and to consolidate related code. It seemed like the right thing to do.

The question:
My question is this: What would your approach be for accessing the particular behavior you want from a command that can perform several actions? I currently have static vars in the TagCommand, ADD_TAG and REMOVE_TAG, and I’m passing either one of those in the body of the notification – the command then calls the appropriate method depending on the which static is in the notification body.
Like this:
 sendNotification( ApplicationFacade.TAG_HANDLER, TagCommand.ADD_TAG );

Does that seem okay? Would it be preferable to set the value of a public variable ‘mode’ on the Command first, then leave the notification body empty? Is there an altogether different preferred approach?

Thanks in advance, and awesome job Cliff!
-Mac

Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: March 18, 2008, 02:46:28 »

Hi, Mac.

Generally you can use the type property of the Notification as a discriminator. Then inside the Command, choose the behavior based on the type property.

In your example, you're passing it in the 'body' but presumably for the same purpose. That would work, but using 'type' allows you to still send a 'body' as well. 

-=Cliff>
Logged
99miles
Jr. Member
**
Posts: 14


View Profile WWW Email
« Reply #2 on: March 18, 2008, 03:39:02 »

Thanks Cliff-
 Is that the idea behind the 'type' parameter? Are there other ways you see if may be used frequently?
Mac
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: March 18, 2008, 07:54:45 »

Yep, that's it. 

-=Cliff>
Logged
Pages: [1]
Print