1 / 24

Re-evolving Design Patterns

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.”.

zasha
Download Presentation

Re-evolving Design Patterns

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chris Hance Re-evolving Design Patterns

  2. 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.”

  3. 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”

  4. The Application • Record Student Arrivals / Departures • (Check In / Check Out) • Enforce rules on student custody, etc. • Integrate with a legacy VB6 system

  5. Intent: Partial Rewrite • First stab at MVC/MVP/… • Isolate UI from Model • COM-compatible • Standardized Control behavior

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

  7. Attempt #1 UI UberDLL Controls "Controller" Form Model DAL DALStub How many DALs in one DLL?

  8. Attempt #2 DAL DAL UI UberDLL Circular Dependency Controls "Controller" Form Model IDAL DALStub DALStub New Rule: Model doesn't talk to the DAL.

  9. Attempt #3 UI Factory Model DAL(Stub) Controls "Controller" Form Factory Model IDAL DAL(Stub) Next: Add Interfaces.

  10. Attempt #4: With Interfaces Interfaces UI Factory Model DAL(Stub) ModelInterface DTOInterface FactoryInterface DALInterface Controls "Controller" Form Factory Model DTO DAL(Stub)

  11. Still Awake? Figure 17. Obligatory Useless Diagram

  12. Low Coupling!What is it good for? • Reusable Code? • Manageable Code • Won't somebody think of the maintenance programmers?

  13. Back to the Application Concepts • Check-In/Check-Out • Student • Contact • School • Teacher • User

  14. Multiple Factories CheckInOutInterfaces CheckInOutModel CheckInOutFactory CheckInOutDAL ContactInterfaces ContactModel ContactFactory ContactDAL UI Controls "Controller" Form Separate the concepts for maintenance programmer sanity, and some reusability. Do I need School, Teacher, Student, etc?

  15. Tour the Model That means open Visual Studio. Yes, now.

  16. So About the UI • MVC • MVP (“retired” per Fowler) • Passive View • Supervising Controller • MVVM • Presentation Model

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

  18. View ViewStub ViewInterfaces Controller Form Control(s) FormStub ControlStub(s) IForm IControl(s) Controller How to test the Controller? Pick a View at Runtime Pick a View at Runtime

  19. 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.

  20. 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

  21. 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.

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

  23. View ViewInterfaces Controller Form Control(s) IForm IControl(s) Controller The Whole… Thing Well, the Event library is omitted. CheckInOutInterfaces CheckInOutModel CheckInOutFactory CheckInOutDAL ContactInterfaces ContactModel ContactFactory ContactDAL

  24. TODO • Replace custom DAL with NHibernate or similar (in lieu of manual caching). • Templates or other codegen for UI repetitiveness. • ObservableCollection?

More Related