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

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

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

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

The Start Menu……..ExposedWhat you never knew existed

Page 2: The Start Menu……..Exposed What you never knew existed.

Model View Presenter in

ASP.NET 2.0

Page 3: The Start Menu……..Exposed What you never knew existed.

Introductions• Nick Parker

• Tim Gifford

Page 4: The Start Menu……..Exposed What you never knew existed.

Gifford Consulting• Embedded Agile Coaching

– Adaptive, Informed Planning– Simple Design– Refactoring– Test-Driven Development– Continuous Integration– Self-Managing Teams– Approaching Deadline Behaviors

Page 5: The Start Menu……..Exposed What you never knew existed.

Nick Parker• Two Rivers Marketing

• Microsoft Visual C# MVP

Page 6: The Start Menu……..Exposed What you never knew existed.

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

Page 7: The Start Menu……..Exposed What you never knew existed.

Expectations?

Page 8: The Start Menu……..Exposed What you never knew existed.

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<ContactDTO> 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); } }

Page 9: The Start Menu……..Exposed What you never knew existed.

Code-Behind vs MVP

Data Access

Business LogicDomain Model

Presentation

User Interface

Database

Data Access

Business LogicDomain Model

Code Behind

User Interface

Database

Page 10: The Start Menu……..Exposed What you never knew existed.

DemoSwap Demo

Page 11: The Start Menu……..Exposed What you never knew existed.

Model – View – Presenter

Model

Presenter

Update View

User Actions

Page 12: The Start Menu……..Exposed What you never knew existed.

Model• Responsibilities:

– Stores Data

• Collaborators:– None

• Anti-Collaborators:– Model does NOT talk to

the view– * Model’s don’t talk to me

either!

Page 13: The Start Menu……..Exposed What you never knew existed.

ViewResponsibilities:

Display and User Interface

Delegate User Actions to Presenter

Collaborators:

Presenter

Anti-Collaborators:Services

Page 14: The Start Menu……..Exposed What you never knew existed.

PresenterResponsibilities:

Map between the UI and the Data

Handle User Events

Collaborators:View

Model

Service

Anti-Collaborators:None*

Page 15: The Start Menu……..Exposed What you never knew existed.

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

Page 16: The Start Menu……..Exposed What you never knew existed.

MVP vs MVC

•MVP is MVC done “right”

Data Access

Model

Presenter

View

Data Access

Model

Controller

View

MVP MVC

Page 17: The Start Menu……..Exposed What you never knew existed.

MVP UML(ish) Diagram

Page 18: The Start Menu……..Exposed What you never knew existed.

Advantages• Reduce duplicate code

• Reduce maintenance

• Separation of Concerns

• Testable/Test-Driven

• Reduce UI defects

Page 19: The Start Menu……..Exposed What you never knew existed.

Agile Testing

Unit Tests

Integration

UISelenium

Mercury Automated QA

FIT FitNesse

Nunit

Page 20: The Start Menu……..Exposed What you never knew existed.

Testing Layers

Unit Int UI

Brittleness Execution Time

Page 21: The Start Menu……..Exposed What you never knew existed.

DemoDisable/Hide Controls

Page 22: The Start Menu……..Exposed What you never knew existed.

Disadvantages• Complexity

• Learning Curve

When NOT to use MVP?

• Quick & Dirty

• Short Application Lifetime

• Support Staff

• Not supported in technology (VB 6.0)

Page 23: The Start Menu……..Exposed What you never knew existed.

ReviewBenefit

– Use MVP to create a unit tested UI– Helps minimize (or eliminate) defects

Costs– Complexity

Page 24: The Start Menu……..Exposed What you never knew existed.

Resources

Tim GiffordEmail: [email protected]

Blog: blogs.giffordconsulting.com

Nick ParkerEmail: [email protected]

Blog: http://developernotes.com

Code:http://code.google.com/p/developernotes/