SlideShare a Scribd company logo
Design Patterns
Through Refactoring
Ganesh Samarthyam
ganesh.samarthyam@gmail.com
“Applying design principles is the key to creating
high-quality software!”
Architectural principles:
Axis, symmetry, rhythm, datum, hierarchy, transformation
Technology changes fast => FOMO
For architects: design is the key!
Agenda
• Introduction
• Design patterns though
exercises
• Patterns through a case-
study
• Wrap-up & key-takeaways
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
Design pattern catalog
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Design pattern catalog
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Creational
Deals with controlled
object creation
Factory method, for
example
Structural
Deals with
composition of classes
or objects
Composite, for example
Behavioral
Deals with interaction
between objects/
classes and
distribution of
responsibility
Strategy, for example
5 minutes intro to notation
An example
Source: “Refactoring for Software Design Smells: Managing Technical Debt”, Girish Suryanarayana, Ganesh Samarthyam, Tushar Sharma, Morgan Kaufmann/Elsevier, 2014
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
Cover key patterns through examples
It is not about the number of
patterns you know, but how
well you understand “why,
when, where, and how” to
apply them effectively
Smells approach to learn patterns
Agenda
• Introduction
• Design patterns though
exercises
• Patterns through a case-
study
• Wrap-up & key-takeaways
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
Builder 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
Report
+ Open()
+ Populate()
+ Print()
+ Save()
SummaryHTMLReport SummaryRichReport DetailedHTMLReport DetailedRichReport
How about this solution?
FileFormat
+ Save()
HTMLReport RichReport
Report
+ Open()
+ Save(ReportType)
+ …
SummaryReport DetailedReport
You’re right: Its Bridge pattern!
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
An example of Bridge pattern
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Bridge pattern: Discussion
❖ An abstraction can be designed as an
interface with one or more concrete
implementers.
❖ When subclassing the hierarchy, it
could lead to an exponential number of
subclasses.
❖ And since both the interface and its
implementation are closely tied
together, they cannot be independently
varied without affecting each other
Decouples an abstraction from its implementation so
that the two can vary independently
❖ Put both the interfaces and the
implementations into separate class
hierarchies.
❖ The Abstraction maintains an object
reference of the Implementer type.
❖ A client application can choose a desired
abstraction type from the Abstraction
class hierarchy.
❖ The abstraction object can then be
configured with an instance of an
appropriate implementer from the
Implementer class hierarchy
Scenario
Initial design
TextView
+ Draw()
BorderedTextView
+ Draw()
+ DrawBorder()
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
At runtime (object diagram)
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
Many other patterns other than GoF
Source: “Refactoring to Patterns”, Joshua Kerievsky, Addison Wesley, 2004
Null Object pattern
Source: “Refactoring to Patterns”, Joshua Kerievsky, Addison Wesley, 2004
EmptySet from Java library
private static class EmptySet<E>
extends AbstractSet<E>
implements Serializable
{
private static final long serialVersionUID = 1582296315990362920L;
public Iterator<E> iterator() { return emptyIterator(); }
public int size() {return 0;}
public boolean isEmpty() {return true;}
public boolean contains(Object obj) {return false;}
public boolean containsAll(Collection<?> c) { return c.isEmpty(); }
public Object[] toArray() { return new Object[0]; }
public <T> T[] toArray(T[] a) {
if (a.length > 0)
a[0] = null;
return a;
}
// Preserves singleton property
private Object readResolve() {
return EMPTY_SET;
}
}
Agenda
• Introduction
• Design patterns though
exercises
• Patterns through a case-
study
• Tools for refactoring
• Wrap-up & key-takeaways
Designing a document editor
• How to maintain a document structure?
• How to support formatting?
• How to support embellishments
(highlighting, marking, etc) with ease?
• Support multiple look-and-feel
standards
• Support multiple windowing systems
(mac, windows, motif, etc)
• How to support user operations and
handle user events?
• How to support spellchecking and
hyphenation?
• ….
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
“Recursive composition”
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Solution using Composite pattern
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
More “recursive composition”
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
“Recursive composition” - class design
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Supporting bordering, scrolling, …
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Supporting multiple look-and-feel
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Abstract factory: Structure
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Supporting multiple look-and-feel
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Separating implementation dependencies
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Supporting user operations
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Supporting user operations
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Command pattern: Structure
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Supporting undo/redo: Command history
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Traversing document (e.g., spell check)
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Iterator pattern: Structure
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Iterator pattern: Another example
Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
Patterns discussed in this case-study
✓ Composite pattern
✓ Decorator pattern
✓ Abstract factory pattern
✓ Bridge pattern
✓ Command pattern
✓ Iterator pattern
Agenda
• Introduction
• Design patterns though
exercises
• Patterns through a case-
study
• Wrap-up & key-
takeaways
Exercise: Create a suitable design
Note:&Responsibility&of&
rendering&the&line&in&chosen&
style&is&with&underlying&OS&/&
pla;orm&
Source: “Refactoring for Software Design Smells: Managing Technical Debt”, Girish Suryanarayana, Ganesh Samarthyam, Tushar Sharma, Morgan Kaufmann/Elsevier, 2014
How about this solution?
Source: “Refactoring for Software Design Smells: Managing Technical Debt”, Girish Suryanarayana, Ganesh Samarthyam, Tushar Sharma, Morgan Kaufmann/Elsevier, 2014
Suggested refactoring for this smell
Source: “Refactoring for Software Design Smells: Managing Technical Debt”, Girish Suryanarayana, Ganesh Samarthyam, Tushar Sharma, Morgan Kaufmann/Elsevier, 2014
Beware of “patterns mania”!
What are your takeaways?
Books to read
“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
Design patterns through refactoring

