0

I want to completely separate data layer from the UI Layer. Here is my example, I have some customers that require different data for the same report and I don't wan the UI to touch the Data Layer, so I am assuming I need some "thing" in between the Data Layer and the UI. Basically, the UI would call some "thing" and that "thing" would call the Data layer and then the data layer would retrieve data based on the user and pass it back to the "thing" and the "thing" would pass back the data to the UI.

I don't know what this "Thing" should be?

I have heard some terms passed around like Model, using an Object Mapper, but not sure if these are relevant.

Xaisoft
  • 45,655
  • 87
  • 279
  • 432

2 Answers2

1

The patter you looking for is MVC - Model-Controller-View. The 'thing' that you need is the controller. Usually the code is organized like this

  • the controller is invoked to get the report
  • is accesses the data layes (or the model) and gets an object populated with the data (can be a strongly typed object, or just a map)
  • the controller invoked the view, passes it the data-object and gets the rendered result
  • the controller returns the rendered result to the client.

This should be enough to get you started.

MVC pattern in wikipedia

RA.
  • 1,405
  • 1
  • 11
  • 18
  • Does this apply to the MVVM model, if yes, how? – Xaisoft Oct 05 '12 at 13:57
  • In MVVM the controller is replaced with a 'view model' layer which transforms that data from the Model to the format that the view understands. Also from what I remember MVVM uses events instead of direct method invocation, thus instead of the Controller being tied to the View and the Model, the View-Model layer just exposes (or consumes) event, knowing only the event signature – RA. Oct 05 '12 at 14:04
0

You're talking about a common architecture: UI --> Business Logic layer (BLL) --> Data Access layer(DLL). Now, the BLL and DAL, can be included in your .exe (you tagged your question with WinForms) or can be part of a service layer/tier, which is very common.

It's generally a good practice to have interfaces that define each layer (BLL and DLL). This will allow you to change the layer's implementation without affecting its consumer (generally), gives you separation of concerns, and it faciliates testing.

The BLL will contain your logic and the DAL will manage your datasource. You mention a Model, that usually refers to the object the DAL is returning via the BLL. Think of it as your Person model or Order model. Since your tag is Winforms, you may want to investigate the MVP pattern.

Big Daddy
  • 5,160
  • 5
  • 46
  • 76
  • Does this apply to the MVVM model, if yes, how? – Xaisoft Oct 05 '12 at 13:56
  • It can, but generally speaking the BLL and DLL in my projects reside in the service/repository tier. I think you want to avoid your ViewModel (or presenter in MVP) becoming surrogate code-behind files. In MVVM, I have my ViewModels call into a repository or service layer that, in turn, call in into the DAL. – Big Daddy Oct 05 '12 at 14:04
  • Can you explain what a Repository or service layer is? – Xaisoft Oct 05 '12 at 15:08
  • From the client side, use these to call into your web service or BLL. Generally, you want your ViewModel/Presenter/Controller to pass requests to one of these - it's more SRP/separation of concerns stuff. These will make the calls to get data, etc. – Big Daddy Oct 05 '12 at 15:21