5

I have seen lots of tutorials and examples using Model-View UI design patterns, and they all implement them pretty differently, especially the Model part. In some examples Model is data (actual object representation of some DB) in some it's data access layer (like repository pattern) in some it's service layer...
If someone tells you he is using MV* pattern in his app, what will it tell you about app design? Does it maintain in-memory representation of database in object graph and use it as data source or some data access layer to query data base...

What you will choose as a Model for data oriented smart client app containing mostly Tab Pages with Tables?

Alex Burtsev
  • 12,418
  • 8
  • 60
  • 87

4 Answers4

7

The word model is used in, at least, two senses. There is your domain model. Here the sense is how you represent your data. There are many ways to structure your data and also many ways to access it. When we talk about the model in this sense we're not particularly concerned with how you are accessing the structures that make it up, i.e., the data access or persistence layer, although you may also hear people speak of the model of persistence. By this, people mean the particular philosophy that the persistence implementation uses, such as ActiveRecord or Repository. You might also hear these referred to as patterns.

Finally, the word model has a very specific meaning in MVC, MVP, and MVVM in the context of a view. In that context it means that particular data object associated with a view, the view model. This could be one of your domain objects, but more typically it is a view-specific object that encapsulates data from one or more domain objects along with ancillary data such as user data that is used by a particular view.

For your application, choose the persistence model that best suits your development environment and language -- LINQ to SQL, LINQ to Entities, nHibernate, Castle ActiveRecord, etc. in the MS world Create view-specific models (classes) for each of your views that hold the data needed by that view. Use your controllers to query your domain model to extract the information needed by the view and map that onto the view model.

tvanfosson
  • 524,688
  • 99
  • 697
  • 795
  • @tvanfosson: but what should i choose to query? DB directly or in-memory object graph? Most of the time my app will have almost whole DB loaded in memory object graph, and it make sense to query it because it's faster, but also i have Views which contains complex and heavy aggregates and it's easer and faster to query DB directly for these, it's too hard to constantly maintain those views state from Object Graph, it's easer to refresh them on demand from db... – Alex Burtsev Jan 02 '11 at 16:07
  • @Broken Pipe - you might want to think about a custom repository (or cache) that maintains your object graph, but refers some queries directly to the DB. This would insulate the rest of your app from knowing how the queries are done. – tvanfosson Jan 02 '11 at 16:15
  • @tvanfosson: yeah, that's what I was thinking about, do you think I can use Nhibernate 2nd level cache for those purposes, or should I implement my own custom system? If so will System.Runtime.Caching can me useful for these? – Alex Burtsev Jan 02 '11 at 16:30
  • @Broken Pipe -- not an nHibernate user so I can't help you there. I suspect that you'd probably want a custom cache, perhaps wrapped around the application cache, if you go that route. It really depends on your application and data structure -- I've done both in different situations. – tvanfosson Jan 02 '11 at 16:35
  • Thank you for answers, they cleared some part of my mind on how to implement my app architecture. – Alex Burtsev Jan 02 '11 at 16:38
  • @tvanfosson - Thank you! Finally someone who knows the model is not a domain model, but rather a view-model. – Phill Jan 02 '11 at 23:34
0

If someone says, he is using MV* pattern, it means the application is split into several parts, acting without a direct reference to a specific type, it doesn't say anything about the actual implementation. MVVM means, you have a Model, a ViewModel and View part, that's all.

The model is your data storage. This doesn't say anything of the implementation of it, it can be anything, depending on the task at hand. However, it should be accessed using interfaces, so you can quickly exchange the implementation. That, in a sense, is the whole point of the MVVM pattern - decoupling of the three tiers via interfaces.

Your description sounds alot like my project at the moment - I use sqlite as backing storage with Entity Framework as ORM. However, I also use T4 to generate Dto objects which then get mapped via automapper in the ViewModel, as those only need the data, not the persistance.

Femaref
  • 60,705
  • 7
  • 138
  • 176
  • yeah pretty much the same but I use Nhibernate as persister, and DTO-Entity-EntityUI inheritance instead of DTO-Entity with auto-mapper, so what is your model it's memory object graph with backed EF as persister, or it's EF data access lair? – Alex Burtsev Jan 02 '11 at 15:46
  • Probably the latter, I only get the data from the database if needed, also I use lazy loading so every access is defered until it's actually used. – Femaref Jan 02 '11 at 15:49
0

The model typically refers to the data layer, but as I discovered, in MVC this can be a little msleading when implementing an ntier approach. The reason for this is that the model is not contained in it's own assembly.

Here is some of very useful feedback I got to a similar question Confussion over MVC and entity model

Community
  • 1
  • 1
hoakey
  • 998
  • 3
  • 18
  • 34
0

A model can be considered as data container that facilitates rendering presentation component and/or persisting data to/from data source (i.e. database etc). Besides the data container elements, a model may or may not contain behavior, depending on design context of corresponding architecture.

While the term “Model” is frequently discussed and used in Model-View-Controller pattern context, it is one of most important consideration in current world of software architecture

You may want to look the following article where few popular and new design patterns that are related to presentation component and model are described.

Ashraf Alam
  • 3,500
  • 32
  • 31