More Related Content

What's hot

Java 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJava 8-streams-collectors-patterns
Java 8-streams-collectors-patterns
José Paumard
 
Building Immutable Machine Images with Packer and Ansible
Building Immutable Machine Images with Packer and AnsibleBuilding Immutable Machine Images with Packer and Ansible
Building Immutable Machine Images with Packer and Ansible
Jason Harley
 
Flamingo Microservice based E-Commerce / Motivations,Backgrounds, Short Intro...
Flamingo Microservice based E-Commerce / Motivations,Backgrounds, Short Intro...Flamingo Microservice based E-Commerce / Motivations,Backgrounds, Short Intro...
Flamingo Microservice based E-Commerce / Motivations,Backgrounds, Short Intro...
i-love-flamingo
 
Solid principles
Solid principlesSolid principles
Solid principles
Monica Rodrigues
 
[132] rust
[132] rust[132] rust
[132] rust
NAVER D2
 
Effective Modern C++
Effective Modern C++Effective Modern C++
Effective Modern C++
Wang Hsiangkai
 
DevOps - A Gentle Introduction
DevOps - A Gentle IntroductionDevOps - A Gentle Introduction
DevOps - A Gentle Introduction
CodeOps Technologies LLP
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
Dzmitry Naskou
 
Real Life Clean Architecture
Real Life Clean ArchitectureReal Life Clean Architecture
Real Life Clean Architecture
Mattia Battiston
 
Domain Driven Design using Laravel
Domain Driven Design using LaravelDomain Driven Design using Laravel
Domain Driven Design using Laravel
wajrcs
 
NestJS
NestJSNestJS
NestJS
Wilson Su
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with Overview
Shahed Chowdhuri
 
Crossplane @ Mastering GitOps.pdf
Crossplane @ Mastering GitOps.pdfCrossplane @ Mastering GitOps.pdf
Crossplane @ Mastering GitOps.pdf
QAware GmbH
 
Kubernetes Helm: Why It Matters
Kubernetes Helm: Why It MattersKubernetes Helm: Why It Matters
Kubernetes Helm: Why It Matters
Platform9
 
Microservice Architecture
Microservice ArchitectureMicroservice Architecture
Microservice Architecture
tyrantbrian
 
Microservice vs. Monolithic Architecture
Microservice vs. Monolithic ArchitectureMicroservice vs. Monolithic Architecture
Microservice vs. Monolithic Architecture
Paul Mooney
 
TypeScript
TypeScriptTypeScript
Introduction to Istio on Kubernetes
Introduction to Istio on KubernetesIntroduction to Istio on Kubernetes
Introduction to Istio on Kubernetes
Jonh Wendell
 
Java Serialization Deep Dive
Java Serialization Deep DiveJava Serialization Deep Dive
Java Serialization Deep Dive
Martijn Dashorst
 
Deploying your first application with Kubernetes
Deploying your first application with KubernetesDeploying your first application with Kubernetes
Deploying your first application with Kubernetes
OVHcloud
 

