SlideShare a Scribd company logo
Design
Patterns
for Fun &
Profit
David Litvak Bruno
@dlitvakb
Contentful
CoderCruise 2018
I’m David Litvak Bruno
I’ve been working with and teaching
Python and Ruby for the past 10 years
I currently work at Contentful in Berlin
as an Ecosystem Engineer creating
SDKs, tools and example apps using
Python, Ruby and Javascript.
Recent father of Julián
Who am I?
Before we start…
Some stuff we need to know
Static Typing
● Explicit typing contracts,
defined before compilation
time
● Typed references
● Immutable object
interfaces
Type Systems - Differences
Dynamic Typing
● Type defined through
usage, and not definition
● References are just names
for object instances and
don’t contain type
information
● Object interfaces are
mutable and can evolve
They are static
What tools do they provide?
● Strong, compile-time checked, interfaces
● Compile-time type safety (with the exception for null pointers)
● Limited runtime reflection capabilities
Type Systems - Java & C++
They are dynamic
What tools do they provide?
● Duck typing
● Code interception
● Introspection
● Reflection
● Self-modification
Type Systems - Python, Ruby &
Javascript
Dynamic Languages - Features
The features that allow us to “obsolete” traditional design patterns:
● Rich types
● Functions and classes as first-order objects
● Magic methods
○ Interceptors
○ Implementors
○ Introspectors
○ Constructors (Allocators)
● Contexts
● Multiple Inheritance
Late 70’s: Christopher Alexander’s: “A Pattern Language”
A bit of history
A bit of history
10 years later: Kent Beck and Ward Cunningham, started developing
a Pattern Language for Object Oriented Software and presented it at
OOPSLA
A bit of history
In 1994: The book that popularized design patterns
A bit of history
Throughout the following years: other literature started appearing
covering patterns for software architecture, testing, security and
other areas of software
Design Patterns
What’s a pattern?
We often found many problems with similar solutions, by analyzing it
we found that, even though all solutions are different, they all use
similar strategies to solve them.
Therefore, design patterns, are generalizations to those solutions for
common problems while designing software systems.
To explain design patterns, we need to specify 4 key items:
● Problem it solves
● Traditional usage
● Applicability
● Example implementation
A foreword of advise
Design Patterns - Categories
● Structural
○ Affect interaction of objects with the surrounding system
● Behavioural
○ Affect behaviour of objects
● Creational
○ Affect creation (or not) of objects
Proxy
What: Transparently intercepts all methods of an object to add
behaviour surrounding them.
How: Through composition and redefinition of the full interface.
When: An example usage is to add logging to every method call.
Design Patterns - Structural
Abstract Factory
What: Creates children objects of multiple different classes within a
family masking the actual implementation class.
How: Static method on an abstract base class that takes some
configuration and decides which implementation to use based on it. It
will return an instantiated object of a concrete child class.
When: An example usage is for instantiating an ORM which supports
different database engines and decides which one to use based on
the connection string.
Design Patterns - Creational
Iterator
What: Provides an interface for iterating through an object as if it
were a native collection.
How: Through implementation of an Iterable interface, limiting
heavily the scope of what an actual collection provides.
When: It’s typically used when internal structure is not relevant to be
exposed and it’s desired to be treated as a collection.
Design Patterns - Behavioural
Memento
What: Saves intermediate states to allow for replaying an object’s
history.
How: Usually through a persistence layer (in database or in memory)
tightly coupled with the implementation details of the concrete class.
When: When requiring some kind of change log, like a text editor’s
undo/redo, a games replay system or a web-browser’s history.
Design Patterns - Behavioural
Observer
What: Monitors state changes and signals interested object.
Composed of an event emitter (Observable) and an event listener
(Observer).
How: Observable objects register to observers. Observers
need to define a tightly coupled interface on how they are
supposed to trigger the received update event.
When: Commonly used in UI programming and when dealing
with database events and other components need notification
of interaction.
Design Patterns - Behavioural
State and Strategy
What: Runtime swap of object behaviour. Strategy applies to a single
method, while State applies to the whole class behaviour.
How: Object composition on a tightly coupled hierarchy.
When: In cases where objects need to change behaviour
depending on some object state, for example the calculation
formula of taxes on a purchase may differ from place to place.
Or a Person object could behave differently depending on
their age.
Design Patterns - Behavioural
By using dynamic languages, we obtain some superpowers and can
make extremely complex things simple.
Conclusion
Conclusion
Conclusion
Having access to these tools though, will broader your way of
thinking about problems and surface solutions you may not have
thought about before.
Step 1: Apply patterns
Step 2: ???
Step 3: Profit
Questions?
@dlitvakb
david.litvak@contentful.com
http://github.com/dlitvakb

