SlideShare a Scribd company logo
1 of 59
Design Pattern
Mastery
Steve Smith (@ardalis)
steve@ardalis.com
Ardalis.com
Podcast: WeeklyDevTips.com
Design
Patterns
http://flic.kr/p/8XgqKu
Industry
Agnostic
Patterns exist in all industries.
Design Patterns
By the Gang of Four (GoF).
Literally The First 3
Results…
Search “programmer bookshelf”
Stages of Learning
Stage Zero - Ignorance
Stage One - Awakening
Stage Two - Overzealous
Stage Three – Mastery
http://flic.kr/p/6StgW5
Goal After This Presentation
At least Stage One – Awakening for a number of
useful patterns
Armed with resources to dive deeper into patterns of
interest
Language
http://flic.kr/p/6UpMt9
Overheard during a code
review…
“We have some tight coupling to the database here. We can
probably fix it if we apply some refactorings.
Maybe we can start by extracting an interface. Then we can
extract a method that contains the persistence code.
After that, we can extract that method into its own class that
implements the interface we created.
Then, we should be able to replace the local instantiation of the
class with a parameter we can pass in and assign to a field.”
Consider instead…
“We have some tight coupling to
the database here. Let’s use the
Repository Pattern to eliminate it.”
Design Patterns
Composite
Iterator
Specification
Unit of
Work
A Few Especially Helpful
Patterns
 (Singleton)
 Strategy
 Repository
 Proxy / Decorator
Singleton: Intent
 Ensure a class has only one instance
 Make the class itself responsible for keeping
track of its sole instance
 “There can be only one”
Singleton Structure (not thread-safe)
Singleton Structure
(thread-safe and fast)
Source: http://csharpindepth.com/Articles/General/Singleton.aspx
Singleton Consequences
 The default implementation is not thread-safe
 Avoid in multi-threaded environments
 Avoid in web server scenarios (e.g. ASP.NET)
 Introduce tight coupling among collaborating
classes
 Singletons are notoriously difficult to test
 Commonly regarded as an anti-pattern
Some commercial tools
can be used to mock and
test Singletons
But why would you
intentionally write code
you can only test with
certain premium tools?
Singleton Consequences
 Violates the Single Responsibility
Principle
 Whatever the class does
AND
 Lifetime Management
 Using an IOC/DI Container it is
straightforward to avoid the coupling
and testability issues
Object Lifetime (in ASP.NET
Core)
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
// you don’t need to implement singleton behavior in class!
services.AddSingleton<ISomeService>();
}
Singleton behavior is fine and
often desirable.
Implementing this behavior using the
Singleton Pattern on the class itself is
usually not ideal.
Strategy
http://flic.kr/p/6spkwo
Strategy: Intent
 Encapsulate a family of related algorithms
 Let the algorithm vary and evolve independently from the class(es) that use it
 Allow a class to maintain a single purpose
 Single Responsibility Principle (SRP)
 Also enables Open/Closed Principle (OCP)
 Learn more about SRP and OCP in my Pluralsight course:
 https://www.pluralsight.com/courses/principles-oo-design
Strategy : Structure
Strategy : Common Usage
 Dependency Inversion and Dependency Injection
 Decouple class dependencies and responsibilities
Refactoring Steps
 Create interfaces for each responsibility
 Inject the implementation of the interface via the constructor
 Move the implementation to a new class that implements the interface
Hidden Dependencies
 Classes should declare their dependencies via their constructor
 Follow the Explicit Dependencies Principle
 Avoid hidden dependencies
 Anything the class needs but which is not passed into constructor
 Avoid making non-stateless static calls
 Avoid directly instantiating classes (except those with no dependencies, like
strings)
 Instead, move these calls to an interface, and call a local instance of the interface
“New is
Glue”
Be conscious of the
consequences of using
“new”
If you need loose coupling,
replace “new” with Strategy
Pattern
http://flic.kr/p/aN4Zv
“new” creates tight
coupling between classes
Repository
Data Access Evolution
Initially no separation of concerns
 Data access logic baked directly
into UI
ASP.NET Data Source Controls
Classic ASP scripts
 Data access logic in UI layer via
codebehind
ASP.NET Page_Load event
ASP.NET Button_Click event
User Interface
Database
Compile Time
Runtime
Data Access : Helper Classes
 Calls to data made through a
utility
 Example: Data Access
Application Block (SqlHelper)
 Logic may still live in UI layer
 Or a Business Logic Layer may
make calls to a Data Access
Layer which might then call the
helper
User Interface
Database
Compile Time
Runtime
Helper Class
What’s Missing? Abstraction!
 No way to abstract away data
access
 Tight coupling
 Leads to Big Ball of Mud
system
 Solution:
Depend on interfaces, not
concrete implementations
What should we call such
interfaces? Repositories!
User Interface
Database
Compile Time
Runtime
Core
IFooRepository
Infrastructure
SqlFooRepository
Repository
 A Data Access Pattern
 Introduced as part of Domain-Driven Design
 Very popular outside of DDD
 Separates persistence responsibility from
