SlideShare uma empresa Scribd logo
1 de 29
Baixar para ler offline
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

Mais conteúdo relacionado

Semelhante a Design patterns for fun & profit - CoderCruise 2018

12266422.ppt
12266422.ppt12266422.ppt
12266422.ppt
CSEC5
 

Semelhante a 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
 

Último

Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Último (20)

MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 

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