Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable...
-
Upload
irma-goodwin -
Category
Documents
-
view
224 -
download
1
Transcript of Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable...
![Page 1: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/1.jpg)
RE-EVOLVING DESIGN PATTERNS
Chris Hance
![Page 2: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/2.jpg)
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: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/3.jpg)
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: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/4.jpg)
The Application
Record Student Arrivals / Departures (Check In / Check Out)
Enforce rules on student custody, etc.
Integrate with a legacy VB6 system
![Page 5: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/5.jpg)
Intent: Partial Rewrite
First stab at MVC/MVP/… Isolate UI from Model COM-compatible Standardized Control behavior
![Page 6: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/6.jpg)
Some (COM/VB6) Limitations No constructor parameters No overloading Events "disappear" in interfaces
![Page 7: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/7.jpg)
Attempt #1
UI UberDLL
ModelDALDALStub
Controls"Controller"Form
How many DALs in one DLL?
![Page 8: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/8.jpg)
Attempt #2
UI UberDLL
ModelIDAL
Controls"Controller"Form
DAL
DAL
DALStub
DALStub
CircularDependency
New Rule:Model doesn't talk to the DAL.
![Page 9: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/9.jpg)
Attempt #3
Factory
Factory
UI
Controls"Controller"Form
Model
ModelIDAL
DAL(Stub)
DAL(Stub)
Next: Add Interfaces.
![Page 10: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/10.jpg)
Attempt #4: With Interfaces
Factory
Factory
UI
Controls"Controller"Form
Model
ModelDTO
DAL(Stub)
DAL(Stub)
Interfaces
ModelInterfaceDTOInterfaceFactoryInterfaceDALInterface
![Page 11: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/11.jpg)
Still Awake?
Figure 17. Obligatory Useless Diagram
![Page 12: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/12.jpg)
Low Coupling!What is it good for?
Reusable Code?
Manageable Code Won't somebody think of the
maintenance programmers?
![Page 13: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/13.jpg)
Back to the Application
Concepts
Check-In/Check-Out Student Contact School Teacher User
![Page 14: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/14.jpg)
Multiple Factories
UI
Controls"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: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/15.jpg)
Tour the Model
That means open Visual Studio.Yes, now.
![Page 16: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/16.jpg)
So About the UI
MVC MVP (“retired” per Fowler)
Passive View Supervising Controller
MVVM Presentation Model
![Page 17: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/17.jpg)
Supervising Controller
Figure π¾. Supervising Controller Sequence Diagram http://martinfowler.com/eaaDev/SupervisingPresenter.html
![Page 18: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/18.jpg)
How to test the Controller?
View
FormControl(s)
ViewInterfacesIFormIControl(s)
Controller
Controller
ViewStub
FormStubControlStub(s)
Pick a View at RuntimePick a View at Runtime
![Page 19: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/19.jpg)
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: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/20.jpg)
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: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/21.jpg)
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: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/22.jpg)
Tour the UI
Or what I have of it. (Work in Progress)We can always fall back to VB6 sample
code.
![Page 23: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/23.jpg)
The Whole… Thing
View
FormControl(s)
ViewInterfacesIFormIControl(s)
Controller
Controller
CheckInOutInterfaces
CheckInOutModelCheckInOutFactory
CheckInOutDAL
ContactInterfaces
ContactModelContactFactory
ContactDAL
Well, the Event library is omitted.
![Page 24: Chris Hance. Where do patterns come from? Canonical Answer Design Patterns: Elements of Reusable Object- Oriented Software, “Gang Of Four” Patterns.](https://reader036.fdocuments.in/reader036/viewer/2022062309/56649f285503460f94c41005/html5/thumbnails/24.jpg)
TODO
Replace custom DAL with NHibernate or similar (in lieu of manual caching).
Templates or other codegen for UI repetitiveness.
ObservableCollection?