Notion of View Model ?

Sep 20, 2012 at 11:33 AM
Edited Sep 20, 2012 at 11:34 AM

Hi,

Just reading through the documentation a little further I notice that some of the attributes are presentational ie "Multiline", "MemberOrder" etc. While convenient I thought that presentational definitions should be seperated from the Data model where one should focus on integrity issues such as "required", "MaxLength" etc. This does raise the question about the usefulness of the "View Model" which I have seen much mention of in other designs, but not fully grasped, although I do understand that it represents the model for the View Layout, rather than the data.

This could be academic since Microsoft obviously offer "Description" etc in the same way.

Thoughts ????

Many thanks in advance,

Ed

Editor
Sep 20, 2012 at 11:40 AM


On 20 September 2012 11:33, ESSB <notifications@codeplex.com> wrote:

From: ESSB

Hi,

Just reading through the documentation a little further I notice that some of the attributes are presentational ie "Multiline", "MemberOrder" etc. While convenient I thought that presentational definitions should be seperated from the Data model where one should focus on integrity issues such as "required", "MaxLength" etc. This does raise the question about the usefulness of the "View Model" which I have seen much mention of in other designs, but not fully grasped, although I do understand that it represents the model for the View Layout, rather than the data.

Thoughts ????


Here's a post of mine from a long while back .. http://danhaywood.com/2009/11/11/annotations-vs-xml/


With respect to view models, NO MVC does support them in a limited form (just a simple wizard, say), but if you want complex sets of information in your view model (ie: view models with references to other objects), then you need to create a persistent entity with some sort of GUID identifier, some sort of mapping technology for shovelling data between the view model and the underlying entity, and, a way of cleaning up those view models from the database afterwards.

I'd counsel against view models in the first instance though; only introduce them once there are certain heavily-used / high volume use cases that you need to optimise for. Thinking of the app only in terms of use cases/view models is - in NO terms, at least - putting the cart before the horse.

Dan

Many thanks in advance,

Ed

Read the full discussion online.

To add a post to this discussion, reply to this email (nakedobjects@discussions.codeplex.com)

To start a new discussion for this project, email nakedobjects@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Sep 20, 2012 at 12:00 PM

Dan,

Appreciate the quick reply.

Yes appreciate the comment "Thinking of the app only in terms of use cases/view models is - in NO terms, at least - putting the cart before the horse." However could one envisage the notion of a generic View which takes a Data Model and a View Model to render the UI? This takes me back to the days of XSLT rendering View XML and Data XML to create XHTML.

You raise another interesting point, that being of "Wizards". I will need to create a dynamic wizard which the view will render(as a Razor View) from XML stored in the DB. This Wizard page will then store all the values for all the generated fields as one XML string. In addition I plan to use XML to define the interplay of the Wizard steps. An alternative to this is WF4 using XAML. Thoughts about this, and in particular within NO.

Many thanks Dan, really appreciate your help,

Ed

Editor
Sep 20, 2012 at 12:04 PM
Edited Sep 27, 2012 at 1:28 PM

Over on the Irish project we have a little utility that uses System.Reflection.Emit to create a class on the fly, and then an instance of that class. The object is not persisted, but since it consists of a bunch of simple scalar properties, it can be data driven easily enough (we're using it to build forms on a questionaire). NO MVC just renders it like any other object.

I suspect we'll roll this utility into the NO MVC framework at some point; but it's easy enough to create a simple version of it.
Cheers
Dan
Sep 20, 2012 at 12:20 PM

Dan,

That is exactly what I am looking to do. It is effectively a series of mini forms that make up a questionnaire, but linked via rules that determine future forms depending on previous answers. In addition it would be neat to have a tree view into this page flow.

I did read your blog post. Very interesting, and agree. Although I think there is a role for annotations which are "atomic" and can be compiled and a role for configurable application logic which can be changed outside of the binary. Perhaps there could be a role for a Config file Annotation ie [XmlConfigName("Person.xml")].

Ed

Editor
Sep 20, 2012 at 12:24 PM
Edited Sep 27, 2012 at 1:28 PM

Look forward to your code contributions in the future!

If you want, I can dig out the dynamic view model stuff for you to experiment with.
Dan

Sep 20, 2012 at 12:47 PM

Dan,

I appreciate the offer. I  need to get to grips with the fundamentals of NO to start with, and then get back to you. If I can contribute anything of value then I will do so of course. At present I am evaluating it as a potential core for my capability for creating ASP.NET MVC applications going forward in a robust and very responsive way. In addition I need to be able to plugin backend services (either 3rd party or internal) and also look to leveraging clientside 3rd party stuff since there are good 3rd party MVC widgets which hopefully one can augment the NO framework with. Perhaps the generic views can pull in a specified widget to render a partial view?? In addition one needs to be able to extend into JQuery and HTML5. In addition I have a special interest in extending further this stack into the Mobile arena using JQuery Mobile and other Mobile MVC technologies such as Orubase.

Loads of stuff here !!! :)

Ed

Editor
Sep 20, 2012 at 12:49 PM
Edited Sep 27, 2012 at 1:28 PM

For the last topic you touch on - JQM - you should also check out Restful Objects. I did actually do some work on this for the Isis (Java) impl. Sounds like that's a way down the line, though.


Dan

Sep 20, 2012 at 12:59 PM

Thanks, will do.

Ed

Sep 23, 2012 at 1:23 AM

Automapper seems to be the conversion tool that links the domain model to the View Model, but I am leaving this for another day.

 

Thanks.

Sep 23, 2012 at 11:12 AM

Yes, AutoMapper is extremely useful and simple for copying properties between objects, should you require that.

Editor
Sep 27, 2012 at 1:31 PM

Just an addendum... I've now uploaded the dynamic view model stuff we've been working on and popped it into a github project [1].  There's also a ticket [2] to request this be integrated back into the framework proper.

Dan

 

[1]  https://github.com/danhaywood/nomvc-dvm

[2] nakedobjects.codeplex.com/workitem/93