PureMVC Architects Lounge

Announcements and General Discussion => Architecture => Topic started by: Roustalski on March 17, 2009, 06:27:40



Title: Data formatting
Post by: Roustalski on March 17, 2009, 06:27:40
Where should things like number formatters happen?

I would assume the proxy, but what about the case of an item renderer formatting an epoch number into a date?

Or maybe you have a total price label and the proxy has the variable stored as a string. Should the proxy format the string, or store it as a number and let whoever cares deal with it? (in this view's case: $123,456,789).

Thanks.


Title: Re: Data formatting
Post by: Jason MacDonald on March 17, 2009, 09:42:41
I like to keep things simple and have my Proxys store information in a universally usable format so any actor can use the "raw" data and do what they want with it from there.

The likely scenario for the money example is to have the Proxy ensure the type is a Number or int and pass that on to the view (also the Proxy should only receive Numbers or ints for saving). In the view have your formatter utility take a Number input and spit out a formatted String for display. An item Renderer is a good example of this. The underlying dataProvider is a Number but the display is formatted however the item renderer dictates.

I often find it helps to look at Proxy's as if they were DB tables when trying to decide how to store info (probably cuase a lot of my data comes directly from a row into my proxy's as VO's). You would store a date in a DB as an epoch number usually and let whatever uses the data format it.


Title: Re: Data formatting
Post by: Roustalski on March 23, 2009, 05:28:09
What about multiple "tables" who need to be grouped together?

Do you have some sort of intermediate step in the model that formats (e.g. groups into a hierarchy), but still left in the raw format before passing off to another actor?

What is grouping/data structuring classified as?

Should there be a proxy for each table, and then another proxy that does the management of each grouping or structure for the data?


Title: Re: Data formatting
Post by: Jason MacDonald on March 23, 2009, 06:17:34
That sounds like the realm of a Command. Have a command grab the "raw" data from the Proxy, or Proxies, and group it together the way you need and then send it back to the view. The view can then handle any further item rendering for formatting of each item (dates, number etc).

For example, a data grid might need the data structured a certain way. So the command groups the data into a ArrayCollection and sends the array back to the data grid where the Item Renderer formats each cell of the data.