Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Start Menu……..Exposed What you never knew existed.

Similar presentations


Presentation on theme: "The Start Menu……..Exposed What you never knew existed."— Presentation transcript:

1 The Start Menu……..Exposed What you never knew existed

2 Model View Presenter in ASP.NET 2.0

3 Introductions Nick Parker Tim Gifford

4 Gifford Consulting Embedded Agile Coaching –Adaptive, Informed Planning –Simple Design –Refactoring –Test-Driven Development –Continuous Integration –Self-Managing Teams –Approaching Deadline Behaviors

5 Nick Parker Two Rivers Marketing Microsoft Visual C# MVP

6 Agenda Compare Code-Behind vs. MVP Demo 1 MVP Definition Comparison to Model View Controller Demo 2 Advantages Agile Testing Overview Disadvantages Review/Resources/Q&A

7 Expectations?

8 Code-Behind vs MVP (Code) protected void btnAdd_Click(object sender, EventArgs e) { txtFirstName.Enabled = true; txtLastName.Enabled = true; txtEmailAddress.Enabled = true; btnSave.Enabled = true; btnSave.Visible = true; btnAdd.Enabled = false; btnAdd.Visible = false; btnCancel.Enabled = true; btnCancel.Visible = true; txtContactId.Value = string.Empty; btnUpdate.Enabled = false; btnUpdate.Visible = false; } private void EditContact(Guid guidContactId) { //Get the contact factory = config.BuildSessionFactory(); ContactDTO contact = null; ISession session = factory.OpenSession(); contact = (ContactDTO)session.CreateCriteria( typeof(ContactDTO)).Add(Expression.Eq("ContactId", guidContactId)).UniqueResult(); session.Close(); if (contact != null) { txtFirstName.Text = contact.FirstName; txtLastName.Text = contact.LastName; this.txtEmailAddress.Text = contact.EmailAddress; this.txtFirstName.Enabled = true; txtLastName.Enabled = true; txtEmailAddress.Enabled = true; btnSave.Enabled = false; btnSave.Visible = false; btnCancel.Enabled = true; btnCancel.Visible = true; btnAdd.Enabled = false; btnAdd.Visible = false; txtContactId.Value = guidContactId.ToString(); btnUpdate.Enabled = true; btnUpdate.Visible = true; } protected void btnSave_Click(object sender, EventArgs e) { presenter.SaveContact(); } protected void btnUpdate_Click(object sender, EventArgs e) { presenter.UpdateContact(); } protected void btnAdd_Click(object sender, EventArgs e) { presenter.NewContact(); } protected void btnCancel_Click(object sender, EventArgs e) { presenter.Cancel(); } public IList DataSource { set { this.gvContacts.DataSource = value; this.gvContacts.DataBind(); } public ITextBoxAdapter EditFirstName { get { return new TextboxAdapter(this.txtFirstName); } } public ITextBoxAdapter EditLastName { get { return new TextboxAdapter(this.txtLastName); } } public ITextBoxAdapter EditEmail { get { return new TextboxAdapter(this.txtEmailAddress); } }

9 Code-Behind vs MVP Data Access Business Logic Domain Model Presentation User Interface Database Data Access Business Logic Domain Model Code Behind User Interface Database

10 Demo Swap Demo

11 Model – View – Presenter Model Presenter Update View User Actions

12 Model Responsibilities: –Stores Data Collaborators: –None Anti-Collaborators: –Model does NOT talk to the view –* Model’s don’t talk to me either!

13 View Responsibilities: Display and User Interface Delegate User Actions to Presenter Collaborators: Presenter Anti-Collaborators: Services

14 Presenter Responsibilities: Map between the UI and the Data Handle User Events Collaborators: View Model Service Anti-Collaborators: None*

15 Split Pattern Passive View –All synchronization between the View & Model is handled by the presenter –Minimal behavior on the View Supervising Controller/Presenter –Allows for more advanced Data Binding –More behaviors handled by view

16 MVP vs MVC MVP is MVC done “right” Data Access Model Presenter View Data Access Model Controller View MVPMVC

17 MVP UML(ish) Diagram

18 Advantages Reduce duplicate code Reduce maintenance Separation of Concerns Testable/Test-Driven Reduce UI defects

19 Agile Testing UI Integration Unit Tests Selenium Mercury Automated QA FIT FitNesse Nunit

20 Testing Layers

21 Demo Disable/Hide Controls

22 Disadvantages Complexity Learning Curve When NOT to use MVP? Quick & Dirty Short Application Lifetime Support Staff Not supported in technology (VB 6.0)

23 Review Benefit –Use MVP to create a unit tested UI –Helps minimize (or eliminate) defects Costs –Complexity

24 Resources Tim Gifford Email: tim@giffordconsulting.com Blog: blogs.giffordconsulting.com Nick Parker Email: nickp@developernotes.com Blog: http://developernotes.com Code: http://code.google.com/p/developernotes/


Download ppt "The Start Menu……..Exposed What you never knew existed."

Similar presentations


Ads by Google