business and UI classes
Repository Benefits
 Enables Single Responsibility Principle
 Promotes Separation of Concerns
 Reduces coupling to persistence details
 Improves testability
Repository Approaches
 Per Entity
 CustomerRepository
 OrderRepository
 ProductRepository
Repository Approaches
 Generic Implementation
 IRepository<TEntity>
 EfRepository<TEntity>
 With specific implementations where necessary
 ProductRepository (with special product-specific methods added)
Repository Approaches
 Organize by Reads vs. Writes (CQRS)
 IReadRepository<T>
 IWriteRepository<T>
 Organize per Bounded Context
 Organize per Aggregate
 Prevent ability to persist any entity outside of its aggregate
Repository Considerations
 Repositories should return domain objects
 Don’t Return
 Persistence-Specific Types (SqlDataReader, etc.)
 View-Specific Types (OrderPageViewModel)
What should List methods
return?
 IEnumerable<T>
 IQueryable<T>
 What about deferred execution?
 How (and where) to define custom queries?
 What about lazy loading?
Avoid Lazy Loading in Web
Apps
 3 Sessions
 2 Speakers
 2 Tags
Avoid Lazy Loading in Web
Apps
@{
ViewBag.Title = "Home Page";
}
@model IEnumerable<LazyLoadingMvc5.Models.Session>
<h2>Sessions</h2>
@foreach (var session in Model)
{
<div class="row">
<h3>@session.Name</h3>
<h4>@string.Join(",", session.SpeakerSessions?.Select(ss => ss.Speaker.Name).ToArray())</h4>
<h4>@string.Join(",", session.SessionTags?.Select(st => st.Tag.Name).ToArray())</h4>
<p>@session.Description</p>
</div>
} https://ardalis.com/avoid-lazy-loading-entities-in-asp-net-applications
22 Queries!
Stacking Patterns
Repository and Strategy
Example Refactoring
(1)
Create/extend an interface to represent
the data access you need
(2)
Copy the
implementation from
your class into a new
class implementing
this interface.
(3)
Inject the interface using the
Strategy Pattern. Use the local field
of this interface type in place of
previous implementation code.
Where do Repositories
Live?
 Place interfaces in Core
 Core includes Model classes and most business logic
 Core has no dependencies (ideally)
 Place implementation in Infrastructure
 Infrastructure references Core
 UI layer (app entry point) references Core
 Accesses Infrastructure at runtime
 Responsible for creating object graph, either manually or via
an IOC Container
Proxy
Proxy
 A class that controls access to another
 Implemented via subclass or via
delegation using a common interface
 Frequent use cases:
Remote Proxy for web services / network calls
Lazy loading implementations
Security / access control
Proxy - Structure
Bonus Pattern: Decorator!
Adding Caching to a
Repository
 Caching is frequently added to query
methods in repositories
 Caching logic is a separate concern and
should live in a separate class from the
main data access logic
Proxy or Decorator?
Proxy pattern provides a
straightforward means to control
access to the “real” data, versus
the cache.
Decorator pattern adds additional
functionality or behavior: caching.
Proxy – CachedRepository Implementation
Implementing with IOC
(StructureMap)
// Strategy Pattern with Proxy Pattern (using composition)
x.For<IAlbumRepository>().Use<CachedAlbumRepository>()
.Ctor<IAlbumRepository>().Is<EfAlbumRepository>(
);
// Doesn’t work:
x.For<IAlbumRepository>().Use<CachedAlbumRepository>();
Implementing with IOC (.NET
Core)
services.AddTransient<IDataService, DataService>((ctx) =>
{
IOtherService svc = ctx.GetService<IOtherService>();
return new DataService(svc);
});
Practice Pain Driven Development
(PDD)
References
 Design Patterns, http://amzn.to/95q9ux
 Design Patterns Explained, http://amzn.to/cr8Vxb
 Design Patterns in C#, http://amzn.to/bqJgdU
 Head First Design Patterns, http://amzn.to/aA4RS6
Pluralsight Resources
 N-Tier Application Design in C# http://bit.ly/Msrwig
 Design Patterns Library http://bit.ly/vyPEgK
 SOLID Principles of OO Design http://bit.ly/OWF4la
 My Blog
 https://ardalis.com
 Podcast
 https://weeklydevtips.com
Discuss
Contact
steve@ardalis.com
Twitter: @ardalis
Web: ardalis.com
http://about.me/stevenasmith

More Related Content

What's hot

Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing SoftwareSteven Smith
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingSteven Smith
 
Refactoring Applications using SOLID Principles
Refactoring Applications using SOLID PrinciplesRefactoring Applications using SOLID Principles
Refactoring Applications using SOLID PrinciplesSteven Smith
 
