0

I have an application which uses Martin Fowler's Presentation Model with WinForms (WPF would be a better choice, but that's irrelevant). As such, every view has a presentation model representing it where the UI logic and domain model translation logic reside. This works very well when the controls in my views are built-in .NET WinForms controls or third-party controls.

In subscribing to the DRY principal, I have a class library used by my application which provides a set of my own custom controls that are used in multiple views in my application; each of these controls is a composite of smaller controls that have some functional relationship. The custom controls also have their own presentation models that control their UI logic.

My question is, how can I architect my application so that the concerns of the view are not tied in with the underlying UI logic of my custom controls? Here is a diagram:

enter image description here

I don't want the flow of information from the form's presentation model to the control's presentation model to have to go through the views themselves; but at the same time, the presentation models don't know (nor should they know) about one another.

rory.ap
  • 34,009
  • 10
  • 83
  • 174
  • I assume myFormPM accesses the built-in controls on MyForm, e.g. MyForm.FieldA. Why don't you want myFormPM to access your custom control in the same way? e.g. MyForm.MyControl – Mike Stockdale Mar 31 '14 at 17:12
  • @MikeStockdale -- It can, for some things. But imagine that MyControl.Field1 is read-only because it's value is determined by UI logic that is inside MyControlPM. Now assume that this logic depends on a dynamic factor that is provided by the application when the control is used in the application. Concrete example: maybe MyControl.Field1 displays a color -- red, blue, or yellow -- if the consuming application wants it to display colors. Or, it could display a mood -- happy, sad, angry -- if the consuming application wants it to do that. – rory.ap Mar 31 '14 at 17:21
  • Which "type" is displayed is determined by the application that is using the control. However, the value of the "type" -- i.e. "red" or "happy" -- is determined by the control's presentation model (MyControlPM). – rory.ap Mar 31 '14 at 17:22
  • OK, I think I understand. MyControl could expose a property DisplayMode that MyFormPM could set: MyForm.MyControl.DisplayMode = Color or MyForm.MyControl.DisplayMode = Mood. Then MyControlPM can control the display of MyControl.Field1. – Mike Stockdale Mar 31 '14 at 18:30

0 Answers0