SlideShare a Scribd company logo
1 of 77
Download to read offline
Applying Design
Patterns in Practice
Ganesh Samarthyam
ganesh.samarthyam@gmail.com
Warm-up exercise
Which pattern is this?
	 a)	Visitor	pa+ern	
	 b)	Factory	method	pa+ern	
	 c)	Template	method		pa+ern	
	 d)	Iterator	pa+ern
Which pattern is this?
a)	Decorator	pa+ern		
b)	Composite	pa+ern		
c)	Adapter	pa+ern		
d)	Model-View-Controller	(MVC)	pa+ern
Which pattern is this?
Calendar calendar = b.set(YEAR, 2003).set(MONTH, APRIL).set(DATE, 6)
.set(HOUR, 15).set(MINUTE, 45).set(SECOND, 22)
.setTimeZone(TimeZone.getDefault()).build();
a)	 Factory	method	pa+ern		
b)	 Abstract	factory	pa+ern		
c)	 Builder	pa+ern			
d)	 Decorator	pa+ern
Which pattern is this?
a)	Bridge	pa+ern		
b)	Abstract	factory	pa+ern		
c)	Builder	pa+ern			
d)	Strategy	pa+ern
Which pattern is this?
a)	Bridge	pa+ern		
b)	Decorator	pa+ern		
c)	Builder	pa+ern			
d)	Strategy	pa+ern	
LineNumberReader lnr =
new LineNumberReader(
new BufferedReader(
new FileReader(“./test.c")));
String str = null;
while((str = lnr.readLine()) != null)
System.out.println(lnr.getLineNumber() + ": " + str);
“Applying design principles is the key to creating
high-quality software!”
Architectural principles:
Axis, symmetry, rhythm, datum, hierarchy, transformation
Technology changes fast => FOMO
Focus on “ever green” topics!
For architects: design is the key!
What are design patterns?
recurrent solutions
to common
design problems
Pattern Name
Problem
Solution
Consequences
Why care about patterns?
❖ Patterns capture expert
knowledge in the form of
proven reusable solutions
❖ Better to reuse proven
solutions than to “re-invent”
the wheel
❖ When used correctly, patterns
positively influence software
quality
❖ Creates maintainable,
extensible, and reusable code
3 principles behind patterns
Program to an interface, not to an
implementation
Favor object composition over inheritance
Encapsulate what varies
What is refactoring?
Refactoring (noun): a change
made to the internal structure of
software to make it easier to
understand and cheaper to
modify without changing its
observable behavior
Refactor (verb): to restructure
software by applying a series
of refactorings without
changing its observable
behavior
Smells approach to learn patterns
Scenario
enum ColorScheme { RGB, HSB, HLS, CMYK }
class Color {
private float red, green, blue; // for supporting RGB scheme
private float hue1, saturation1, brightness1; // for supporting HSB scheme
private float hue2, lightness2, saturation2; // for supporting HLS scheme
public Color(float arg1, float arg2, float arg3, ColorScheme cs) {
switch (cs) {
// initialize arg1, arg2, and arg3 based on ColorScheme value
}
}
}
• Assume that you need to support different Color schemes in your software
• RGB (Red, Green, Blue), HSB (Hue, Saturation, Brightness), and HLS (Hue,
Lightness, and Saturation) schemes
• Overloading constructors and differentiating them using enums can become
confusing
• What could be a better design?
A solution using Factory Method pattern
Color
+ GetRGBColor()
+ GetHSBColor()
+ GetHLSColor()
RGBColor
- red : float
- green : float
- blue : float
HSBColor
- hue : float
- saturation : float
- brightness : float
HLSColor
- hue : float
- lightness : float
- saturation : float
A solution using Factory Method pattern
Color
+ GetColor(ColorType)
+ …
RGBColor
- red : float
- green : float
- blue : float
HSBColor
- hue : float
- saturation : float
- brightness : float
HLSColor
- hue : float
- lightness : float
- saturation : float
Factory Method pattern: Structure
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Factory method pattern: Discussion
❖ A class cannot anticipate the
class of objects it must create
❖ A class wants its subclasses to
specify the objects it creates
Define an interface for creating an object, but let subclasses decide which class to
instantiate. Factory method lets a class defer instantiation to subclasses.
❖ Delegate the responsibility
to one of the several helper
subclasses
❖ Also, localize the
knowledge of which
subclass is the delegate
Factory method: Java library example
Logger	logger	=	Logger.getLogger(TestFileLogger.class.getName());
Factory method: Java library example
class SimpleThreadFactory implements ThreadFactory {
public Thread newThread(Runnable r) {
return new Thread(r);
}
}
Scenario
public Locale (String language, // e.g. “en" for English
String script, // e.g., “Arab” for Arabic
String country, // e.g., “us” for United States
String variant, // e.g., “TH” for Thai
LocaleExtensions extensions) // e.g., “ca-buddhist” for Thai Buddhist Calendar
• Assume that you have a Locale class constructor that takes many “optional
constructors”
• Constraint: Only certain variants are allowed - you need to “disallow”
inappropriate combinations(e.g., invalid combination of country and variant) by
throwing IllformedLocaleException.
• Overloading constructors will result in “too many constructors”
• How will you design a solution for this?
Recommended solution
Locale aLocale =
new Locale.Builder()
.setLanguage(“sr")
.setScript(“Latn")
.setRegion("RS")
.build();
• Create a Locale Builder that “builds” and returns an object step-by-step
• Validation will be performed by the individual set methods
• The build() method will return the “built” object
Builder pattern: structure
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Builer pattern: Discussion
❖ Creating or assembling a
complex object can be tedious
Separate the construction of a complex object from its representation so that the same
construction process can create different representations.
❖ Make the algorithm for
creating a complex object
independent of parts that
make up the object and
how they are assembled
❖ The construction process
allows different
representations for the
object that is constructed
Builders common for complex classes
Calendar.Builder b = new Calendar.Builder();
Calendar calendar = b
.set(YEAR, 2003)
.set(MONTH, APRIL)
.set(DATE, 6)
.set(HOUR, 15)
.set(MINUTE, 45)
.set(SECOND, 22)
.setTimeZone(TimeZone.getDefault())
.build();
System.out.println(calendar);
Scenario
❖ Consider a Route class in an
application like Google Maps
❖ For finding shortest path from
source to destination, many
algorithms can be used
❖ The problem is that these
algorithms get embedded into
Route class and cannot be
reused easily (smell!)
Route
+ SetRoute(Location, Location)
+ FindShortestPathJohnson()
+ FindShortestDijkstra()
+ FindShortestBellmanFord()
+ …
How will you refactor such that
a) Support for shortest path
algorithm can be added easily?
b) Separate path finding logic
from dealing with location
information.
How about this solution?
ShortestPathAlgos
+ FindPath()
JohnsonsAlgo DijkstrasAlgo
Route
+ SetRoute(Locati
on, Location)
+ ShortestPath()
+ …
You’re right: Its Strategy pattern!
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Strategy pattern: Discussion
❖ Useful when there is a set of
related algorithms and a client
object needs to be able to
dynamically pick and choose
an algorithm that suits its
current need
Defines a family of algorithms, encapsulates each one, and makes
them interchangeable. Strategy lets the algorithm vary
independently from clients that use it
❖ The implementation of each of the
algorithms is kept in a separate
class referred to as a strategy.
❖ An object that uses a Strategy
object is referred to as a context
object.
❖ Changing the behavior of a
Context object is a matter of
changing its Strategy object to the
one that implements the required
algorithm
Wait, what principle did we apply?
Open Closed Principle (OCP)
Bertrand Meyer
Software entities should be open for
extension, but closed for modification
SOLID principles
•  There&should&never&be&more&than&one&reason&for&a&class&to&
change&&
Single'Responsibility'
Principle'(SRP)'
•  So6ware&en88es&(classes,&modules,&func8ons,&etc.)&should&
be&open&for&extension,&but&closed&for&modifica8on&
Open'Closed'Principle'
(OCP)'
•  Pointers&or&references&to&base&classes&must&be&able&to&use&
objects&of&derived&classes&without&knowing&it&
Liskov’s'Subs<tu<on'
Principle'(LSP)'
•  Depend&on&abstrac8ons,&not&on&concre8ons&
Dependency'Inversion'
Principle'(DIP)'
•  Many&clientGspecific&interfaces&are&beHer&than&one&
generalGpurpose&interface&
Interface'Segrega<on'
Principle'(ISP)'
Variation Encapsulation Principle (VEP)
Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides
Encapsulate the concept that varies
Fundamental principle: Encapsulation
The principle of encapsulation advocates separation of concerns and
information hiding through techniques such as hiding implementation
details of abstractions and hiding variations
What do you mean by “principle”?
“Design principles are key notions considered
fundamental to many different software design
approaches and concepts. They are also called
enabling techniques.”
- SWEBOK ‘04
Design determines qualities
Understandability Changeability Extensibility
Reusability Testability Reliability
DESIGN
impacts
impacts
impacts
Scenario
Initial design
TextView
+ Draw()
BorderedTextView
+ Draw()
+ DrawBorder()
Real scenario
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Supporting new requirements
Revised design with
new requirements
TextView
+ Draw()
BorderedTextView
+ Draw()
+ DrawBorder()
ScrollableTextView
ScrollableBordered
TextView
- borderWidth
+ Draw()
+ ScrollTo()
- ScrollPosition
+ Draw()
+ ScrollTo()
+ DrawBorder()
- ScrollPosition
- borderWidth
Scenario
❖ How will you refactor such
that:
❖ You don't have to “multiply-
out” sub-types? (i.e., avoid
“explosion of classes”)
❖ You can add or remove
responsibilities (e.g.,
scrolling)?
Next change:
smelly design
How about this solution?
VisualComponent
+ Draw()
TextView
+ Draw()
ScrollDecortor BorderDecorator
+ Draw()
+ ScrollTo()
- ScrollPosition
+ Draw()
+ DrawBorder()
- borderWidth
Decorator
+ Draw() component->Draw()
Decorator::Draw()
DrawBorder()
Decorator::Draw()
ScrollTo()
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Can you identify the pattern?
VisualComponent
+ Draw()
TextView
+ Draw()
ScrollDecortor BorderDecorator
+ Draw()
+ ScrollTo()
- ScrollPosition
+ Draw()
+ DrawBorder()
- borderWidth
Decorator
+ Draw() component->Draw()
Decorator::Draw()
DrawBorder()
Decorator::Draw()
ScrollTo()
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
You’re right: Its Decorator pattern!
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Decorator pattern: Discussion
❖ Want to add responsibilities to
individual objects (not an
entire class)
❖ One way is to use inheritance
❖ Inflexible; static choice
❖ Hard to add and remove
responsibilities dynamically
Attach additional responsibilities to an object dynamically. Decorators
provide a flexible alternative to subclassing for extending functionality
❖ Add responsibilities through
decoration
❖ in a way transparent to the
clients
❖ Decorator forwards the requests to
the contained component to
perform additional actions
❖ Can nest recursively
❖ Can add an unlimited number
of responsibilities dynamically
Identify pattern used in this code
LineNumberReader lnr =
new LineNumberReader(
new BufferedReader(
new FileReader(“./test.c")));
String str = null;
while((str = lnr.readLine()) != null)
System.out.println(lnr.getLineNumber() + ": " + str);
Decorator pattern in Reader
Decorator pattern extensively used in library designs
Scenario
a) How do we treat files
and folders alike?
b) How can we handle
shortcuts?
File
+ GetName()
+ GetSize()
+ …
- name: String
- size: int
- type: FileType
- data: char[]
- …
Folder
+ GetName()
+ GetFiles()
+ GetFolders()
+ …
- name: String
- files[]: File
- folders[]: Folder
How about this solution?
FileItem
+ GetName()
+ GetSize()
+ Add(FileItem)
+ Remove(FileItem)
Folder
+ GetFiles()
+ …
File
- files: FileItem
+ GetType()
+ GetContents()
+ …
- type: FileType
- data: char[]
Shortcut
+ GetLinkedFileItem()
+ …
- linkToFile: FileItem
Composite pattern
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Composite pattern: Discussion
❖ There are many situations where
a group of components form
larger components
❖ Simplistic approach: Make
container component contain
primitive ones
❖ Problem: Code has to treat
container and primitive
components differently
Compose objects into tree structures to represent part-whole hierarchies. Composite
lets client treat individual objects and compositions of objects uniformly.
❖ Perform recursive
composition of
components
❖ Clients don’t have to
treat container and
primitive components
differently
Decorator vs. Composite
Decorator and composite structure looks similar:
Decorator is a degenerate form of Composite!
Decorator Composite
At max. one component Can have many components
Adds responsibilities Aggregates objects
Does not make sense to have
methods such as Add(),
Remove(), GetChid() etc.
Has methods such as Add(),
Remove(), GetChild(), etc.
Composite pattern extensively used in library designs
Scenario
How to separate:
a) code generation logic
from node types?
b) how to support different
target types?
class Plus extends Expr {
private Expr left, right;
public Plus(Expr arg1, Expr arg2) {
left = arg1;
right = arg2;
}
public void genCode() {
left.genCode();
right.genCode();
if(t == Target.JVM) {
System.out.println("iadd");
}
else { // DOTNET
System.out.println("add");
}
}
}
Group exercise -
Understanding visitor pattern
A solution using Visitor pattern
class Plus extends Expr {
private Expr left, right;
public Plus(Expr arg1, Expr arg2) {
left = arg1;
right = arg2;
}
public Expr getLeft() {
return left;
}
public Expr getRight() {
return right;
}
public void accept(Visitor v) {
v.visit(this);
}
}
class DOTNETVisitor extends Visitor {
public void visit(Constant arg) {
System.out.println("ldarg " + arg.getVal());
}
public void visit(Plus plus) {
genCode(plus.getLeft());
genCode(plus.getRight());
System.out.println("add");
}
public void visit(Sub sub) {
genCode(sub.getLeft());
genCode(sub.getRight());
System.out.println("sub");
}
public void genCode(Expr expr) {
expr.accept(this);
}
}
Visitor pattern: structure
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Visitor pattern: call sequence
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Visitor pattern: Discussion
❖ Many distinct and unrelated
operations need to be
performed on objects in an
object structure, and you want
to avoid “polluting” their
classes with these operations
Represent an operation to be performed on the elements of an object structure.
Visitor lets you define a new operation without changing the classes of the
elements on which it operations
❖ Create two class
hierarchies:
❖ One for the elements
being operated on
❖ One for the visitors that
define operations on the
elements
Patterns discussed so far
✓ Builder pattern
✓ Factory method pattern
✓ Strategy pattern
✓ Decorator pattern
✓ Composite pattern
✓ Visitor pattern
Can you recap these
patterns?
What architectural style is
this?
Real-world pipes-and-filters
sediment
pre-
carbon
ultra-filter
post-
carbon
Filtered
water
Pipe-and-filter style
Pipe-and-filter: Benefits
+ Flexibility by filter exchange
+ Flexibility by recombination
+ Reuse of filter components
+ Rapid prototyping of pipelines
Frank Buschmann, Regine Meunier, Hans Rohnert, Peter Sommerlad, and Michael Stal. 1996. Pattern-Oriented Software Architecture: A System of Patterns. John Wiley & Sons, Inc., NY, USA.
Pipe-and-filter: Liabilities
- Sharing state information is expensive or
inflexible
- Efficiency gain by parallel processing is
often an illusion
- Data transformation overhead
- Difficult to handle errors
Frank Buschmann, Regine Meunier, Hans Rohnert, Peter Sommerlad, and Michael Stal. 1996. Pattern-Oriented Software Architecture: A System of Patterns. John Wiley & Sons, Inc., NY, USA.
What are your takeaways?
http://www.amazon.in/dp/935107305X
“Applying design principles is the key to creating
high-quality software!”
Architectural principles:
Axis, symmetry, rhythm, datum, hierarchy, transformation
Image/video credits
❖ http://en.wikipedia.org/wiki/Fear_of_missing_out
❖ http://lesliejanemoran.blogspot.in/2010_05_01_archive.html
❖ http://javra.eu/wp-content/uploads/2013/07/angry_laptop2.jpg
❖ https://www.youtube.com/watch?v=5R8XHrfJkeg
❖ http://womenworld.org/image/052013/31/113745161.jpg
❖ http://www.fantom-xp.com/wallpapers/33/I'm_not_sure.jpg
❖ https://www.flickr.com/photos/31457017@N00/453784086
❖ https://www.gradtouch.com/uploads/images/question3.jpg
❖ http://gurujohn.files.wordpress.com/2008/06/bookcover0001.jpg
❖ http://upload.wikimedia.org/wikipedia/commons/d/d5/Martin_Fowler_-_Swipe_Conference_2012.jpg
❖ http://www.codeproject.com/KB/architecture/csdespat_2/dpcs_br.gif
❖ http://upload.wikimedia.org/wikipedia/commons/thumb/2/28/Bertrand_Meyer_IMG_2481.jpg/440px-
Bertrand_Meyer_IMG_2481.jpg
❖ http://takeji-soft.up.n.seesaa.net/takeji-soft/image/GOF-OOPLSA-94-Color-75.jpg?d=a0
❖ https://developer.apple.com/library/ios/documentation/cocoa/Conceptual/OOP_ObjC/Art/watchcalls_35.gif
❖ http://www.pluspack.com/files/billeder/Newsletter/25/takeaway_bag.png
❖ http://cdn1.tnwcdn.com/wp-content/blogs.dir/1/files/2013/03/design.jpg
ganesh@codeops.tech @GSamarthyam
www.codeops.tech slideshare.net/sgganesh
+91 98801 64463 bit.ly/ganeshsg

More Related Content

What's hot

Curso : Introdução Orientação a Objetos
Curso : Introdução Orientação a ObjetosCurso : Introdução Orientação a Objetos
Curso : Introdução Orientação a Objetosdanielrpgj30
 
Encapsulation in C++
Encapsulation in C++Encapsulation in C++
Encapsulation in C++Hitesh Kumar
 
[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?NAVER D2
 
Presentation Csharp et winforms
Presentation Csharp et winformsPresentation Csharp et winforms
Presentation Csharp et winformsChristophe Zome
 
Cohesion et couplage
Cohesion et couplage Cohesion et couplage
Cohesion et couplage Ahmed HARRAK
 
Introduction à spring boot
Introduction à spring bootIntroduction à spring boot
Introduction à spring bootAntoine Rey
 
Java orientação a objetos (variaveis de instancia e metodos)
Java   orientação a objetos (variaveis de instancia e metodos)Java   orientação a objetos (variaveis de instancia e metodos)
Java orientação a objetos (variaveis de instancia e metodos)Armando Daniel
 
Polimorfismo java
Polimorfismo javaPolimorfismo java
Polimorfismo javaFAFICA
 
Type script - advanced usage and practices
Type script  - advanced usage and practicesType script  - advanced usage and practices
Type script - advanced usage and practicesIwan van der Kleijn
 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVMRafael Winterhalter
 
[TGDF 2019] Mali GPU Architecture and Mobile Studio
[TGDF 2019] Mali GPU Architecture and Mobile Studio[TGDF 2019] Mali GPU Architecture and Mobile Studio
[TGDF 2019] Mali GPU Architecture and Mobile StudioOwen Wu
 
Classes abstratas
Classes abstratasClasses abstratas
Classes abstratasPedro Neto
 
Création de Vues | SQL Oracle
Création de Vues | SQL OracleCréation de Vues | SQL Oracle
Création de Vues | SQL Oraclewebreaker
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQLJoel Brewer
 
Functional and Algebraic Domain Modeling
Functional and Algebraic Domain ModelingFunctional and Algebraic Domain Modeling
Functional and Algebraic Domain ModelingDebasish Ghosh
 

What's hot (20)

Curso : Introdução Orientação a Objetos
Curso : Introdução Orientação a ObjetosCurso : Introdução Orientação a Objetos
Curso : Introdução Orientação a Objetos
 
Encapsulation in C++
Encapsulation in C++Encapsulation in C++
Encapsulation in C++
 
POO - Aula 09 - Herança
POO - Aula 09 - HerançaPOO - Aula 09 - Herança
POO - Aula 09 - Herança
 
[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?[143] Modern C++ 무조건 써야 해?
[143] Modern C++ 무조건 써야 해?
 
Presentation Csharp et winforms
Presentation Csharp et winformsPresentation Csharp et winforms
Presentation Csharp et winforms
 
Classes abstratas e interfaces
Classes abstratas e interfacesClasses abstratas e interfaces
Classes abstratas e interfaces
 
Cohesion et couplage
Cohesion et couplage Cohesion et couplage
Cohesion et couplage
 
Introduction à spring boot
Introduction à spring bootIntroduction à spring boot
Introduction à spring boot
 
Java orientação a objetos (variaveis de instancia e metodos)
Java   orientação a objetos (variaveis de instancia e metodos)Java   orientação a objetos (variaveis de instancia e metodos)
Java orientação a objetos (variaveis de instancia e metodos)
 
Polimorfismo java
Polimorfismo javaPolimorfismo java
Polimorfismo java
 
Type script - advanced usage and practices
Type script  - advanced usage and practicesType script  - advanced usage and practices
Type script - advanced usage and practices
 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVM
 
[TGDF 2019] Mali GPU Architecture and Mobile Studio
[TGDF 2019] Mali GPU Architecture and Mobile Studio[TGDF 2019] Mali GPU Architecture and Mobile Studio
[TGDF 2019] Mali GPU Architecture and Mobile Studio
 
Classes abstratas
Classes abstratasClasses abstratas
Classes abstratas
 
Modele mvc
Modele mvcModele mvc
Modele mvc
 
Création de Vues | SQL Oracle
Création de Vues | SQL OracleCréation de Vues | SQL Oracle
Création de Vues | SQL Oracle
 
Support NodeJS avec TypeScript Express MongoDB
Support NodeJS avec TypeScript Express MongoDBSupport NodeJS avec TypeScript Express MongoDB
Support NodeJS avec TypeScript Express MongoDB
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQL
 
Présentation Docker
Présentation DockerPrésentation Docker
Présentation Docker
 
Functional and Algebraic Domain Modeling
Functional and Algebraic Domain ModelingFunctional and Algebraic Domain Modeling
Functional and Algebraic Domain Modeling
 

Viewers also liked

Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patternspradeepkothiyal
 
The visitor design pattern
The visitor design patternThe visitor design pattern
The visitor design patternSamnang Chhun
 
9781111530532 ppt ch14
9781111530532 ppt ch149781111530532 ppt ch14
9781111530532 ppt ch14Terry Yoast
 
9781285852744 ppt ch16
9781285852744 ppt ch169781285852744 ppt ch16
9781285852744 ppt ch16Terry Yoast
 
Data Structures- Part8 stacks and queues
Data Structures- Part8 stacks and queuesData Structures- Part8 stacks and queues
Data Structures- Part8 stacks and queuesAbdullah Al-hazmy
 
Data Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsData Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsAbdullah Al-hazmy
 
Data Structures- Part9 trees simplified
Data Structures- Part9 trees simplifiedData Structures- Part9 trees simplified
Data Structures- Part9 trees simplifiedAbdullah Al-hazmy
 
AWS Innovate: AWS Container Management using Amazon EC2 Container Service an...
AWS Innovate:  AWS Container Management using Amazon EC2 Container Service an...AWS Innovate:  AWS Container Management using Amazon EC2 Container Service an...
AWS Innovate: AWS Container Management using Amazon EC2 Container Service an...Amazon Web Services Korea
 
AWS ECS Quick Introduction
AWS ECS Quick IntroductionAWS ECS Quick Introduction
AWS ECS Quick IntroductionVinothini Raju
 
Web Database
Web DatabaseWeb Database
Web Databaseidroos7
 
10 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 810 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 8Garth Gilmour
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked listsAbdullah Al-hazmy
 
S.O.L.I.D. Principles for Software Architects
S.O.L.I.D. Principles for Software ArchitectsS.O.L.I.D. Principles for Software Architects
S.O.L.I.D. Principles for Software ArchitectsRicardo Wilkins
 
Java 8 Support at the JVM Level
Java 8 Support at the JVM LevelJava 8 Support at the JVM Level
Java 8 Support at the JVM LevelNikita Lipsky
 
Advanced Java - Praticals
Advanced Java - PraticalsAdvanced Java - Praticals
Advanced Java - PraticalsFahad Shaikh
 
How to name things: the hardest problem in programming
How to name things: the hardest problem in programmingHow to name things: the hardest problem in programming
How to name things: the hardest problem in programmingPeter Hilton
 

Viewers also liked (20)

The Visitor Pattern
The Visitor PatternThe Visitor Pattern
The Visitor Pattern
 
Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patterns
 
The visitor design pattern
The visitor design patternThe visitor design pattern
The visitor design pattern
 
Visitor pattern
Visitor patternVisitor pattern
Visitor pattern
 
9781111530532 ppt ch14
9781111530532 ppt ch149781111530532 ppt ch14
9781111530532 ppt ch14
 
9781285852744 ppt ch16
9781285852744 ppt ch169781285852744 ppt ch16
9781285852744 ppt ch16
 
Chap01
Chap01Chap01
Chap01
 
Data Structures- Part8 stacks and queues
Data Structures- Part8 stacks and queuesData Structures- Part8 stacks and queues
Data Structures- Part8 stacks and queues
 
Data Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsData Structures- Part2 analysis tools
Data Structures- Part2 analysis tools
 
Data Structures- Part9 trees simplified
Data Structures- Part9 trees simplifiedData Structures- Part9 trees simplified
Data Structures- Part9 trees simplified
 
AWS Innovate: AWS Container Management using Amazon EC2 Container Service an...
AWS Innovate:  AWS Container Management using Amazon EC2 Container Service an...AWS Innovate:  AWS Container Management using Amazon EC2 Container Service an...
AWS Innovate: AWS Container Management using Amazon EC2 Container Service an...
 
AWS ECS Quick Introduction
AWS ECS Quick IntroductionAWS ECS Quick Introduction
AWS ECS Quick Introduction
 
Lecture 2a arrays
Lecture 2a arraysLecture 2a arrays
Lecture 2a arrays
 
Web Database
Web DatabaseWeb Database
Web Database
 
10 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 810 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 8
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
 
S.O.L.I.D. Principles for Software Architects
S.O.L.I.D. Principles for Software ArchitectsS.O.L.I.D. Principles for Software Architects
S.O.L.I.D. Principles for Software Architects
 
Java 8 Support at the JVM Level
Java 8 Support at the JVM LevelJava 8 Support at the JVM Level
Java 8 Support at the JVM Level
 
Advanced Java - Praticals
Advanced Java - PraticalsAdvanced Java - Praticals
Advanced Java - Praticals
 
How to name things: the hardest problem in programming
How to name things: the hardest problem in programmingHow to name things: the hardest problem in programming
How to name things: the hardest problem in programming
 

Similar to Applying Design Patterns in Practice

Design patterns through refactoring
Design patterns through refactoringDesign patterns through refactoring
Design patterns through refactoringGanesh Samarthyam
 
Software Architecture: Principles, Patterns and Practices
Software Architecture: Principles, Patterns and PracticesSoftware Architecture: Principles, Patterns and Practices
Software Architecture: Principles, Patterns and PracticesGanesh Samarthyam
 
Applying Design Principles in Practice
Applying Design Principles in PracticeApplying Design Principles in Practice
Applying Design Principles in PracticeTushar Sharma
 
Applying Design Principles in Practice - ISEC 2015 Tutorial
Applying Design Principles in Practice - ISEC 2015 TutorialApplying Design Principles in Practice - ISEC 2015 Tutorial
Applying Design Principles in Practice - ISEC 2015 TutorialGanesh Samarthyam
 
SOLID Principles and Design Patterns
SOLID Principles and Design PatternsSOLID Principles and Design Patterns
SOLID Principles and Design PatternsGanesh Samarthyam
 
Machine Learning with ML.NET and Azure - Andy Cross
Machine Learning with ML.NET and Azure - Andy CrossMachine Learning with ML.NET and Azure - Andy Cross
Machine Learning with ML.NET and Azure - Andy CrossAndrew Flatters
 
How to crack java script certification
How to crack java script certificationHow to crack java script certification
How to crack java script certificationKadharBashaJ
 
Scalable Ensemble Machine Learning @ Harvard Health Policy Data Science Lab
Scalable Ensemble Machine Learning @ Harvard Health Policy Data Science LabScalable Ensemble Machine Learning @ Harvard Health Policy Data Science Lab
Scalable Ensemble Machine Learning @ Harvard Health Policy Data Science LabSri Ambati
 
Design patterns
Design patternsDesign patterns
Design patternsnisheesh
 
Vital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and Spark
Vital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and SparkVital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and Spark
Vital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and SparkVital.AI
 
Web Development using Ruby on Rails
Web Development using Ruby on RailsWeb Development using Ruby on Rails
Web Development using Ruby on RailsAvi Kedar
 
Distributed GLM with H2O - Atlanta Meetup
Distributed GLM with H2O - Atlanta MeetupDistributed GLM with H2O - Atlanta Meetup
Distributed GLM with H2O - Atlanta MeetupSri Ambati
 
New Ideas for Old Code - Greach
New Ideas for Old Code - GreachNew Ideas for Old Code - Greach
New Ideas for Old Code - GreachHamletDRC
 

Similar to Applying Design Patterns in Practice (20)

Design patterns through refactoring
Design patterns through refactoringDesign patterns through refactoring
Design patterns through refactoring
 
Software Architecture: Principles, Patterns and Practices
Software Architecture: Principles, Patterns and PracticesSoftware Architecture: Principles, Patterns and Practices
Software Architecture: Principles, Patterns and Practices
 
Applying Design Principles in Practice
Applying Design Principles in PracticeApplying Design Principles in Practice
Applying Design Principles in Practice
 
Applying Design Principles in Practice - ISEC 2015 Tutorial
Applying Design Principles in Practice - ISEC 2015 TutorialApplying Design Principles in Practice - ISEC 2015 Tutorial
Applying Design Principles in Practice - ISEC 2015 Tutorial
 
CPP15 - Inheritance
CPP15 - InheritanceCPP15 - Inheritance
CPP15 - Inheritance
 
SOLID Principles and Design Patterns
SOLID Principles and Design PatternsSOLID Principles and Design Patterns
SOLID Principles and Design Patterns
 
Machine Learning with ML.NET and Azure - Andy Cross
Machine Learning with ML.NET and Azure - Andy CrossMachine Learning with ML.NET and Azure - Andy Cross
Machine Learning with ML.NET and Azure - Andy Cross
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
How to crack java script certification
How to crack java script certificationHow to crack java script certification
How to crack java script certification
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
 
Scalable Ensemble Machine Learning @ Harvard Health Policy Data Science Lab
Scalable Ensemble Machine Learning @ Harvard Health Policy Data Science LabScalable Ensemble Machine Learning @ Harvard Health Policy Data Science Lab
Scalable Ensemble Machine Learning @ Harvard Health Policy Data Science Lab
 
Overview of the Hive Stinger Initiative
Overview of the Hive Stinger InitiativeOverview of the Hive Stinger Initiative
Overview of the Hive Stinger Initiative
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Vital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and Spark
Vital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and SparkVital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and Spark
Vital AI MetaQL: Queries Across NoSQL, SQL, Sparql, and Spark
 
Bdd with m spec
Bdd with m specBdd with m spec
Bdd with m spec
 
Web Development using Ruby on Rails
Web Development using Ruby on RailsWeb Development using Ruby on Rails
Web Development using Ruby on Rails
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Distributed GLM with H2O - Atlanta Meetup
Distributed GLM with H2O - Atlanta MeetupDistributed GLM with H2O - Atlanta Meetup
Distributed GLM with H2O - Atlanta Meetup
 
New Ideas for Old Code - Greach
New Ideas for Old Code - GreachNew Ideas for Old Code - Greach
New Ideas for Old Code - Greach
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 

More from Ganesh Samarthyam

Applying Refactoring Tools in Practice
Applying Refactoring Tools in PracticeApplying Refactoring Tools in Practice
Applying Refactoring Tools in PracticeGanesh Samarthyam
 
CFP - 1st Workshop on “AI Meets Blockchain”
CFP - 1st Workshop on “AI Meets Blockchain”CFP - 1st Workshop on “AI Meets Blockchain”
CFP - 1st Workshop on “AI Meets Blockchain”Ganesh Samarthyam
 
Great Coding Skills Aren't Enough
Great Coding Skills Aren't EnoughGreat Coding Skills Aren't Enough
Great Coding Skills Aren't EnoughGanesh Samarthyam
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionGanesh Samarthyam
 
Coding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeCoding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeGanesh Samarthyam
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesGanesh Samarthyam
 
Bangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief PresentationBangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief PresentationGanesh Samarthyam
 
Bangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - PosterBangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - PosterGanesh Samarthyam
 
Software Design in Practice (with Java examples)
Software Design in Practice (with Java examples)Software Design in Practice (with Java examples)
Software Design in Practice (with Java examples)Ganesh Samarthyam
 
OO Design and Design Patterns in C++
OO Design and Design Patterns in C++ OO Design and Design Patterns in C++
OO Design and Design Patterns in C++ Ganesh Samarthyam
 
Bangalore Container Conference 2017 - Sponsorship Deck
Bangalore Container Conference 2017 - Sponsorship DeckBangalore Container Conference 2017 - Sponsorship Deck
Bangalore Container Conference 2017 - Sponsorship DeckGanesh Samarthyam
 
Let's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming LanguageLet's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming LanguageGanesh Samarthyam
 
Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction Ganesh Samarthyam
 
Java Generics - Quiz Questions
Java Generics - Quiz QuestionsJava Generics - Quiz Questions
Java Generics - Quiz QuestionsGanesh Samarthyam
 
Software Architecture - Quiz Questions
Software Architecture - Quiz QuestionsSoftware Architecture - Quiz Questions
Software Architecture - Quiz QuestionsGanesh Samarthyam
 
Core Java: Best practices and bytecodes quiz
Core Java: Best practices and bytecodes quizCore Java: Best practices and bytecodes quiz
Core Java: Best practices and bytecodes quizGanesh Samarthyam
 

More from Ganesh Samarthyam (20)

Wonders of the Sea
Wonders of the SeaWonders of the Sea
Wonders of the Sea
 
Animals - for kids
Animals - for kids Animals - for kids
Animals - for kids
 
Applying Refactoring Tools in Practice
Applying Refactoring Tools in PracticeApplying Refactoring Tools in Practice
Applying Refactoring Tools in Practice
 
CFP - 1st Workshop on “AI Meets Blockchain”
CFP - 1st Workshop on “AI Meets Blockchain”CFP - 1st Workshop on “AI Meets Blockchain”
CFP - 1st Workshop on “AI Meets Blockchain”
 
Great Coding Skills Aren't Enough
Great Coding Skills Aren't EnoughGreat Coding Skills Aren't Enough
Great Coding Skills Aren't Enough
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - Description
 
Coding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeCoding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean Code
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on Examples
 
Bangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief PresentationBangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief Presentation
 
Bangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - PosterBangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - Poster
 
Software Design in Practice (with Java examples)
Software Design in Practice (with Java examples)Software Design in Practice (with Java examples)
Software Design in Practice (with Java examples)
 
OO Design and Design Patterns in C++
OO Design and Design Patterns in C++ OO Design and Design Patterns in C++
OO Design and Design Patterns in C++
 
Bangalore Container Conference 2017 - Sponsorship Deck
Bangalore Container Conference 2017 - Sponsorship DeckBangalore Container Conference 2017 - Sponsorship Deck
Bangalore Container Conference 2017 - Sponsorship Deck
 
Let's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming LanguageLet's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming Language
 
Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction
 
Java Generics - Quiz Questions
Java Generics - Quiz QuestionsJava Generics - Quiz Questions
Java Generics - Quiz Questions
 
Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
 
Software Architecture - Quiz Questions
Software Architecture - Quiz QuestionsSoftware Architecture - Quiz Questions
Software Architecture - Quiz Questions
 
Docker by Example - Quiz
Docker by Example - QuizDocker by Example - Quiz
Docker by Example - Quiz
 
Core Java: Best practices and bytecodes quiz
Core Java: Best practices and bytecodes quizCore Java: Best practices and bytecodes quiz
Core Java: Best practices and bytecodes quiz
 

Recently uploaded

%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...masabamasaba
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsBert Jan Schrijver
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durbanmasabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 

Recently uploaded (20)

%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 

Applying Design Patterns in Practice

  • 1. Applying Design Patterns in Practice Ganesh Samarthyam ganesh.samarthyam@gmail.com
  • 3. Which pattern is this? a) Visitor pa+ern b) Factory method pa+ern c) Template method pa+ern d) Iterator pa+ern
  • 4. Which pattern is this? a) Decorator pa+ern b) Composite pa+ern c) Adapter pa+ern d) Model-View-Controller (MVC) pa+ern
  • 5. Which pattern is this? Calendar calendar = b.set(YEAR, 2003).set(MONTH, APRIL).set(DATE, 6) .set(HOUR, 15).set(MINUTE, 45).set(SECOND, 22) .setTimeZone(TimeZone.getDefault()).build(); a) Factory method pa+ern b) Abstract factory pa+ern c) Builder pa+ern d) Decorator pa+ern
  • 6. Which pattern is this? a) Bridge pa+ern b) Abstract factory pa+ern c) Builder pa+ern d) Strategy pa+ern
  • 7. Which pattern is this? a) Bridge pa+ern b) Decorator pa+ern c) Builder pa+ern d) Strategy pa+ern LineNumberReader lnr = new LineNumberReader( new BufferedReader( new FileReader(“./test.c"))); String str = null; while((str = lnr.readLine()) != null) System.out.println(lnr.getLineNumber() + ": " + str);
  • 8. “Applying design principles is the key to creating high-quality software!” Architectural principles: Axis, symmetry, rhythm, datum, hierarchy, transformation
  • 10. Focus on “ever green” topics!
  • 11. For architects: design is the key!
  • 12. What are design patterns? recurrent solutions to common design problems Pattern Name Problem Solution Consequences
  • 13. Why care about patterns? ❖ Patterns capture expert knowledge in the form of proven reusable solutions ❖ Better to reuse proven solutions than to “re-invent” the wheel ❖ When used correctly, patterns positively influence software quality ❖ Creates maintainable, extensible, and reusable code
  • 14. 3 principles behind patterns Program to an interface, not to an implementation Favor object composition over inheritance Encapsulate what varies
  • 15. What is refactoring? Refactoring (noun): a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior Refactor (verb): to restructure software by applying a series of refactorings without changing its observable behavior
  • 16. Smells approach to learn patterns
  • 17. Scenario enum ColorScheme { RGB, HSB, HLS, CMYK } class Color { private float red, green, blue; // for supporting RGB scheme private float hue1, saturation1, brightness1; // for supporting HSB scheme private float hue2, lightness2, saturation2; // for supporting HLS scheme public Color(float arg1, float arg2, float arg3, ColorScheme cs) { switch (cs) { // initialize arg1, arg2, and arg3 based on ColorScheme value } } } • Assume that you need to support different Color schemes in your software • RGB (Red, Green, Blue), HSB (Hue, Saturation, Brightness), and HLS (Hue, Lightness, and Saturation) schemes • Overloading constructors and differentiating them using enums can become confusing • What could be a better design?
  • 18. A solution using Factory Method pattern Color + GetRGBColor() + GetHSBColor() + GetHLSColor() RGBColor - red : float - green : float - blue : float HSBColor - hue : float - saturation : float - brightness : float HLSColor - hue : float - lightness : float - saturation : float
  • 19. A solution using Factory Method pattern Color + GetColor(ColorType) + … RGBColor - red : float - green : float - blue : float HSBColor - hue : float - saturation : float - brightness : float HLSColor - hue : float - lightness : float - saturation : float
  • 20. Factory Method pattern: Structure Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 21. Factory method pattern: Discussion ❖ A class cannot anticipate the class of objects it must create ❖ A class wants its subclasses to specify the objects it creates Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory method lets a class defer instantiation to subclasses. ❖ Delegate the responsibility to one of the several helper subclasses ❖ Also, localize the knowledge of which subclass is the delegate
  • 22. Factory method: Java library example Logger logger = Logger.getLogger(TestFileLogger.class.getName());
  • 23. Factory method: Java library example class SimpleThreadFactory implements ThreadFactory { public Thread newThread(Runnable r) { return new Thread(r); } }
  • 24. Scenario public Locale (String language, // e.g. “en" for English String script, // e.g., “Arab” for Arabic String country, // e.g., “us” for United States String variant, // e.g., “TH” for Thai LocaleExtensions extensions) // e.g., “ca-buddhist” for Thai Buddhist Calendar • Assume that you have a Locale class constructor that takes many “optional constructors” • Constraint: Only certain variants are allowed - you need to “disallow” inappropriate combinations(e.g., invalid combination of country and variant) by throwing IllformedLocaleException. • Overloading constructors will result in “too many constructors” • How will you design a solution for this?
  • 25. Recommended solution Locale aLocale = new Locale.Builder() .setLanguage(“sr") .setScript(“Latn") .setRegion("RS") .build(); • Create a Locale Builder that “builds” and returns an object step-by-step • Validation will be performed by the individual set methods • The build() method will return the “built” object
  • 26. Builder pattern: structure Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 27. Builer pattern: Discussion ❖ Creating or assembling a complex object can be tedious Separate the construction of a complex object from its representation so that the same construction process can create different representations. ❖ Make the algorithm for creating a complex object independent of parts that make up the object and how they are assembled ❖ The construction process allows different representations for the object that is constructed
  • 28. Builders common for complex classes Calendar.Builder b = new Calendar.Builder(); Calendar calendar = b .set(YEAR, 2003) .set(MONTH, APRIL) .set(DATE, 6) .set(HOUR, 15) .set(MINUTE, 45) .set(SECOND, 22) .setTimeZone(TimeZone.getDefault()) .build(); System.out.println(calendar);
  • 29. Scenario ❖ Consider a Route class in an application like Google Maps ❖ For finding shortest path from source to destination, many algorithms can be used ❖ The problem is that these algorithms get embedded into Route class and cannot be reused easily (smell!) Route + SetRoute(Location, Location) + FindShortestPathJohnson() + FindShortestDijkstra() + FindShortestBellmanFord() + … How will you refactor such that a) Support for shortest path algorithm can be added easily? b) Separate path finding logic from dealing with location information.
  • 30. How about this solution? ShortestPathAlgos + FindPath() JohnsonsAlgo DijkstrasAlgo Route + SetRoute(Locati on, Location) + ShortestPath() + …
  • 31. You’re right: Its Strategy pattern! Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 32. Strategy pattern: Discussion ❖ Useful when there is a set of related algorithms and a client object needs to be able to dynamically pick and choose an algorithm that suits its current need Defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it ❖ The implementation of each of the algorithms is kept in a separate class referred to as a strategy. ❖ An object that uses a Strategy object is referred to as a context object. ❖ Changing the behavior of a Context object is a matter of changing its Strategy object to the one that implements the required algorithm
  • 33. Wait, what principle did we apply?
  • 34. Open Closed Principle (OCP) Bertrand Meyer Software entities should be open for extension, but closed for modification
  • 35. SOLID principles •  There&should&never&be&more&than&one&reason&for&a&class&to& change&& Single'Responsibility' Principle'(SRP)' •  So6ware&en88es&(classes,&modules,&func8ons,&etc.)&should& be&open&for&extension,&but&closed&for&modifica8on& Open'Closed'Principle' (OCP)' •  Pointers&or&references&to&base&classes&must&be&able&to&use& objects&of&derived&classes&without&knowing&it& Liskov’s'Subs<tu<on' Principle'(LSP)' •  Depend&on&abstrac8ons,&not&on&concre8ons& Dependency'Inversion' Principle'(DIP)' •  Many&clientGspecific&interfaces&are&beHer&than&one& generalGpurpose&interface& Interface'Segrega<on' Principle'(ISP)'
  • 36. Variation Encapsulation Principle (VEP) Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides Encapsulate the concept that varies
  • 37. Fundamental principle: Encapsulation The principle of encapsulation advocates separation of concerns and information hiding through techniques such as hiding implementation details of abstractions and hiding variations
  • 38. What do you mean by “principle”? “Design principles are key notions considered fundamental to many different software design approaches and concepts. They are also called enabling techniques.” - SWEBOK ‘04
  • 39. Design determines qualities Understandability Changeability Extensibility Reusability Testability Reliability DESIGN impacts impacts impacts
  • 41. Real scenario Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 42. Supporting new requirements Revised design with new requirements TextView + Draw() BorderedTextView + Draw() + DrawBorder() ScrollableTextView ScrollableBordered TextView - borderWidth + Draw() + ScrollTo() - ScrollPosition + Draw() + ScrollTo() + DrawBorder() - ScrollPosition - borderWidth
  • 43. Scenario ❖ How will you refactor such that: ❖ You don't have to “multiply- out” sub-types? (i.e., avoid “explosion of classes”) ❖ You can add or remove responsibilities (e.g., scrolling)? Next change: smelly design
  • 44. How about this solution? VisualComponent + Draw() TextView + Draw() ScrollDecortor BorderDecorator + Draw() + ScrollTo() - ScrollPosition + Draw() + DrawBorder() - borderWidth Decorator + Draw() component->Draw() Decorator::Draw() DrawBorder() Decorator::Draw() ScrollTo() Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 45. Can you identify the pattern? VisualComponent + Draw() TextView + Draw() ScrollDecortor BorderDecorator + Draw() + ScrollTo() - ScrollPosition + Draw() + DrawBorder() - borderWidth Decorator + Draw() component->Draw() Decorator::Draw() DrawBorder() Decorator::Draw() ScrollTo() Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 46. You’re right: Its Decorator pattern! Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 47. Decorator pattern: Discussion ❖ Want to add responsibilities to individual objects (not an entire class) ❖ One way is to use inheritance ❖ Inflexible; static choice ❖ Hard to add and remove responsibilities dynamically Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality ❖ Add responsibilities through decoration ❖ in a way transparent to the clients ❖ Decorator forwards the requests to the contained component to perform additional actions ❖ Can nest recursively ❖ Can add an unlimited number of responsibilities dynamically
  • 48. Identify pattern used in this code LineNumberReader lnr = new LineNumberReader( new BufferedReader( new FileReader(“./test.c"))); String str = null; while((str = lnr.readLine()) != null) System.out.println(lnr.getLineNumber() + ": " + str);
  • 50. Decorator pattern extensively used in library designs
  • 51. Scenario a) How do we treat files and folders alike? b) How can we handle shortcuts? File + GetName() + GetSize() + … - name: String - size: int - type: FileType - data: char[] - … Folder + GetName() + GetFiles() + GetFolders() + … - name: String - files[]: File - folders[]: Folder
  • 52. How about this solution? FileItem + GetName() + GetSize() + Add(FileItem) + Remove(FileItem) Folder + GetFiles() + … File - files: FileItem + GetType() + GetContents() + … - type: FileType - data: char[] Shortcut + GetLinkedFileItem() + … - linkToFile: FileItem
  • 53. Composite pattern Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 54. Composite pattern: Discussion ❖ There are many situations where a group of components form larger components ❖ Simplistic approach: Make container component contain primitive ones ❖ Problem: Code has to treat container and primitive components differently Compose objects into tree structures to represent part-whole hierarchies. Composite lets client treat individual objects and compositions of objects uniformly. ❖ Perform recursive composition of components ❖ Clients don’t have to treat container and primitive components differently
  • 55. Decorator vs. Composite Decorator and composite structure looks similar: Decorator is a degenerate form of Composite! Decorator Composite At max. one component Can have many components Adds responsibilities Aggregates objects Does not make sense to have methods such as Add(), Remove(), GetChid() etc. Has methods such as Add(), Remove(), GetChild(), etc.
  • 56. Composite pattern extensively used in library designs
  • 57. Scenario How to separate: a) code generation logic from node types? b) how to support different target types? class Plus extends Expr { private Expr left, right; public Plus(Expr arg1, Expr arg2) { left = arg1; right = arg2; } public void genCode() { left.genCode(); right.genCode(); if(t == Target.JVM) { System.out.println("iadd"); } else { // DOTNET System.out.println("add"); } } }
  • 59. A solution using Visitor pattern class Plus extends Expr { private Expr left, right; public Plus(Expr arg1, Expr arg2) { left = arg1; right = arg2; } public Expr getLeft() { return left; } public Expr getRight() { return right; } public void accept(Visitor v) { v.visit(this); } } class DOTNETVisitor extends Visitor { public void visit(Constant arg) { System.out.println("ldarg " + arg.getVal()); } public void visit(Plus plus) { genCode(plus.getLeft()); genCode(plus.getRight()); System.out.println("add"); } public void visit(Sub sub) { genCode(sub.getLeft()); genCode(sub.getRight()); System.out.println("sub"); } public void genCode(Expr expr) { expr.accept(this); } }
  • 60. Visitor pattern: structure Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 61. Visitor pattern: call sequence Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 62. Visitor pattern: Discussion ❖ Many distinct and unrelated operations need to be performed on objects in an object structure, and you want to avoid “polluting” their classes with these operations Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operations ❖ Create two class hierarchies: ❖ One for the elements being operated on ❖ One for the visitors that define operations on the elements
  • 63. Patterns discussed so far ✓ Builder pattern ✓ Factory method pattern ✓ Strategy pattern ✓ Decorator pattern ✓ Composite pattern ✓ Visitor pattern Can you recap these patterns?
  • 67. Pipe-and-filter: Benefits + Flexibility by filter exchange + Flexibility by recombination + Reuse of filter components + Rapid prototyping of pipelines Frank Buschmann, Regine Meunier, Hans Rohnert, Peter Sommerlad, and Michael Stal. 1996. Pattern-Oriented Software Architecture: A System of Patterns. John Wiley & Sons, Inc., NY, USA.
  • 68. Pipe-and-filter: Liabilities - Sharing state information is expensive or inflexible - Efficiency gain by parallel processing is often an illusion - Data transformation overhead - Difficult to handle errors Frank Buschmann, Regine Meunier, Hans Rohnert, Peter Sommerlad, and Michael Stal. 1996. Pattern-Oriented Software Architecture: A System of Patterns. John Wiley & Sons, Inc., NY, USA.
  • 69. What are your takeaways?
  • 70.
  • 71.
  • 72.
  • 73.
  • 75. “Applying design principles is the key to creating high-quality software!” Architectural principles: Axis, symmetry, rhythm, datum, hierarchy, transformation
  • 76. Image/video credits ❖ http://en.wikipedia.org/wiki/Fear_of_missing_out ❖ http://lesliejanemoran.blogspot.in/2010_05_01_archive.html ❖ http://javra.eu/wp-content/uploads/2013/07/angry_laptop2.jpg ❖ https://www.youtube.com/watch?v=5R8XHrfJkeg ❖ http://womenworld.org/image/052013/31/113745161.jpg ❖ http://www.fantom-xp.com/wallpapers/33/I'm_not_sure.jpg ❖ https://www.flickr.com/photos/31457017@N00/453784086 ❖ https://www.gradtouch.com/uploads/images/question3.jpg ❖ http://gurujohn.files.wordpress.com/2008/06/bookcover0001.jpg ❖ http://upload.wikimedia.org/wikipedia/commons/d/d5/Martin_Fowler_-_Swipe_Conference_2012.jpg ❖ http://www.codeproject.com/KB/architecture/csdespat_2/dpcs_br.gif ❖ http://upload.wikimedia.org/wikipedia/commons/thumb/2/28/Bertrand_Meyer_IMG_2481.jpg/440px- Bertrand_Meyer_IMG_2481.jpg ❖ http://takeji-soft.up.n.seesaa.net/takeji-soft/image/GOF-OOPLSA-94-Color-75.jpg?d=a0 ❖ https://developer.apple.com/library/ios/documentation/cocoa/Conceptual/OOP_ObjC/Art/watchcalls_35.gif ❖ http://www.pluspack.com/files/billeder/Newsletter/25/takeaway_bag.png ❖ http://cdn1.tnwcdn.com/wp-content/blogs.dir/1/files/2013/03/design.jpg