Refactoring with SOLID - Telerik India DevCon 2013
Refactoring with SOLID - Telerik India DevCon 2013Refactoring with SOLID - Telerik India DevCon 2013
Refactoring with SOLID - Telerik India DevCon 2013Steven Smith
 
Design Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldDesign Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldSaurabh Moody
 
Principles and patterns for test driven development
Principles and patterns for test driven developmentPrinciples and patterns for test driven development
Principles and patterns for test driven developmentStephen Fuqua
 
Refactoring to SOLID Code
Refactoring to SOLID CodeRefactoring to SOLID Code
Refactoring to SOLID CodeAdil Mughal
 
06 integrating extra features and looking forward
06   integrating extra features and looking forward06   integrating extra features and looking forward
06 integrating extra features and looking forwardМарина Босова
 
An introduction to unit testing
An introduction to unit testingAn introduction to unit testing
An introduction to unit testingAdam Stephensen
 
01 introduction to entity framework
01   introduction to entity framework01   introduction to entity framework
01 introduction to entity frameworkMaxim Shaptala
 
Writing usableap isinpractice
Writing usableap isinpracticeWriting usableap isinpractice
Writing usableap isinpracticeGiovanni Asproni
 
Testing Java EE apps with Arquillian
Testing Java EE apps with ArquillianTesting Java EE apps with Arquillian
Testing Java EE apps with ArquillianIvan Ivanov
 
C++ 11 Style : A Touch of Class
C++ 11 Style : A Touch of ClassC++ 11 Style : A Touch of Class
C++ 11 Style : A Touch of ClassYogendra Rampuria
 
Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013Dror Helper
 

What's hot (20)

Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
 
Refactoring Applications using SOLID Principles
Refactoring Applications using SOLID PrinciplesRefactoring Applications using SOLID Principles
Refactoring Applications using SOLID Principles
 
Refactoring with SOLID - Telerik India DevCon 2013
Refactoring with SOLID - Telerik India DevCon 2013Refactoring with SOLID - Telerik India DevCon 2013
Refactoring with SOLID - Telerik India DevCon 2013
 
Design Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldDesign Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The World
 
Principles and patterns for test driven development
Principles and patterns for test driven developmentPrinciples and patterns for test driven development
Principles and patterns for test driven development
 
Refactoring to SOLID Code
Refactoring to SOLID CodeRefactoring to SOLID Code
Refactoring to SOLID Code
 
06 integrating extra features and looking forward
06   integrating extra features and looking forward06   integrating extra features and looking forward
06 integrating extra features and looking forward
 
An introduction to unit testing
An introduction to unit testingAn introduction to unit testing
An introduction to unit testing
 
01 introduction to entity framework
01   introduction to entity framework01   introduction to entity framework
01 introduction to entity framework
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
IoC and Mapper in C#
IoC and Mapper in C#IoC and Mapper in C#
IoC and Mapper in C#
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
C#/.NET Little Wonders
C#/.NET Little WondersC#/.NET Little Wonders
C#/.NET Little Wonders
 
Writing usableap isinpractice
Writing usableap isinpracticeWriting usableap isinpractice
Writing usableap isinpractice
 
Selenium Frameworks
Selenium FrameworksSelenium Frameworks
Selenium Frameworks
 
Testing Java EE apps with Arquillian
Testing Java EE apps with ArquillianTesting Java EE apps with Arquillian
Testing Java EE apps with Arquillian
 
Design patterns
Design patternsDesign patterns
Design patterns
 
C++ 11 Style : A Touch of Class
C++ 11 Style : A Touch of ClassC++ 11 Style : A Touch of Class
C++ 11 Style : A Touch of Class
 
Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013
 

Similar to Design Pattern Mastery - Momentum Dev Con 19 Apr 2018

Introduction To Design Patterns
Introduction To Design PatternsIntroduction To Design Patterns
Introduction To Design Patternssukumarraju6
 
P Training Presentation
P Training PresentationP Training Presentation
P Training PresentationGaurav Tyagi
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsJason Townsend, MBA
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Luis Valencia
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Pythondn
 
C#.net, C Sharp.Net Online Training Course Content
C#.net, C Sharp.Net Online Training Course ContentC#.net, C Sharp.Net Online Training Course Content
C#.net, C Sharp.Net Online Training Course ContentSVRTechnologies
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxdanhaley45372
 
Repository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity FrameworkRepository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity FrameworkAkhil Mittal
 
chapter 5 Objectdesign.ppt
chapter 5 Objectdesign.pptchapter 5 Objectdesign.ppt
chapter 5 Objectdesign.pptTemesgenAzezew
 
Software development effort reduction with Co-op
Software development effort reduction with Co-opSoftware development effort reduction with Co-op
Software development effort reduction with Co-oplbergmans
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using ReflectionGanesh Samarthyam
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstEnea Gabriel
 
Lunch and learn as3_frameworks
Lunch and learn as3_frameworksLunch and learn as3_frameworks
Lunch and learn as3_frameworksYuri Visser
 
