This is the slide show I created for the first Twin Cities Code Camp in November of \'06 - I did this when I was working for Digineer and also used it in a Digi-U session that I put on for the other consultants.
Pattern oriented architecture for web based architecture
Code Camp 06 Model View Presenter Architecture
1. Code Camp 06’ Presentation – Model View Presenter Design and Implementation Chase Thomas Consultant - MCSD.NET - Digineer Inc.
2. Model View Presenter Architecture The Model View Presenter is a user interface architecture similar in nature to the model view controller. One of the greatest strengths in the MVP design is the ability to unit test user interface logic without a user interface. It’s origins are from the Taligent programming model for C++ and Java (based on the Smalltalk MVC) and has seen various implementations since it’s introduction. You can read more about the origins of MVP at the following URLs… ftp://www6.software.ibm.com/software/developer/library/mvp.pdf http://www.object-arts.com/papers/TwistingTheTriad.PDF
3. Model View Presenter Architecture Traditionally The View has a dependency on the model. The view directly interacts with the Model and the controller directly interacts with the view – controlling complex UI logic and data mapping. Classic Model View Controller (MVC) Architecture.
8. Model View Presenter Architecture Architecture UML Diagram (Sequence – Loading an Employee Model)
9. Model View Presenter Architecture Architecture UML Diagram (Sequence – Changing a value in the UI)
10.
11. Model View Presenter Architecture Implementation in C# (.NET 2.0) Building the model objects – Using Gestalt
12. Model View Presenter Architecture Implementation in C# (.NET 2.0) Building the model objects – Using CSLA.NET
13. Model View Presenter Architecture Implementation in C# (.NET 2.0) Building the model objects – Simple INotifyPropertyChanged Interface Implementation
14.
15. Model View Presenter Architecture Implementation in C# (.NET 2.0) Defining Our Interfaces – IEmployeeView Interface
16.
17. Model View Presenter Architecture Implementation in C# (.NET 2.0) Implementing our View Interface (part one – the Windows Form)… Implement the IEmployeeView interface on the windows form – the windows form implementation will receive information from the presenter and utilize it to perform display tasks.
18. Model View Presenter Architecture Implementation in C# (.NET 2.0) Implementing our View Interface (part two – the UI Unit Tests)… Implement the IEmployeeView interface on the unit test class that has the TestFixture attribute applied. Within the unit test class you will need to create placeholder values for what the windows form user interface state (i.e. control colors – error messages – enabled / disabled state etc…). The unit test in essence becomes a Windows Form simulator. If you did it right – there will be nothing missed by using a Unit test in place of a windows form.
19. Model View Presenter Architecture “ Blind Data binding” Problem: Since the view knows nothing about the model – how can we bind the view to our objects? Solution: Create a windows custom binding source object pass the binding source object to our presenter. Finally: Once the presenter has a reference to the windows forms Binding Source - establish the data bindings between the controls and the object in our form code.
20. Model View Presenter Architecture Implementation of “Blind Data binding” in C# (.NET 2.0) Create and pass our binding source to the presenter
21. Model View Presenter Architecture Implementation of “Blind Data binding” in C# (.NET 2.0) Establishing the Data bindings from our view The one of the cardinal rules of the MVP is that the View cannot know about or have a reference to the Model. That does not mean we can’t look at our Model property names and set up bindings in the form. We have not retained any knowledge of the Model within our presenter by doing this – just string values – you could even keep these values as constants in the presenter to centralize the information.
22. Model View Presenter Architecture What is the Supervising Controller and Passive View? http://www.martinfowler.com/eaaDev/SupervisingPresenter.html The 10 second description of these two derivations of the MVP are that they vary in how much interaction the view has with the model. In a supervising presenter the model is exposed to the view in order to perform data binding or other simple data to UI mapping. http://www.martinfowler.com/eaaDev/PassiveScreen.html A passive view is closer to what we just discussed with the original MVP. The view has no dependence on the Model whatsoever. The presenter handles all data mapping between the UI and Model To describe these two “new” concepts is beyond the scope of this presentation – however since they are now the recommended approaches according to Fowler’s website, a brief explanation of the two are in order…
23. Model View Presenter Architecture Sources of Material http://www.martinfowler.com/eaaDev/uiArchs.html http://www.martinfowler.com/eaaDev/SupervisingPresenter.html http://www.martinfowler.com/eaaDev/PassiveScreen.html http://msdn.microsoft.com/msdnmag/issues/06/08/DesignPatterns/
Hinweis der Redaktion
Go to EmployeePresenter code example here since there is too much to display on the screen