2

Question:

Does it make sense to use MVVM for a UI that interacts with a web-service in a 3-tiered application?


Details:

  1. Application's architecture is 3-tiered:

    Presentation Layer <--Web-Service-->| Business Layer | Data Access Layer

  2. Front-end: .NET (WPF and C#)

  3. Back-end: Java EE

Does it make sense to use MVVM for the UI?

  1. How can the Model abstract the database since it cannot access it directly without the web-service in between?
  2. If it was in fact possible to abstract the database via the Model, is it even a good idea to do it that way?

Other considerations:

Don't need to have a live update of data:

  • Updates on the DB needn't be instantly reflected on the UI and vice versa.

  • This makes me think that I don't need to have a Model as such. Is MVVM appropriate in my case?


EDIT

Links:

It'll help if you can post links to projects that have used an MVVM for a UI in a 3-tiered application.

Community
  • 1
  • 1
mauryat
  • 1,610
  • 5
  • 29
  • 53

2 Answers2

3

The Model in MVVM is not necessarily provided by the database.

In this case I would consider the data structure that is published by the Business Layer the Model.

The data structure in the database should be optimized for storage and querying. The data structure exposed by the Business Layer should be optimized for (all) possible clients and considerations such as bandwidth.

The data structure in a client should be optimized for presentation and this is what we call the Viewmodel in MVVM.

MVVM is very appropriate because it allows you to translate between the data structure exposed by the Business Layer and the required data structure by the UI.

Emond
  • 50,210
  • 11
  • 84
  • 115
  • Thanks for your answer, esp for the clarity on the Model. Correct me, if I'm inferring something wrong: 1. **Model** is the data-structure exposed by the _Business Layer_. 2. **ViewModel** is the abstraction that optimizes the data-structure in the Model for presentation. I'm taking your word for it at the moment since its hard for me to be convinced. Unless I put the MVVM concepts to work in my project, I won't really get what it means and why it is important. – mauryat May 15 '12 at 14:40
  • 1
    The data structure that is exposed by the Business Layer might or might not fit the requirements of a View. E.g., the BL exposes Persons and Departments and the View you are creating is to display the names of the persons of a specific department. The ViewModel could simply be a class containing list of strings(names) and a string(department name). So the ViewModel is a data structure that provides a View with the correct data and functionality fitting the requirements. – Emond May 15 '12 at 14:52
1

I have seen in enterprise archicture an additional layer known as an Integration Layer. In the context of MVVM I imagine this still 'sits' within the Model, but never-the-less it acts an arbiter between the database, and any other external data layers. In the example I saw, the Integration Layer connected a 3rd party web-service, some input that came over a WCF service, and the main application database.

I think you might be a little off with what the Model means in MVVM. It doesn't mean that the UI/Presentation layer is instantly updated (however it can be configured as such) but more that any business objects, or data-access components are stored in the Model. In that was, there is really no such thing as VVM as the View Model is dependant upon the business objects defined in the Model.

Anyway, I think MVVM is completely appropriate for what you described, but then so are a lot of other architectures. MVVM is particularly good for a WPF frontend, and it fits in very well with the UI databinding model. Model-View-Presenter is very good for Winforms applications, as state is handled differently to Model-View-Controller, which is great for an ASP.net enterprise application. All these archictures support the integration you have described in the OP.

See How to store business logic in domain object? for my recent description of MVVM.

http://www.codeproject.com/Articles/66585/Comparison-of-Architecture-presentation-patterns-M is a great comparison article, a lot of content coming from Martin Fowler - a pioneer of a lot of enterprise software architecture and patterns.

Community
  • 1
  • 1
Patrick McCurley
  • 2,006
  • 1
  • 14
  • 24