Lublin Startup Festival - Mobile Architecture Design Patterns
Lublin Startup Festival - Mobile Architecture Design PatternsLublin Startup Festival - Mobile Architecture Design Patterns
Lublin Startup Festival - Mobile Architecture Design PatternsKarol Szmaj
 
Enterprise Library 2.0
Enterprise Library 2.0Enterprise Library 2.0
Enterprise Library 2.0Raju Permandla
 

Similar to Design Pattern Mastery - Momentum Dev Con 19 Apr 2018 (20)

Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Introduction To Design Patterns
Introduction To Design PatternsIntroduction To Design Patterns
Introduction To Design Patterns
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design Patterns
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Python
 
C#.net, C Sharp.Net Online Training Course Content
C#.net, C Sharp.Net Online Training Course ContentC#.net, C Sharp.Net Online Training Course Content
C#.net, C Sharp.Net Online Training Course Content
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
 
L09 Frameworks
L09 FrameworksL09 Frameworks
L09 Frameworks
 
Repository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity FrameworkRepository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity Framework
 
chapter 5 Objectdesign.ppt
chapter 5 Objectdesign.pptchapter 5 Objectdesign.ppt
chapter 5 Objectdesign.ppt
 
Design pattern
Design patternDesign pattern
Design pattern
 
Software development effort reduction with Co-op
Software development effort reduction with Co-opSoftware development effort reduction with Co-op
Software development effort reduction with Co-op
 
L05 Frameworks
L05 FrameworksL05 Frameworks
L05 Frameworks
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using Reflection
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code First
 
Lunch and learn as3_frameworks
Lunch and learn as3_frameworksLunch and learn as3_frameworks
Lunch and learn as3_frameworks
 
Lublin Startup Festival - Mobile Architecture Design Patterns
Lublin Startup Festival - Mobile Architecture Design PatternsLublin Startup Festival - Mobile Architecture Design Patterns
Lublin Startup Festival - Mobile Architecture Design Patterns
 
Enterprise Library 2.0
Enterprise Library 2.0Enterprise Library 2.0
Enterprise Library 2.0
 

More from Steven Smith

Clean architecture with asp.net core by Ardalis
Clean architecture with asp.net core by ArdalisClean architecture with asp.net core by Ardalis
Clean architecture with asp.net core by ArdalisSteven Smith
 
Finding Patterns in the Clouds - Cloud Design Patterns
Finding Patterns in the Clouds - Cloud Design PatternsFinding Patterns in the Clouds - Cloud Design Patterns
Finding Patterns in the Clouds - Cloud Design PatternsSteven Smith
 
Introducing Domain Driven Design - codemash
Introducing Domain Driven Design - codemashIntroducing Domain Driven Design - codemash
Introducing Domain Driven Design - codemashSteven Smith
 
Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0Steven Smith
 
Decoupling with Domain Events
Decoupling with Domain EventsDecoupling with Domain Events
Decoupling with Domain EventsSteven Smith
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing SoftwareSteven Smith
 
A Whirldwind Tour of ASP.NET 5
A Whirldwind Tour of ASP.NET 5A Whirldwind Tour of ASP.NET 5
A Whirldwind Tour of ASP.NET 5Steven Smith
 
My Iraq Experience
My Iraq ExperienceMy Iraq Experience
My Iraq ExperienceSteven Smith
 
Add Some DDD to Your ASP.NET MVC, OK?
Add Some DDD to Your ASP.NET MVC, OK?Add Some DDD to Your ASP.NET MVC, OK?
Add Some DDD to Your ASP.NET MVC, OK?Steven Smith
 
Domain-Driven Design with ASP.NET MVC
Domain-Driven Design with ASP.NET MVCDomain-Driven Design with ASP.NET MVC
Domain-Driven Design with ASP.NET MVCSteven Smith
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingSteven Smith
 
Refactoring with SOLID Principles (FalafelCon 2013)
Refactoring with SOLID Principles (FalafelCon 2013)Refactoring with SOLID Principles (FalafelCon 2013)
Refactoring with SOLID Principles (FalafelCon 2013)Steven Smith
 
Common asp.net design patterns aspconf2012
Common asp.net design patterns aspconf2012Common asp.net design patterns aspconf2012
Common asp.net design patterns aspconf2012Steven Smith
 
Common design patterns (migang 16 May 2012)
Common design patterns (migang 16 May 2012)Common design patterns (migang 16 May 2012)
Common design patterns (migang 16 May 2012)Steven Smith
 
Introducing Pair Programming
Introducing Pair ProgrammingIntroducing Pair Programming
Introducing Pair ProgrammingSteven Smith
 
Cinci ug-january2011-anti-patterns
Cinci ug-january2011-anti-patternsCinci ug-january2011-anti-patterns
Cinci ug-january2011-anti-patternsSteven Smith
 

More from Steven Smith (17)