What's hot (20)

Java 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJava 8-streams-collectors-patterns
Java 8-streams-collectors-patterns
 
Building Immutable Machine Images with Packer and Ansible
Building Immutable Machine Images with Packer and AnsibleBuilding Immutable Machine Images with Packer and Ansible
Building Immutable Machine Images with Packer and Ansible
 
Flamingo Microservice based E-Commerce / Motivations,Backgrounds, Short Intro...
Flamingo Microservice based E-Commerce / Motivations,Backgrounds, Short Intro...Flamingo Microservice based E-Commerce / Motivations,Backgrounds, Short Intro...
Flamingo Microservice based E-Commerce / Motivations,Backgrounds, Short Intro...
 
Solid principles
Solid principlesSolid principles
Solid principles
 
[132] rust
[132] rust[132] rust
[132] rust
 
Effective Modern C++
Effective Modern C++Effective Modern C++
Effective Modern C++
 
DevOps - A Gentle Introduction
DevOps - A Gentle IntroductionDevOps - A Gentle Introduction
DevOps - A Gentle Introduction
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Real Life Clean Architecture
Real Life Clean ArchitectureReal Life Clean Architecture
Real Life Clean Architecture
 
Domain Driven Design using Laravel
Domain Driven Design using LaravelDomain Driven Design using Laravel
Domain Driven Design using Laravel
 
NestJS
NestJSNestJS
NestJS
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with Overview
 
Crossplane @ Mastering GitOps.pdf
Crossplane @ Mastering GitOps.pdfCrossplane @ Mastering GitOps.pdf
Crossplane @ Mastering GitOps.pdf
 
Kubernetes Helm: Why It Matters
Kubernetes Helm: Why It MattersKubernetes Helm: Why It Matters
Kubernetes Helm: Why It Matters
 
Microservice Architecture
Microservice ArchitectureMicroservice Architecture
Microservice Architecture
 
Microservice vs. Monolithic Architecture
Microservice vs. Monolithic ArchitectureMicroservice vs. Monolithic Architecture
Microservice vs. Monolithic Architecture
 
TypeScript
TypeScriptTypeScript
TypeScript
 
Introduction to Istio on Kubernetes
Introduction to Istio on KubernetesIntroduction to Istio on Kubernetes
Introduction to Istio on Kubernetes
 
Java Serialization Deep Dive
Java Serialization Deep DiveJava Serialization Deep Dive
Java Serialization Deep Dive
 
Deploying your first application with Kubernetes
Deploying your first application with KubernetesDeploying your first application with Kubernetes
Deploying your first application with Kubernetes
 

Viewers also liked

Refactoring Design Patterns the Functional Way (in Scala)
Refactoring Design Patterns the Functional Way (in Scala)Refactoring Design Patterns the Functional Way (in Scala)
Refactoring Design Patterns the Functional Way (in Scala)
Kfir Bloch
 
Angular js
Angular jsAngular js
Angular js
Manav Prasad
 
Angular js
Angular jsAngular js
Angular js
ParmarAnisha
 
Creational Design Patterns
Creational Design PatternsCreational Design Patterns
Creational Design Patterns
Jamie (Taka) Wang
 
Node js meetup
Node js meetupNode js meetup
Node js meetup
Ansuman Roy
 
Angular JS blog tutorial
Angular JS blog tutorialAngular JS blog tutorial
Angular JS blog tutorial
Claude Tech
 
Get satrted angular js
Get satrted angular jsGet satrted angular js
Get satrted angular js
Alexandre Marreiros
 
Angular 2
Angular 2Angular 2
Angular 2
Nigam Goyal
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework
Sakthi Bro
 
Getting Started with Angular JS
Getting Started with Angular JSGetting Started with Angular JS
Getting Started with Angular JS
Akshay Mathur
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
Akshay Mathur
 
SOLID Principles and Design Patterns
SOLID Principles and Design PatternsSOLID Principles and Design Patterns
SOLID Principles and Design Patterns
Ganesh Samarthyam
 
