Re-evolving Design Patterns
description
Transcript of Re-evolving Design Patterns
![Page 1: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/1.jpg)
Chris Hance
![Page 2: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/2.jpg)
Why “Re-”evolving?
NIH Epidemic My name is Chris, and I’m a… VB6
Coder YAGNI
![Page 3: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/3.jpg)
Who Are You?
1. A Drag-n-drop Developer2. A Design Patterns Practitioner3. Somewhere In Between4. The Heckling Section5. Making A Quick Exit
![Page 4: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/4.jpg)
What Do I Know?
Not as much as I’d like But way too much VB6 and COM
Definitely Certifiable MCDBA on SQL 2000 MCPD on .NET 3.5 Windows Apps
![Page 5: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/5.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 6: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/6.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 7: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/7.jpg)
Antipatterns?
1. Forms Over Data2. Stored Procedures for Everything!3. Naïve OOP
We'll discuss what's wrong and right.
![Page 8: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/8.jpg)
1. Forms Over Data
Sub Form_Load SQL = "Select * From <table>" Set RS = Conn.Execute SQL Do Until RS.EOF Grid.AddItem RS(0) & Tab & RS(1) RS.MoveNext LoopEnd Sub
![Page 9: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/9.jpg)
1.Forms Over Data
No way to share this code That's what Object-Oriented is for, right?
Coder has to know SQL Schema Stored procedures? Data Access Layer (DAL)? Object/Relational Mapper (O/RM)?
![Page 10: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/10.jpg)
2. Stored Procedures for Everything!Sub Form_Load Set RS = Conn.Execute
"prGetMyTable" Do Until RS.EOF Grid.AddItem RS(0) & Tab & RS(1) RS.MoveNext LoopEnd Sub
![Page 11: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/11.jpg)
2. Stored Procedures for Everything! Every change requires a DBA and a
developer. DBAs can change the recordset. Database lock-in?
Some reusability.
![Page 12: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/12.jpg)
3. Naïve OOP
Build an Object Model Link Everything to Everything Edit Anything Commit It All Back?
![Page 13: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/13.jpg)
3. Naïve OOP
Worked fine for Build (Compile) Automation Very little "Commit It All Back" Could only model changes, not the
whole system, for memory and speed. Still hard to change.
Can you "load everything" and "save everything" safely?
![Page 14: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/14.jpg)
3. Simplified Build Model
![Page 15: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/15.jpg)
3. Simplified Student Model
Not simplified enough.
![Page 16: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/16.jpg)
4. Concentrations
Light version of Aggregate RootsEric Evans, Domain Driven Design
Limited models for updating data
Top level = what you're updating Attach child collections / objects Reference other concentrations
![Page 17: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/17.jpg)
4. Concentrations
![Page 18: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/18.jpg)
4. Concentrations
![Page 19: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/19.jpg)
Where do we get data?
Classes self-populate? E.g. Student.LoadByID(int ID) Single Responsibility Principle (SRP)
Violation Unit testing is slow and difficult.
Object/Relational Mapper (ORM) Another learning curve, but worth it.
![Page 20: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/20.jpg)
Where do we get data? (2)
Custom Data Access Layer (DAL) Talks to the database (or is the collection) Retrieves editable objects Save the edited objects Nothing about keeping them consistent in
memory.
![Page 21: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/21.jpg)
Command / Query Separation Don't use your DAL for reports
Don't need to update Don't need to enforce business rules Just need properly linked rows or
hierarchical data
Data Warehouse or raw SQL
![Page 22: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/22.jpg)
Multiple Versions of a DAL Unit Testing – Mock DAL Compatibility with multiple DBs Different implementations for QA /
Prod
Probably requires multiple assemblies Single assembly would contain unused
code Define a DAL interface
![Page 23: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/23.jpg)
Replaceable DAL
![Page 24: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/24.jpg)
Cross-concentration Queries Should one DAL know about another
DAL? CheckOutDAL references ContactDAL?
If not, returned objects are incomplete
If so, do we ever want to "short-circuit" and populate the references locally? Teacher name & room number on
Checkout list by date
![Page 25: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/25.jpg)
Cross-DAL references
![Page 26: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/26.jpg)
Abstract Factory Pattern
Different factories create objects differently, and/or instantiate different classes of the same interface.
Factories are interchangeable (like the previous DALs).
Domain Objects have different behavior or implementation, same interface.
![Page 27: Re-evolving Design Patterns](https://reader035.fdocuments.in/reader035/viewer/2022062423/56814bfd550346895db8f9d5/html5/thumbnails/27.jpg)
Factory vs DAL?
Do you want to separate instantiation and reference setting code from data access?