tags:

views:

295

answers:

3

using the MVP pattern in winforms is predicated on the presenter knowing about which controls to access as defined by the IViewInterface. for example if you had 2 textboxes and one button on your form, than you would define an IViewInterface with two properties for textbox and upon a button click event you forward the call to Presenter and the presenter can have access to those two properties. Pretty simple. now imagine if your UI is constructed at runtime based on tables in your database. let's say you have 500 tables in your database and you want to design CRUD apps for those 500 tables. lets say somewhere in your database you define how you want to layout those 500 tables in your UI. you have one program that at runtime creates UI controls for these 500 tables. how do You apply MVP pattern in such cases??

A: 

Fully dynamic user interfaces have been tried by many many programmers without much success. I'm sure plenty of people could give you the basic premise i.e. tables -> make UI but beyond that nothing has really worked out so you're better off just doing your own thing.

If you think you've got a different approach you should just try it out and see how it works.

Spencer Ruport
A: 

For this the presenter shouldn't care about controls at all.

The view could be exposing this data as properties. If those 500 tables with their 500 UI layouts are all at least using a standard display control like GridView, you could expose a property of "CurrentTableName" and one of "CurrentRow" for the active row in the GridView. The presenter could take those and pass along or transform into DTO or DM objects to a business or service layer.

This may or may not be possible in this instance though.

Tom
i had a similar notion. i was thinking that my IView would just have one method like thisList<string> GetValuesFromTheFormForTheseControls(List<string> ControlNames)Since we have a convention of using table fields as control names my presenter would call this method anytime I needed values retriever for any number of controls
codemnky
A: 

using the MVP pattern in winforms is predicated on the presenter knowing about which controls to access as defined by the IViewInterface

True, but in the case of dynamic GUI you don't need to expose these controls individually as interface's properties. You could define a generic control as a class with some common properties and expose a list of these controls as a single property of your view interface.

This is only one way of doing it - the design depends on the exact scenario. But in general I would say dynamic GUIs are even better candidates for introducing MVP, not the opposite.

Igor Brejc