More Related Content

Similar to Design patterns for fun & profit - CoderCruise 2018

Benefits of using software design patterns and when to use design pattern
Benefits of using software design patterns and when to use design patternBenefits of using software design patterns and when to use design pattern
Benefits of using software design patterns and when to use design pattern
Beroza Paul
 
Modular Web Design With Components
Modular Web Design With ComponentsModular Web Design With Components
Modular Web Design With Components
Nadal Soler
 
Design patterns
Design patternsDesign patterns
Design patterns
mudabbirwarsi
 
12266422.ppt
12266422.ppt12266422.ppt
12266422.ppt
CSEC5
 
DOC-20210303-WA0017..pptx,coding stuff in c
DOC-20210303-WA0017..pptx,coding stuff in cDOC-20210303-WA0017..pptx,coding stuff in c
DOC-20210303-WA0017..pptx,coding stuff in c
floraaluoch3
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
Satheesh Sukumaran
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
Satheesh Sukumaran
 
L05 Design Patterns
L05 Design PatternsL05 Design Patterns
L05 Design Patterns
Ólafur Andri Ragnarsson
 
Design Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur UniversityDesign Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur University
Shubham Narkhede
 
Design Patterns in Ruby
Design Patterns in RubyDesign Patterns in Ruby
Design Patterns in Ruby
Mindfire Solutions
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Luis Valencia
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptx
anguraju1
 
L03 Design Patterns
L03 Design PatternsL03 Design Patterns
L03 Design Patterns
Ólafur Andri Ragnarsson
 
Design_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.pptDesign_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.ppt
C Meenakshi Meyyappan
 
Importance Of Being Driven
Importance Of Being DrivenImportance Of Being Driven
Importance Of Being Driven
Antonio Terreno
 
Nicholas Gustilo "Clean Android: building great mobile apps"
Nicholas Gustilo "Clean Android: building great mobile apps"Nicholas Gustilo "Clean Android: building great mobile apps"
Nicholas Gustilo "Clean Android: building great mobile apps"
IT Event
 
Object Oriented Analysis
Object Oriented AnalysisObject Oriented Analysis
Object Oriented Analysis
AMITJain879
 
Design patterns
Design patternsDesign patterns
Design patterns
F(x) Data Labs Pvt Ltd
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
imedo.de
 
Unit No 6 Design Patterns.pptx
Unit No 6 Design Patterns.pptxUnit No 6 Design Patterns.pptx
Unit No 6 Design Patterns.pptx
DrYogeshDeshmukh1
 

Similar to Design patterns for fun & profit - CoderCruise 2018 (20)

Benefits of using software design patterns and when to use design pattern
Benefits of using software design patterns and when to use design patternBenefits of using software design patterns and when to use design pattern
Benefits of using software design patterns and when to use design pattern
 
Modular Web Design With Components
Modular Web Design With ComponentsModular Web Design With Components
Modular Web Design With Components
 
Design patterns
Design patternsDesign patterns
Design patterns
 
12266422.ppt
12266422.ppt12266422.ppt
12266422.ppt
 
DOC-20210303-WA0017..pptx,coding stuff in c
DOC-20210303-WA0017..pptx,coding stuff in cDOC-20210303-WA0017..pptx,coding stuff in c
DOC-20210303-WA0017..pptx,coding stuff in c
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
L05 Design Patterns
L05 Design PatternsL05 Design Patterns
L05 Design Patterns
 
Design Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur UniversityDesign Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur University
 
Design Patterns in Ruby
Design Patterns in RubyDesign Patterns in Ruby
Design Patterns in Ruby
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptx
 
L03 Design Patterns
L03 Design PatternsL03 Design Patterns
L03 Design Patterns
 
Design_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.pptDesign_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.ppt
 
Importance Of Being Driven
Importance Of Being DrivenImportance Of Being Driven
Importance Of Being Driven
 
Nicholas Gustilo "Clean Android: building great mobile apps"
Nicholas Gustilo "Clean Android: building great mobile apps"Nicholas Gustilo "Clean Android: building great mobile apps"
Nicholas Gustilo "Clean Android: building great mobile apps"
 
Object Oriented Analysis
Object Oriented AnalysisObject Oriented Analysis
Object Oriented Analysis
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Unit No 6 Design Patterns.pptx
Unit No 6 Design Patterns.pptxUnit No 6 Design Patterns.pptx
Unit No 6 Design Patterns.pptx
 

Recently uploaded

LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
Patrick Weigel
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
aymanquadri279
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
TaghreedAltamimi
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 

Recently uploaded (20)

LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 

