24
RE-EVOLVING DESIGN PATTERNS Chris Hance

Re-evolving Design Patterns

  • Upload
    zasha

  • View
    29

  • Download
    0

Embed Size (px)

DESCRIPTION

Chris Hance. Re-evolving Design Patterns. Where do patterns come from?. Canonical Answer Design Patterns: Elements of Reusable Object-Oriented Software, “Gang Of Four” Patterns of Enterprise Application Architecture (PoEAA), Martin Fowler Real Answer “Lots of people do it this way.”. - PowerPoint PPT Presentation

Citation preview

Page 1: Re-evolving Design Patterns

RE-EVOLVING DESIGN PATTERNS

Chris Hance

Page 2: Re-evolving Design Patterns

Where do patterns come from? Canonical Answer

Design Patterns: Elements of Reusable Object-Oriented Software, “Gang Of Four”

Patterns of Enterprise Application Architecture(PoEAA), Martin Fowler

Real Answer “Lots of people do it this way.”

Page 3: Re-evolving Design Patterns

Lots of People are Wrong

Anti-pattern Common practice that’s (usually)

inefficient or incorrect.

Get used to “It Depends”

www.c2.com/cgi/wiki “Portland Pattern Repository's Wiki”

Page 4: Re-evolving Design Patterns

The Application

Record Student Arrivals / Departures (Check In / Check Out)

Enforce rules on student custody, etc.

Integrate with a legacy VB6 system

Page 5: Re-evolving Design Patterns

Intent: Partial Rewrite

First stab at MVC/MVP/… Isolate UI from Model COM-compatible Standardized Control behavior

Page 6: Re-evolving Design Patterns

Some (COM/VB6) Limitations No constructor parameters No overloading Events "disappear" in interfaces

Page 7: Re-evolving Design Patterns

Attempt #1

UI UberDLLModelDALDALStub

Controls"Controller"Form

How many DALs in one DLL?

Page 8: Re-evolving Design Patterns

Attempt #2

UI UberDLLModelIDAL

Controls"Controller"Form

DALDAL

DALStubDALStub

CircularDependency

New Rule:Model doesn't talk to the DAL.

Page 9: Re-evolving Design Patterns

Attempt #3

FactoryFactory

UIControls"Controller"Form

ModelModelIDAL

DAL(Stub)DAL(Stub)

Next: Add Interfaces.

Page 10: Re-evolving Design Patterns

Attempt #4: With Interfaces

FactoryFactory

UIControls"Controller"Form

ModelModelDTO

DAL(Stub)DAL(Stub)

InterfacesModelInterfaceDTOInterfaceFactoryInterfaceDALInterface

Page 11: Re-evolving Design Patterns

Still Awake?

Figure 17. Obligatory Useless Diagram

Page 12: Re-evolving Design Patterns

Low Coupling!What is it good for?

Reusable Code?

Manageable Code Won't somebody think of the

maintenance programmers?

Page 13: Re-evolving Design Patterns

Back to the Application

Concepts Check-In/Check-Out Student Contact School Teacher User

Page 14: Re-evolving Design Patterns

Multiple Factories

UIControls"Controller"Form

CheckInOutInterfaces

CheckInOutModelCheckInOutFactory

CheckInOutDAL

ContactInterfaces

ContactModelContactFactory

ContactDAL

Separate the concepts for maintenance programmer sanity, and some reusability. Do I need School,

Teacher, Student, etc?

Page 15: Re-evolving Design Patterns

Tour the Model

That means open Visual Studio.Yes, now.

Page 16: Re-evolving Design Patterns

So About the UI

MVC MVP (“retired” per Fowler)

Passive View Supervising Controller

MVVM Presentation Model

Page 17: Re-evolving Design Patterns

Supervising Controller

Figure π¾. Supervising Controller Sequence Diagram http://martinfowler.com/eaaDev/SupervisingPresenter.html

Page 18: Re-evolving Design Patterns

How to test the Controller?

ViewFormControl(s)

ViewInterfacesIFormIControl(s)

ControllerController

ViewStubFormStubControlStub(s)

Pick a View at RuntimePick a View at Runtime

Page 19: Re-evolving Design Patterns

IControl(s)?

Yes, define ITextbox, ICheckbox, ad nauseam.

Need control wrappers that implement ITextbox, etc. = Adapter pattern.

Also useful for standardized control behavior. = Decorator pattern.

Page 20: Re-evolving Design Patterns

And a concession to VB6

VB6 can’t define events in interfaces

Events only work withDim WithEvents txt As Textbox

They don’t fire forDim WithEvents itxt As ITextbox

Page 21: Re-evolving Design Patterns

Alternate Event System

WeakReference to objects String event / method name

Marshal.IsComObject() TypeLibInfo .InvokeSub() for COM

objects MemberInfo.Invoke() for CLR objects

Parameters are ugly.

Page 22: Re-evolving Design Patterns

Tour the UI

Or what I have of it. (Work in Progress)We can always fall back to VB6 sample

code.

Page 23: Re-evolving Design Patterns

The Whole… ThingViewFormControl(s)

ViewInterfacesIFormIControl(s)

ControllerController

CheckInOutInterfaces

CheckInOutModelCheckInOutFactory

CheckInOutDAL

ContactInterfaces

ContactModelContactFactory

ContactDAL

Well, the Event library is omitted.

Page 24: Re-evolving Design Patterns

TODO

Replace custom DAL with NHibernate or similar (in lieu of manual caching).

Templates or other codegen for UI repetitiveness.

ObservableCollection?