Design Patterns
Design Patterns
Aamir Khan
Solution Architect
Design Patterns
for 70% of programmers in the world
Saurabh Verma
Solution Architect
I blog at http://www.domaindrivendesign.info
Agenda
• Do you OOPs?
• I hate my job
Normal Classes vs Abstract Classes vs Interfaces
Normal Class: This is a normal class
Shut up !
We know all this
Million Dollar Question? What is Why?
Employee
Developer Manager
Actors in a Movie
IS-A vs HAS-A vs CAN-DO
IS-A Inheritance
Shahrukh Khan is an ACTOR
HAS-A Composition
Movie has ACTORS
CAN-DO Interfaces
Salman Khan can DRIVE BIKE
What is a Pattern
• It describes the problem, the solution, when to apply the solution, and
its consequences.
Behavioral Patterns
Structural Patterns
+
Let’s understand the purpose
Creational
Structural
Behavioral
Single Washroom
between
4 persons
Singleton Pattern
System.Data.SqlClient.SqlClientFactory
Structural Patterns
Façade Pattern
Façade Pattern
Provide a unified interface to set of interfaces in a subsystem.
Example:
a) Every object “IS-A” shape
b) Every shape “HAS-A” draw behavior
Composite Pattern
System.Web.UI.Control (Render Mechanism)
Composite Pattern
System.Web.UI.Control
WebControls.WebControl
WebControls.BaseDataList
WebControls.DataGrid
Adapter Pattern
Adapter Pattern
Convert the interface of a class into another interface clients expect
Legacy
Application
Component
Adapter Framework
Adapter Pattern
GearsTypelib.HtmlDialogHostClass
(Interop.GearsTypelib)
Decorator vs Adapter
Decorator looks like Adapter which “decorates” an existing class to
make it compatible. Though, Decorator doesn’t wants you to decorate
every method in the Adapted class. But who has stopped from doing it.
One Receiver
and
Multiple actions
Command Pattern
System.ComponentModel.Design.MenuCommand
Command Pattern
Saurabh.Learning.DesignPatterns.Patterns.CommandPattern
Strategy Pattern
Strategy Pattern
Define strategies for a performing a behavior and change them
dynamically as per requirement
• This lets the algorithm vary independently from clients that uses it
One behavior
and
Multiple strategies
Strategy Pattern
System.Collections.ArrayList
Template Method
Template Method
Define the skeleton of an algorithm in an operations, deferring some
steps to subclass
Saurabh Verma
Solution Architect