Design patterns for fun & profit - CoderCruise 2018

  • 1. Design Patterns for Fun & Profit David Litvak Bruno @dlitvakb Contentful CoderCruise 2018
  • 2. I’m David Litvak Bruno I’ve been working with and teaching Python and Ruby for the past 10 years I currently work at Contentful in Berlin as an Ecosystem Engineer creating SDKs, tools and example apps using Python, Ruby and Javascript. Recent father of Julián Who am I?
  • 3. Before we start… Some stuff we need to know
  • 4. Static Typing ● Explicit typing contracts, defined before compilation time ● Typed references ● Immutable object interfaces Type Systems - Differences Dynamic Typing ● Type defined through usage, and not definition ● References are just names for object instances and don’t contain type information ● Object interfaces are mutable and can evolve
  • 5. They are static What tools do they provide? ● Strong, compile-time checked, interfaces ● Compile-time type safety (with the exception for null pointers) ● Limited runtime reflection capabilities Type Systems - Java & C++
  • 6.
  • 7. They are dynamic What tools do they provide? ● Duck typing ● Code interception ● Introspection ● Reflection ● Self-modification Type Systems - Python, Ruby & Javascript
  • 8.
  • 9. Dynamic Languages - Features The features that allow us to “obsolete” traditional design patterns: ● Rich types ● Functions and classes as first-order objects ● Magic methods ○ Interceptors ○ Implementors ○ Introspectors ○ Constructors (Allocators) ● Contexts ● Multiple Inheritance
  • 10. Late 70’s: Christopher Alexander’s: “A Pattern Language” A bit of history
  • 11. A bit of history 10 years later: Kent Beck and Ward Cunningham, started developing a Pattern Language for Object Oriented Software and presented it at OOPSLA
  • 12. A bit of history In 1994: The book that popularized design patterns
  • 13. A bit of history Throughout the following years: other literature started appearing covering patterns for software architecture, testing, security and other areas of software
  • 14. Design Patterns What’s a pattern? We often found many problems with similar solutions, by analyzing it we found that, even though all solutions are different, they all use similar strategies to solve them. Therefore, design patterns, are generalizations to those solutions for common problems while designing software systems. To explain design patterns, we need to specify 4 key items: ● Problem it solves ● Traditional usage ● Applicability ● Example implementation
  • 15.
  • 16. A foreword of advise
  • 17.
  • 18. Design Patterns - Categories ● Structural ○ Affect interaction of objects with the surrounding system ● Behavioural ○ Affect behaviour of objects ● Creational ○ Affect creation (or not) of objects
  • 19. Proxy What: Transparently intercepts all methods of an object to add behaviour surrounding them. How: Through composition and redefinition of the full interface. When: An example usage is to add logging to every method call. Design Patterns - Structural
  • 20. Abstract Factory What: Creates children objects of multiple different classes within a family masking the actual implementation class. How: Static method on an abstract base class that takes some configuration and decides which implementation to use based on it. It will return an instantiated object of a concrete child class. When: An example usage is for instantiating an ORM which supports different database engines and decides which one to use based on the connection string. Design Patterns - Creational
  • 21. Iterator What: Provides an interface for iterating through an object as if it were a native collection. How: Through implementation of an Iterable interface, limiting heavily the scope of what an actual collection provides. When: It’s typically used when internal structure is not relevant to be exposed and it’s desired to be treated as a collection. Design Patterns - Behavioural
  • 22. Memento What: Saves intermediate states to allow for replaying an object’s history. How: Usually through a persistence layer (in database or in memory) tightly coupled with the implementation details of the concrete class. When: When requiring some kind of change log, like a text editor’s undo/redo, a games replay system or a web-browser’s history. Design Patterns - Behavioural
  • 23. Observer What: Monitors state changes and signals interested object. Composed of an event emitter (Observable) and an event listener (Observer). How: Observable objects register to observers. Observers need to define a tightly coupled interface on how they are supposed to trigger the received update event. When: Commonly used in UI programming and when dealing with database events and other components need notification of interaction. Design Patterns - Behavioural
  • 24. State and Strategy What: Runtime swap of object behaviour. Strategy applies to a single method, while State applies to the whole class behaviour. How: Object composition on a tightly coupled hierarchy. When: In cases where objects need to change behaviour depending on some object state, for example the calculation formula of taxes on a purchase may differ from place to place. Or a Person object could behave differently depending on their age. Design Patterns - Behavioural
  • 25. By using dynamic languages, we obtain some superpowers and can make extremely complex things simple. Conclusion
  • 27. Conclusion Having access to these tools though, will broader your way of thinking about problems and surface solutions you may not have thought about before.
  • 28. Step 1: Apply patterns Step 2: ??? Step 3: Profit