Clean architecture with asp.net core by Ardalis
Clean architecture with asp.net core by ArdalisClean architecture with asp.net core by Ardalis
Clean architecture with asp.net core by Ardalis
 
Finding Patterns in the Clouds - Cloud Design Patterns
Finding Patterns in the Clouds - Cloud Design PatternsFinding Patterns in the Clouds - Cloud Design Patterns
Finding Patterns in the Clouds - Cloud Design Patterns
 
Introducing Domain Driven Design - codemash
Introducing Domain Driven Design - codemashIntroducing Domain Driven Design - codemash
Introducing Domain Driven Design - codemash
 
Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0
 
Decoupling with Domain Events
Decoupling with Domain EventsDecoupling with Domain Events
Decoupling with Domain Events
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 
A Whirldwind Tour of ASP.NET 5
A Whirldwind Tour of ASP.NET 5A Whirldwind Tour of ASP.NET 5
A Whirldwind Tour of ASP.NET 5
 
Domain events
Domain eventsDomain events
Domain events
 
My Iraq Experience
My Iraq ExperienceMy Iraq Experience
My Iraq Experience
 
Add Some DDD to Your ASP.NET MVC, OK?
Add Some DDD to Your ASP.NET MVC, OK?Add Some DDD to Your ASP.NET MVC, OK?
Add Some DDD to Your ASP.NET MVC, OK?
 
Domain-Driven Design with ASP.NET MVC
Domain-Driven Design with ASP.NET MVCDomain-Driven Design with ASP.NET MVC
Domain-Driven Design with ASP.NET MVC
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
 
Refactoring with SOLID Principles (FalafelCon 2013)
Refactoring with SOLID Principles (FalafelCon 2013)Refactoring with SOLID Principles (FalafelCon 2013)
Refactoring with SOLID Principles (FalafelCon 2013)
 
Common asp.net design patterns aspconf2012
Common asp.net design patterns aspconf2012Common asp.net design patterns aspconf2012
Common asp.net design patterns aspconf2012
 
Common design patterns (migang 16 May 2012)
Common design patterns (migang 16 May 2012)Common design patterns (migang 16 May 2012)
Common design patterns (migang 16 May 2012)
 
Introducing Pair Programming
Introducing Pair ProgrammingIntroducing Pair Programming
Introducing Pair Programming
 
Cinci ug-january2011-anti-patterns
Cinci ug-january2011-anti-patternsCinci ug-january2011-anti-patterns
Cinci ug-january2011-anti-patterns
 

Recently uploaded

Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 

Recently uploaded (20)

Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 