Object-oriented design patterns in UML [Software Modeling] [Computer Science...
Object-oriented design patterns  in UML [Software Modeling] [Computer Science...Object-oriented design patterns  in UML [Software Modeling] [Computer Science...
Object-oriented design patterns in UML [Software Modeling] [Computer Science...
Ivano Malavolta
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
Aayush Shrestha
 
Design Patterns
Design PatternsDesign Patterns
Design Patternssoms_1
 
Modern UI Development With Node.js
Modern UI Development With Node.jsModern UI Development With Node.js
Modern UI Development With Node.js
Ryan Anklam
 
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
Svetlin Nakov
 
Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)
Aniruddha Chakrabarti
 
Design Patterns Illustrated
Design Patterns IllustratedDesign Patterns Illustrated
Design Patterns Illustrated
Herman Peeren
 

Viewers also liked (20)

Refactoring Design Patterns the Functional Way (in Scala)
Refactoring Design Patterns the Functional Way (in Scala)Refactoring Design Patterns the Functional Way (in Scala)
Refactoring Design Patterns the Functional Way (in Scala)
 
Angular js
Angular jsAngular js
Angular js
 
Angular js
Angular jsAngular js
Angular js
 
Design Patterns in .Net
Design Patterns in .NetDesign Patterns in .Net
Design Patterns in .Net
 
Creational Design Patterns
Creational Design PatternsCreational Design Patterns
Creational Design Patterns
 
Node js meetup
Node js meetupNode js meetup
Node js meetup
 
Angular JS blog tutorial
Angular JS blog tutorialAngular JS blog tutorial
Angular JS blog tutorial
 
Get satrted angular js
Get satrted angular jsGet satrted angular js
Get satrted angular js
 
Angular 2
Angular 2Angular 2
Angular 2
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework
 
Getting Started with Angular JS
Getting Started with Angular JSGetting Started with Angular JS
Getting Started with Angular JS
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
 
SOLID Principles and Design Patterns
SOLID Principles and Design PatternsSOLID Principles and Design Patterns
SOLID Principles and Design Patterns
 
Object-oriented design patterns in UML [Software Modeling] [Computer Science...
Object-oriented design patterns  in UML [Software Modeling] [Computer Science...Object-oriented design patterns  in UML [Software Modeling] [Computer Science...
Object-oriented design patterns in UML [Software Modeling] [Computer Science...
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Modern UI Development With Node.js
Modern UI Development With Node.jsModern UI Development With Node.js
Modern UI Development With Node.js
 
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
 
Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)
 
Design Patterns Illustrated
Design Patterns IllustratedDesign Patterns Illustrated
Design Patterns Illustrated
 

Similar to Design patterns through refactoring

Applying Design Patterns in Practice
Applying Design Patterns in PracticeApplying Design Patterns in Practice
Applying Design Patterns in Practice
Ganesh Samarthyam
 
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
Ganesh Samarthyam
 
Software Architecture: Principles, Patterns and Practices
Software Architecture: Principles, Patterns and PracticesSoftware Architecture: Principles, Patterns and Practices
Software Architecture: Principles, Patterns and Practices
Ganesh Samarthyam
 
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
Sri Ambati
 
Design Patterns.ppt
Design Patterns.pptDesign Patterns.ppt
Design Patterns.ppt
TanishaKochak
 
Online TechTalk  "Patterns in Embedded SW Design"
Online TechTalk  "Patterns in Embedded SW Design"Online TechTalk  "Patterns in Embedded SW Design"
Online TechTalk  "Patterns in Embedded SW Design"
GlobalLogic Ukraine
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
Asma CHERIF
 
Implementing Conceptual Search in Solr using LSA and Word2Vec: Presented by S...
Implementing Conceptual Search in Solr using LSA and Word2Vec: Presented by S...Implementing Conceptual Search in Solr using LSA and Word2Vec: Presented by S...
Implementing Conceptual Search in Solr using LSA and Word2Vec: Presented by S...
Lucidworks
 
Object Oriented PHP Overview
Object Oriented PHP OverviewObject Oriented PHP Overview
Object Oriented PHP OverviewLarry Ball
 
Strata San Jose 2016: Scalable Ensemble Learning with H2O
Strata San Jose 2016: Scalable Ensemble Learning with H2OStrata San Jose 2016: Scalable Ensemble Learning with H2O
Strata San Jose 2016: Scalable Ensemble Learning with H2O
Sri Ambati
 
Introduction to Mahout and Machine Learning
Introduction to Mahout and Machine LearningIntroduction to Mahout and Machine Learning
Introduction to Mahout and Machine Learning
Varad Meru
 
Introduction to Design Patterns in Javascript
Introduction to Design Patterns in JavascriptIntroduction to Design Patterns in Javascript
Introduction to Design Patterns in Javascript
Santhosh Kumar Srinivasan
 
Erin LeDell, Machine Learning Scientist, H2O.ai at MLconf ATL 2016
Erin LeDell, Machine Learning Scientist, H2O.ai at MLconf ATL 2016Erin LeDell, Machine Learning Scientist, H2O.ai at MLconf ATL 2016
Erin LeDell, Machine Learning Scientist, H2O.ai at MLconf ATL 2016
MLconf
 
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
Vital.AI
 
Query-time Nonparametric Regression with Temporally Bounded Models - Patrick ...
Query-time Nonparametric Regression with Temporally Bounded Models - Patrick ...Query-time Nonparametric Regression with Temporally Bounded Models - Patrick ...
Query-time Nonparametric Regression with Temporally Bounded Models - Patrick ...
Lucidworks
 
Dr. Erin LeDell, Machine Learning Scientist, H2O.ai at MLconf SEA - 5/20/16
Dr. Erin LeDell, Machine Learning Scientist, H2O.ai at MLconf SEA - 5/20/16Dr. Erin LeDell, Machine Learning Scientist, H2O.ai at MLconf SEA - 5/20/16
Dr. Erin LeDell, Machine Learning Scientist, H2O.ai at MLconf SEA - 5/20/16
MLconf
 
Introduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John MulhallIntroduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John Mulhall
John Mulhall
 
Introduction to object oriented programming
Introduction to object oriented programmingIntroduction to object oriented programming
Introduction to object oriented programmingAbzetdin Adamov
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
Mindfire Solutions
 

Similar to Design patterns through refactoring (20)

Applying Design Patterns in Practice
Applying Design Patterns in PracticeApplying Design Patterns in Practice
Applying Design Patterns 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
 
Software Architecture: Principles, Patterns and Practices
Software Architecture: Principles, Patterns and PracticesSoftware Architecture: Principles, Patterns and Practices
Software Architecture: Principles, Patterns and Practices
 
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
 
Design Patterns.ppt
Design Patterns.pptDesign Patterns.ppt
Design Patterns.ppt
 
Online TechTalk  "Patterns in Embedded SW Design"
Online TechTalk  "Patterns in Embedded SW Design"Online TechTalk  "Patterns in Embedded SW Design"
Online TechTalk  "Patterns in Embedded SW Design"
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
 
Implementing Conceptual Search in Solr using LSA and Word2Vec: Presented by S...
Implementing Conceptual Search in Solr using LSA and Word2Vec: Presented by S...Implementing Conceptual Search in Solr using LSA and Word2Vec: Presented by S...
Implementing Conceptual Search in Solr using LSA and Word2Vec: Presented by S...
 
Object Oriented PHP Overview
Object Oriented PHP OverviewObject Oriented PHP Overview
Object Oriented PHP Overview
 
Strata San Jose 2016: Scalable Ensemble Learning with H2O
Strata San Jose 2016: Scalable Ensemble Learning with H2OStrata San Jose 2016: Scalable Ensemble Learning with H2O
Strata San Jose 2016: Scalable Ensemble Learning with H2O
 
Introduction to Mahout and Machine Learning
Introduction to Mahout and Machine LearningIntroduction to Mahout and Machine Learning
Introduction to Mahout and Machine Learning
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Introduction to Design Patterns in Javascript
Introduction to Design Patterns in JavascriptIntroduction to Design Patterns in Javascript
Introduction to Design Patterns in Javascript
 
Erin LeDell, Machine Learning Scientist, H2O.ai at MLconf ATL 2016
Erin LeDell, Machine Learning Scientist, H2O.ai at MLconf ATL 2016Erin LeDell, Machine Learning Scientist, H2O.ai at MLconf ATL 2016
Erin LeDell, Machine Learning Scientist, H2O.ai at MLconf ATL 2016
 
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
 
Query-time Nonparametric Regression with Temporally Bounded Models - Patrick ...
Query-time Nonparametric Regression with Temporally Bounded Models - Patrick ...Query-time Nonparametric Regression with Temporally Bounded Models - Patrick ...
Query-time Nonparametric Regression with Temporally Bounded Models - Patrick ...
 
Dr. Erin LeDell, Machine Learning Scientist, H2O.ai at MLconf SEA - 5/20/16
Dr. Erin LeDell, Machine Learning Scientist, H2O.ai at MLconf SEA - 5/20/16Dr. Erin LeDell, Machine Learning Scientist, H2O.ai at MLconf SEA - 5/20/16
Dr. Erin LeDell, Machine Learning Scientist, H2O.ai at MLconf SEA - 5/20/16
 
Introduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John MulhallIntroduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John Mulhall
 
Introduction to object oriented programming
Introduction to object oriented programmingIntroduction to object oriented programming
Introduction to object oriented programming
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
 

More from Ganesh Samarthyam

Wonders of the Sea
Wonders of the SeaWonders of the Sea
Wonders of the Sea
Ganesh Samarthyam
 
Animals - for kids
Animals - for kids Animals - for kids
Animals - for kids
Ganesh Samarthyam
 
Applying Refactoring Tools in Practice
Applying Refactoring Tools in PracticeApplying Refactoring Tools in Practice
Applying Refactoring Tools in Practice
Ganesh 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 Enough
Ganesh Samarthyam
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - Description
Ganesh Samarthyam
 
Coding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeCoding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean Code
Ganesh 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 Examples
Ganesh Samarthyam
 
Bangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief PresentationBangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief Presentation
Ganesh Samarthyam
 
Bangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - PosterBangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - Poster
Ganesh 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 Deck
Ganesh 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 Language
Ganesh 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 Questions
Ganesh Samarthyam
 
Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
Ganesh Samarthyam
 
Software Architecture - Quiz Questions
Software Architecture - Quiz QuestionsSoftware Architecture - Quiz Questions
Software Architecture - Quiz Questions
Ganesh Samarthyam
 
Docker by Example - Quiz
Docker by Example - QuizDocker by Example - Quiz
Docker by Example - Quiz
Ganesh 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 quiz
Ganesh 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

OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
Jelle | Nordend
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
varshanayak241
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 

Recently uploaded (20)

OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 

Design patterns through refactoring

  • 1. Design Patterns Through Refactoring Ganesh Samarthyam ganesh.samarthyam@gmail.com
  • 2. “Applying design principles is the key to creating high-quality software!” Architectural principles: Axis, symmetry, rhythm, datum, hierarchy, transformation
  • 5. Agenda • Introduction • Design patterns though exercises • Patterns through a case- study • Wrap-up & key-takeaways
  • 6. What are design patterns? recurrent solutions to common design problems Pattern Name Problem Solution Consequences
  • 7. 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
  • 8. Design pattern catalog Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 9. Design pattern catalog Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994 Creational Deals with controlled object creation Factory method, for example Structural Deals with composition of classes or objects Composite, for example Behavioral Deals with interaction between objects/ classes and distribution of responsibility Strategy, for example
  • 10. 5 minutes intro to notation
  • 11. An example Source: “Refactoring for Software Design Smells: Managing Technical Debt”, Girish Suryanarayana, Ganesh Samarthyam, Tushar Sharma, Morgan Kaufmann/Elsevier, 2014
  • 12. 3 principles behind patterns Program to an interface, not to an implementation Favor object composition over inheritance Encapsulate what varies
  • 13. 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
  • 14. Cover key patterns through examples It is not about the number of patterns you know, but how well you understand “why, when, where, and how” to apply them effectively
  • 15. Smells approach to learn patterns
  • 16. Agenda • Introduction • Design patterns though exercises • Patterns through a case- study • Wrap-up & key-takeaways
  • 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. Builder 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
  • 40. Scenario Report + Open() + Populate() + Print() + Save() SummaryHTMLReport SummaryRichReport DetailedHTMLReport DetailedRichReport
  • 41. How about this solution? FileFormat + Save() HTMLReport RichReport Report + Open() + Save(ReportType) + … SummaryReport DetailedReport
  • 42. You’re right: Its Bridge pattern! Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 43. An example of Bridge pattern Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 44. Bridge pattern: Discussion ❖ An abstraction can be designed as an interface with one or more concrete implementers. ❖ When subclassing the hierarchy, it could lead to an exponential number of subclasses. ❖ And since both the interface and its implementation are closely tied together, they cannot be independently varied without affecting each other Decouples an abstraction from its implementation so that the two can vary independently ❖ Put both the interfaces and the implementations into separate class hierarchies. ❖ The Abstraction maintains an object reference of the Implementer type. ❖ A client application can choose a desired abstraction type from the Abstraction class hierarchy. ❖ The abstraction object can then be configured with an instance of an appropriate implementer from the Implementer class hierarchy
  • 46. Scenario Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 47. 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
  • 48. 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
  • 49. 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
  • 50. At runtime (object diagram) Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 51. 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
  • 52. 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
  • 53. 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
  • 54. 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);
  • 56. Decorator pattern extensively used in library designs
  • 57. 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
  • 58. 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
  • 59. Composite pattern Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 60. 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
  • 61. 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.
  • 62. Composite pattern extensively used in library designs
  • 63. 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"); } } }
  • 65. 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); } }
  • 66. Visitor pattern: Structure Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 67. 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
  • 68. 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
  • 69. Many other patterns other than GoF Source: “Refactoring to Patterns”, Joshua Kerievsky, Addison Wesley, 2004
  • 70. Null Object pattern Source: “Refactoring to Patterns”, Joshua Kerievsky, Addison Wesley, 2004
  • 71. EmptySet from Java library private static class EmptySet<E> extends AbstractSet<E> implements Serializable { private static final long serialVersionUID = 1582296315990362920L; public Iterator<E> iterator() { return emptyIterator(); } public int size() {return 0;} public boolean isEmpty() {return true;} public boolean contains(Object obj) {return false;} public boolean containsAll(Collection<?> c) { return c.isEmpty(); } public Object[] toArray() { return new Object[0]; } public <T> T[] toArray(T[] a) { if (a.length > 0) a[0] = null; return a; } // Preserves singleton property private Object readResolve() { return EMPTY_SET; } }
  • 72. Agenda • Introduction • Design patterns though exercises • Patterns through a case- study • Tools for refactoring • Wrap-up & key-takeaways
  • 73. Designing a document editor • How to maintain a document structure? • How to support formatting? • How to support embellishments (highlighting, marking, etc) with ease? • Support multiple look-and-feel standards • Support multiple windowing systems (mac, windows, motif, etc) • How to support user operations and handle user events? • How to support spellchecking and hyphenation? • …. Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 74. “Recursive composition” Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 75. Solution using Composite pattern Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 76. More “recursive composition” Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 77. “Recursive composition” - class design Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 78. Supporting bordering, scrolling, … Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 79. Supporting multiple look-and-feel Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 80. Abstract factory: Structure Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 81. Supporting multiple look-and-feel Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 82. Separating implementation dependencies Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 83. Supporting user operations Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 84. Supporting user operations Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 85. Command pattern: Structure Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 86. Supporting undo/redo: Command history Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 87. Traversing document (e.g., spell check) Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 88. Iterator pattern: Structure Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 89. Iterator pattern: Another example Source: “Design Patterns: Elements of Reusable Object-Oriented Software”, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Addison-Wesley,1994
  • 90. Patterns discussed in this case-study ✓ Composite pattern ✓ Decorator pattern ✓ Abstract factory pattern ✓ Bridge pattern ✓ Command pattern ✓ Iterator pattern
  • 91. Agenda • Introduction • Design patterns though exercises • Patterns through a case- study • Wrap-up & key- takeaways
  • 92. Exercise: Create a suitable design Note:&Responsibility&of& rendering&the&line&in&chosen& style&is&with&underlying&OS&/& pla;orm& Source: “Refactoring for Software Design Smells: Managing Technical Debt”, Girish Suryanarayana, Ganesh Samarthyam, Tushar Sharma, Morgan Kaufmann/Elsevier, 2014
  • 93. How about this solution? Source: “Refactoring for Software Design Smells: Managing Technical Debt”, Girish Suryanarayana, Ganesh Samarthyam, Tushar Sharma, Morgan Kaufmann/Elsevier, 2014
  • 94. Suggested refactoring for this smell Source: “Refactoring for Software Design Smells: Managing Technical Debt”, Girish Suryanarayana, Ganesh Samarthyam, Tushar Sharma, Morgan Kaufmann/Elsevier, 2014
  • 96. What are your takeaways?
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103. “Applying design principles is the key to creating high-quality software!” Architectural principles: Axis, symmetry, rhythm, datum, hierarchy, transformation
  • 104. 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