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: The good logic for command ?  (Read 16630 times)
fidiman
Full Member
***
Posts: 23


View Profile Email
« on: October 16, 2008, 12:51:03 »

Hello,

As many people before me, i've trouble in understanding when i can talk with proxy directly from mediator and when i 've to use a command.

But this morning, i was trying to implement a logic of deleting product. In fact when i delete a product i've to talk with product_proxy but also with description_product_proxy (another table in db).

So i was beginnning to implement it into the product_proxy but it seems to myself that was not a good solution to invoke description_proxy from product_proxy, so the logical of puremvc push me in thinking about a command where i can invoke product_proxy and all the others proxy i need.

So is it the good way of thinking a command ?

(please, do not tell me to read the doc, i read it all days (holly bible), but there's a difference between read the concept and understanding examples and work with them)

Thanks !
Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #1 on: October 16, 2008, 02:12:14 »

For my part, I try to always use the controller to change or use the model when the user does something. It's the root of the MVC paradigm.

The use you made of your command seems to be the good one for me. You use it to dispatch changes on your model from the controller .. it is its role, it must be in a command.
« Last Edit: October 16, 2008, 02:15:29 by Tek » Logged
fidiman
Full Member
***
Posts: 23


View Profile Email
« Reply #2 on: October 16, 2008, 02:18:05 »

you're right about purity in using command, but in many case it's seems that it's not  necessary to invoke model by controller.

the mediator can do it because he's not the view.

That's what i've seen in many examples.


i 'm searching some complexe example of command, would you have some link ?
Logged
Jason MacDonald
Sr. Member
****
Posts: 243


View Profile Email
« Reply #3 on: October 16, 2008, 06:13:55 »

There's nothing wrong with Proxy's talking with other Proxy's, they are all part of the model and don't need to be partitioned from each other.

In my opinion, commands are best used in keeping the View from binding directly with the model (though some argue that using proxy's in Mediators is ok), and to handle domain logic as well as centralizing repetitive tasks used by multiple views.
« Last Edit: October 16, 2008, 06:15:51 by jasonmac » Logged
fidiman
Full Member
***
Posts: 23


View Profile Email
« Reply #4 on: October 16, 2008, 08:05:11 »

commands are best used in keeping the View from binding directly with the model

sorry, i'm french .

but you mean that you dont use binding ?
Logged
Jason MacDonald
Sr. Member
****
Posts: 243


View Profile Email
« Reply #5 on: October 16, 2008, 11:22:42 »

but you mean that you dont use binding ?

Sorry, I forget sometimes that the term "binding" means something in Flex, I'm an AS3 only guy. What I meant was that using Commands allows the View to access the Model without tying it directly to the Model. This allows you to change out the Model at anytime and reuse the View. But when you access the Model [Proxy] directly from the View [Mediator] that "binds" or "ties" the View to that particular Model.  Which is why I tend to use Commands and not access the Proxy in Mediators. I was only trying to illustrate one of the major roles a Commands has.

My point though was that you don't have to use Commands when dealing with Proxy-to-Proxy communications. You'd end up building tons of Commands just for your Model alone if you did, and this is unnecessary. Your Model should be walled off from your View, and vice-versa. But there's no need to add such separation between parts of your Model.
« Last Edit: October 16, 2008, 11:35:40 by jasonmac » Logged
fidiman
Full Member
***
Posts: 23


View Profile Email
« Reply #6 on: October 16, 2008, 12:19:13 »

ok, i understand.

thanks
Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #7 on: October 16, 2008, 02:27:11 »

Jasonmac, you are right, but here he only wants to delete two entries when the user asks for, one in product list, the other in description list. It is better not to call a proxy that will call another just after ... a command to centralize the whole process is a better choice at my own opinion.

A good "complex" command that answers your problem is the DeleteUserCommand in the employee admin demo in : http://puremvc.org/pages/demos/AS3/Demo_AS3_Flex_EmployeeAdmin/srcview/ it does exactly what you want to do, delete an entry and some informations associated with it.
Logged
fidiman
Full Member
***
Posts: 23


View Profile Email
« Reply #8 on: October 17, 2008, 12:08:15 »

thnaks tek, it was exactly what i'm looking for. Even if it's not a very complex command.

The add logic may be more explicit in this case.

In order to add a product, i've two request to do.

First, register the productVO into product DB. The result event (via amfphp for example) send me back  the productVO with the ID generated by the table.

Then with this ID, i have to register descriptions for product.

Actually i do all this operations in product proxy, that call description proxy on getting result form service.

It's a more complex opération, that the delete example, because i need to wait the first operation finishing before launch the second one.

So, if we imagine a command to do this, we need in fact 2 commands.

First command :

addProduct -> call product proxy (remote service, etc...)

on the back onCreateProduct -> send Notification that call the second command add Descriptions passing the ID product

and finally when onDescriptionAdded calling -> send NOtification to the mediator to tell the adding product loop is ending ?

What do you think about it ?

Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #9 on: October 17, 2008, 12:54:41 »

You could merge "onCreateProduct" and "onDescriptionAdded" in one command only, named "addProduct" because you will add product only this way (the one used to add product on server would be "createProduct").
Logged
fidiman
Full Member
***
Posts: 23


View Profile Email
« Reply #10 on: October 17, 2008, 05:28:09 »

product and description are 2 differents tables..
Logged
Pages: [1]
Print