Design Pattern Mastery - Momentum Dev Con 19 Apr 2018

  • 1. Design Pattern Mastery Steve Smith (@ardalis) steve@ardalis.com Ardalis.com Podcast: WeeklyDevTips.com
  • 2.
  • 5. Design Patterns By the Gang of Four (GoF).
  • 6. Literally The First 3 Results… Search “programmer bookshelf”
  • 7.
  • 8.
  • 9.
  • 10. Stages of Learning Stage Zero - Ignorance Stage One - Awakening Stage Two - Overzealous Stage Three – Mastery http://flic.kr/p/6StgW5
  • 11. Goal After This Presentation At least Stage One – Awakening for a number of useful patterns Armed with resources to dive deeper into patterns of interest
  • 13. Overheard during a code review… “We have some tight coupling to the database here. We can probably fix it if we apply some refactorings. Maybe we can start by extracting an interface. Then we can extract a method that contains the persistence code. After that, we can extract that method into its own class that implements the interface we created. Then, we should be able to replace the local instantiation of the class with a parameter we can pass in and assign to a field.”
  • 14. Consider instead… “We have some tight coupling to the database here. Let’s use the Repository Pattern to eliminate it.”
  • 15.
  • 17. A Few Especially Helpful Patterns  (Singleton)  Strategy  Repository  Proxy / Decorator
  • 18. Singleton: Intent  Ensure a class has only one instance  Make the class itself responsible for keeping track of its sole instance  “There can be only one”
  • 19. Singleton Structure (not thread-safe)
  • 20. Singleton Structure (thread-safe and fast) Source: http://csharpindepth.com/Articles/General/Singleton.aspx
  • 21. Singleton Consequences  The default implementation is not thread-safe  Avoid in multi-threaded environments  Avoid in web server scenarios (e.g. ASP.NET)  Introduce tight coupling among collaborating classes  Singletons are notoriously difficult to test  Commonly regarded as an anti-pattern Some commercial tools can be used to mock and test Singletons But why would you intentionally write code you can only test with certain premium tools?
  • 22. Singleton Consequences  Violates the Single Responsibility Principle  Whatever the class does AND  Lifetime Management  Using an IOC/DI Container it is straightforward to avoid the coupling and testability issues
  • 23. Object Lifetime (in ASP.NET Core) public void ConfigureServices(IServiceCollection services) { services.AddMvc(); // you don’t need to implement singleton behavior in class! services.AddSingleton<ISomeService>(); }
  • 24. Singleton behavior is fine and often desirable. Implementing this behavior using the Singleton Pattern on the class itself is usually not ideal.
  • 26. Strategy: Intent  Encapsulate a family of related algorithms  Let the algorithm vary and evolve independently from the class(es) that use it  Allow a class to maintain a single purpose  Single Responsibility Principle (SRP)  Also enables Open/Closed Principle (OCP)  Learn more about SRP and OCP in my Pluralsight course:  https://www.pluralsight.com/courses/principles-oo-design
  • 28. Strategy : Common Usage  Dependency Inversion and Dependency Injection  Decouple class dependencies and responsibilities Refactoring Steps  Create interfaces for each responsibility  Inject the implementation of the interface via the constructor  Move the implementation to a new class that implements the interface
  • 29. Hidden Dependencies  Classes should declare their dependencies via their constructor  Follow the Explicit Dependencies Principle  Avoid hidden dependencies  Anything the class needs but which is not passed into constructor  Avoid making non-stateless static calls  Avoid directly instantiating classes (except those with no dependencies, like strings)  Instead, move these calls to an interface, and call a local instance of the interface
  • 30. “New is Glue” Be conscious of the consequences of using “new” If you need loose coupling, replace “new” with Strategy Pattern http://flic.kr/p/aN4Zv “new” creates tight coupling between classes
  • 32. Data Access Evolution Initially no separation of concerns  Data access logic baked directly into UI ASP.NET Data Source Controls Classic ASP scripts  Data access logic in UI layer via codebehind ASP.NET Page_Load event ASP.NET Button_Click event User Interface Database Compile Time Runtime
  • 33. Data Access : Helper Classes  Calls to data made through a utility  Example: Data Access Application Block (SqlHelper)  Logic may still live in UI layer  Or a Business Logic Layer may make calls to a Data Access Layer which might then call the helper User Interface Database Compile Time Runtime Helper Class
  • 34. What’s Missing? Abstraction!  No way to abstract away data access  Tight coupling  Leads to Big Ball of Mud system  Solution: Depend on interfaces, not concrete implementations What should we call such interfaces? Repositories! User Interface Database Compile Time Runtime Core IFooRepository Infrastructure SqlFooRepository
  • 35. Repository  A Data Access Pattern  Introduced as part of Domain-Driven Design  Very popular outside of DDD  Separates persistence responsibility from business and UI classes
  • 36. Repository Benefits  Enables Single Responsibility Principle  Promotes Separation of Concerns  Reduces coupling to persistence details  Improves testability
  • 37. Repository Approaches  Per Entity  CustomerRepository  OrderRepository  ProductRepository
  • 38. Repository Approaches  Generic Implementation  IRepository<TEntity>  EfRepository<TEntity>  With specific implementations where necessary  ProductRepository (with special product-specific methods added)
  • 39. Repository Approaches  Organize by Reads vs. Writes (CQRS)  IReadRepository<T>  IWriteRepository<T>  Organize per Bounded Context  Organize per Aggregate  Prevent ability to persist any entity outside of its aggregate
  • 40. Repository Considerations  Repositories should return domain objects  Don’t Return  Persistence-Specific Types (SqlDataReader, etc.)  View-Specific Types (OrderPageViewModel)
  • 41. What should List methods return?  IEnumerable<T>  IQueryable<T>  What about deferred execution?  How (and where) to define custom queries?  What about lazy loading?
  • 42. Avoid Lazy Loading in Web Apps  3 Sessions  2 Speakers  2 Tags
  • 43. Avoid Lazy Loading in Web Apps @{ ViewBag.Title = "Home Page"; } @model IEnumerable<LazyLoadingMvc5.Models.Session> <h2>Sessions</h2> @foreach (var session in Model) { <div class="row"> <h3>@session.Name</h3> <h4>@string.Join(",", session.SpeakerSessions?.Select(ss => ss.Speaker.Name).ToArray())</h4> <h4>@string.Join(",", session.SessionTags?.Select(st => st.Tag.Name).ToArray())</h4> <p>@session.Description</p> </div> } https://ardalis.com/avoid-lazy-loading-entities-in-asp-net-applications 22 Queries!
  • 46. (1) Create/extend an interface to represent the data access you need (2) Copy the implementation from your class into a new class implementing this interface. (3) Inject the interface using the Strategy Pattern. Use the local field of this interface type in place of previous implementation code.
  • 47. Where do Repositories Live?  Place interfaces in Core  Core includes Model classes and most business logic  Core has no dependencies (ideally)  Place implementation in Infrastructure  Infrastructure references Core  UI layer (app entry point) references Core  Accesses Infrastructure at runtime  Responsible for creating object graph, either manually or via an IOC Container
  • 48. Proxy
  • 49. Proxy  A class that controls access to another  Implemented via subclass or via delegation using a common interface  Frequent use cases: Remote Proxy for web services / network calls Lazy loading implementations Security / access control
  • 52. Adding Caching to a Repository  Caching is frequently added to query methods in repositories  Caching logic is a separate concern and should live in a separate class from the main data access logic
  • 53. Proxy or Decorator? Proxy pattern provides a straightforward means to control access to the “real” data, versus the cache. Decorator pattern adds additional functionality or behavior: caching.
  • 54. Proxy – CachedRepository Implementation
  • 55. Implementing with IOC (StructureMap) // Strategy Pattern with Proxy Pattern (using composition) x.For<IAlbumRepository>().Use<CachedAlbumRepository>() .Ctor<IAlbumRepository>().Is<EfAlbumRepository>( ); // Doesn’t work: x.For<IAlbumRepository>().Use<CachedAlbumRepository>();
  • 56. Implementing with IOC (.NET Core) services.AddTransient<IDataService, DataService>((ctx) => { IOtherService svc = ctx.GetService<IOtherService>(); return new DataService(svc); });
  • 57. Practice Pain Driven Development (PDD)
  • 58. References  Design Patterns, http://amzn.to/95q9ux  Design Patterns Explained, http://amzn.to/cr8Vxb  Design Patterns in C#, http://amzn.to/bqJgdU  Head First Design Patterns, http://amzn.to/aA4RS6 Pluralsight Resources  N-Tier Application Design in C# http://bit.ly/Msrwig  Design Patterns Library http://bit.ly/vyPEgK  SOLID Principles of OO Design http://bit.ly/OWF4la  My Blog  https://ardalis.com  Podcast  https://weeklydevtips.com

Editor's Notes

  1. Contact me if you’d like a 30-day pass to Pluralsight. Please consider some of my courses on design patterns, architecture, and domain-driven design.
  2. General, reusable solutions to common problems Not a complete, finished solution A template, recipe, or approach to solving certain problems Each has a specific name, so we can discuss common elements of design using a common vocabulary
  3. Published in 1977, this book is cited as the inspiration for the classic, Design Patterns book, by the Gang of Four.
  4. Published in 1994, this book is still in its first edition after almost 25 years. Though you can find much of the concepts online, the book is a great reference and if nothing else look great on your bookshelf to impress visitors.
  5. Here are some images of programmer bookshelves I found with a quick google search…
  6. Learning anything – a musical chord, a martial arts technique, etc. Zero: You used a what? Never heard of it. Awakening: Wow, I just learned how XYZ pattern can improve my design. I’m not really sure where it would work in my code, but I’m definitely looking. Overzealous: I totally “get” the XYZ pattern; I’m adding it everywhere I can shoehorn it into my code. My design’s gonna be better now, for sure! Mastery: In response to some specific design pain points, the XYZ pattern was a logical next step and was achieved through a simple refactoring.
  7. Design pattern names provide placeholders or complex abstractions and sets of refactorings.
  8. This is where a lot of people work. Don’t be these guys. When you have a lot of wood to cut, it pays off to periodically sharpen the saw. Sharpening the saw is one of the seven habits of highly effective people. Take time to improve your skills, and practice, and in the long run you will be more effective.
  9. It’s possible for the new Singleton(); line to be called more than once.
  10. Jon Skeet lays out several different ways to implement the Singleton pattern in C#, with different performance and thread safety considerations.
  11. Add Kragle slide next
  12. In my own career as a developer, I’ve seen an evolution in how most data access is performed. I started with classic ASP and soon after, the first version of ASP.NET. In both cases, there was typically little separation of concerns between UI, business rules, and data access. This tended to result in a lot of duplicate concepts and code, as well as direct dependence on a database.
  13. To address the duplication, helper classes were often created to take repetitive tasks and centralize them. However, in this case the runtime program flow still mirrored the compile time dependency tree, in both cases targeting a database. This made testing such applications difficult.
  14. The problem with these approaches is that there is no abstraction layer between the application and its infrastructure – in this case the database.
  15. Consider grabbing repository image from DDD slide here Split into two slides
  16. Consider grabbing repository image from DDD slide here Split into two slides
  17. Note – this cannot easily be tested without an actual database instance in place.
  18. Add image showing Onion Architecture and/or a simple solution with Core, Infrastructure, and Web.
  19. http://en.wikipedia.org/wiki/File:Proxy_concept_en.svg
  20. Note that the structure of the Proxy is very similar to the Strategy pattern, which we already saw (click). The key difference between the two is in the intent. Note that this is just one Proxy implementation – it can also be achieved with a proxy class that inherits from the subject class, rather than sharing a common interface implementation.
  21. TODO: Show an example of adding caching logic to a repository without any separation of concerns. Consider starting with an MVC method that does direct data access without any repository, uses caching, etc, and lament its lack of testability. Perhaps a Music Store method, maybe with some modification.
  22. Don’t try to apply every pattern you know up front.
  23. Update PS links to use referral links
  24. Maybe look for an image representing military orders being received
  25. Ask about Amazon and what actually happens when you place an order there, compared to with most other online stores.
  26. The background for this slide is the FirstOrDefault image I liked for the Null Object pattern
  27. Some polymorphic code
  28. Change this to something that isn’t displayed in the UI layer, such as a function that must be called or a number to be summed.
  29. Apply patterns via refactoring, Not Big Design Up Front
  30. Show the MvcMusicStore application Hg clone https://hg.codeplex.com/forks/ssmith/mvcmusicstorerepositorypattern 
  31. Talk about the CacheDependencyBug in AdSignia and how it was introduced by moving a hard-coded instantiation to a parameter, and then fixed by replacing the parameter with a Factory (lambda).
  32. Update with imagery and review of patterns and when to use them. Fewer words. Don’t be too busy to improve Avoid adding coupling to your system with Singleton Decouple specific implementation from use with Strategy Avoid hidden dependencies; remember New is Glue! Decouple your database with Repository Decouple caching, lazy loading, and other access concerns with Proxy Decouple execution of other actions with Commands Decouple construction with Factory – remember Lazy<T> and lambda as factory shortcuts Cut down on prolific null checks with the Null Object Pattern Don’t try to use every pattern up front – practice Pain Driven Development
  33. Update with imagery and review of patterns and when to use them. Fewer words. Don’t be too busy to improve Avoid adding coupling to your system with Singleton Decouple specific implementation from use with Strategy Avoid hidden dependencies; remember New is Glue! Decouple your database with Repository Decouple caching, lazy loading, and other access concerns with Proxy Decouple execution of other actions with Commands Decouple construction with Factory – remember Lazy<T> and lambda as factory shortcuts Cut down on prolific null checks with the Null Object Pattern Don’t try to use every pattern up front – practice Pain Driven Development
  34. Update with imagery and review of patterns and when to use them. Fewer words. Don’t be too busy to improve Avoid adding coupling to your system with Singleton Decouple specific implementation from use with Strategy Avoid hidden dependencies; remember New is Glue! Decouple your database with Repository Decouple caching, lazy loading, and other access concerns with Proxy Decouple execution of other actions with Commands Decouple construction with Factory – remember Lazy<T> and lambda as factory shortcuts Cut down on prolific null checks with the Null Object Pattern Don’t try to use every pattern up front – practice Pain Driven Development
  35. Update with imagery and review of patterns and when to use them. Fewer words. Don’t be too busy to improve Avoid adding coupling to your system with Singleton Decouple specific implementation from use with Strategy Avoid hidden dependencies; remember New is Glue! Decouple your database with Repository Decouple caching, lazy loading, and other access concerns with Proxy Decouple execution of other actions with Commands Decouple construction with Factory – remember Lazy<T> and lambda as factory shortcuts Cut down on prolific null checks with the Null Object Pattern Don’t try to use every pattern up front – practice Pain Driven Development
  36. Update with imagery and review of patterns and when to use them. Fewer words. Don’t be too busy to improve Avoid adding coupling to your system with Singleton Decouple specific implementation from use with Strategy Avoid hidden dependencies; remember New is Glue! Decouple your database with Repository Decouple caching, lazy loading, and other access concerns with Proxy Decouple execution of other actions with Commands Decouple construction with Factory – remember Lazy<T> and lambda as factory shortcuts Cut down on prolific null checks with the Null Object Pattern Don’t try to use every pattern up front – practice Pain Driven Development
  37. Update with imagery and review of patterns and when to use them. Fewer words. Don’t be too busy to improve Avoid adding coupling to your system with Singleton Decouple specific implementation from use with Strategy Avoid hidden dependencies; remember New is Glue! Decouple your database with Repository Decouple caching, lazy loading, and other access concerns with Proxy Decouple execution of other actions with Commands Decouple construction with Factory – remember Lazy<T> and lambda as factory shortcuts Cut down on prolific null checks with the Null Object Pattern Don’t try to use every pattern up front – practice Pain Driven Development
  38. Update with imagery and review of patterns and when to use them. Fewer words. Don’t be too busy to improve Avoid adding coupling to your system with Singleton Decouple specific implementation from use with Strategy Avoid hidden dependencies; remember New is Glue! Decouple your database with Repository Decouple caching, lazy loading, and other access concerns with Proxy Decouple execution of other actions with Commands Decouple construction with Factory – remember Lazy<T> and lambda as factory shortcuts Cut down on prolific null checks with the Null Object Pattern Don’t try to use every pattern up front – practice Pain Driven Development
  39. Decouple construction with Factory Remember Lazy<T> and lambda as factory shortcuts Remember IOC containers are factories on steroids
  40. Decouple construction with Factory Remember Lazy<T> and lambda as factory shortcuts Remember IOC containers are factories on steroids
  41. Don’t try to apply every pattern you know up front.
  42. Update PS links to use referral links