SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Downloaden Sie, um offline zu lesen
Agile Saturday VI




        Choose a pattern
         for a problem!


Anton Keks
anton@codeborne.com
The Increasing Complexity

Complexity of software systems
                                    Time

New programming paradigms
Higher level of abstraction
HW Assembler Structural   (objects+functions?)
  CPUs  Procedural    <OOP>                ...
What are design patterns?
●
    Anywhere in the world you can find recurring
    patterns
●   Design patterns
    –   are building blocks of a system's
        architecture
    –   are recurring solutions to design problems
        that you see over
    –   identify and specify abstractions that are
        above the level of single classes and
        instances
Pattern classification
The GOF book defines 3 major types of patterns:
–   Creational patterns – substitute the new keyword. This
    gives your program more flexibility in deciding which
    objects need to be created for a given case
–   Structural patterns - compose groups of objects into
    larger structures, such as complex user interfaces or
    accounting data
–   Behavioral patterns - define the communication
    between objects and how the flow is controlled in a
    complex program.
Decorator
Adapter
 Composite      Strategy
                 State
                   Observer
     Factory
                Iterator
  Builder
    Prototype
Software Design: The Good
●
    Loose coupling
●
    Immutability
●
    Encapsulation
●   Short code blocks
●   Appropriate typing
●
    Duplication avoidance
●   Simplicity
●
    Consistent terminology
●   Clear naming
Bad, bad, bad!
●
    Loose coupling                       Tight coupling
●
    Immutability                Mutable data structures
●
    Encapsulation                          Tramp data
●   Short code blocks        Monster functions/methods
●   Appropriate typing           String/Integer overuse
●
    Duplication avoidance                   Copy-Paste
●   Simplicity                        Over-engineering
●
    Consistent terminology            Mixture of terms
●   Clear naming                     Runtime surprises
Let's get to business!
●   Next slides describe problems
       – What is given
          (existing code)
       – What we want to achieve
          (using a pattern)

●
    As usual, the code is on github:
       http://github.com/angryziber/patterns
Problem 1: Pizza
●
    We have:
    –   A pizzeria
    –   Multitude of options for pizzas: name, toppings,
        thickness, size, delivery address, etc
●   We want:
    –   Allow users to “order” custom pizzas
    –   Disallow changing the order once the pizza is
        already in the oven
    –   Keep the ordering code readable
Problem 2: Unzipper
●
    We have:
    –   unzip() method
    –   It is able to decompress a single compressed
        stream
●   We need:
    –   Support multiple-volume archives
    –   Compressed data is split into multiple floppies
Problem 3: Maps
●
    We have:
    –   Map data of entire Tallinn with all the streets,
        buildings, etc
    –   The MapVisualizer class that can draw the full map
        on the screen
●
    We want:
    –   User to see only a section of the map at any given
        time
    –   User to be able to move around the map
Problem 4: CD Player
●
    We have:
    –   A CD player with buttons play, stop, next, eject
●
    We want:
    –   Play to switch the player on
    –   Play again to pause playback, again to resume
    –   Stop to turn off the player
    –   Eject to open the disk tray (if no disk – no playback
        possible)
    –   etc, etc, etc
Problem 5: Vending Machine
●
    We have:
    –   A vending machine that can sell any small enough
        items
●
    We want:
    –   To deploy several such machines selling bottles of
        pepsi, sushi boxes, and Hintai magazines
    –   Each machine to sell items of one type
Problem 6: Spreadsheet
●
    We have:
    –   A spreadsheet-type program
    –   Containing a table for entering data and formulas
●   We want:
    –   The program to support charts
    –   The charts to be updated automatically if user
        changes the data in the table
    –   To sell the chart add-on separately for only $99.99
Problem 7: Battlefield
●
    We have:
    –   A tank
    –   Several types of bullets
    –   Lots of enemies around, e.g. airplanes, other
        tanks, guys with Molotov-coctails
●
    We want:
    –   To survive
    –   To kill 'em all
Problem 8: TCP over DNS
●
    We have:
    –    A paid Wi-Fi network (e.g. in an airport)
    –    Lots of spare time, but no credit card
●   We want:
    –    To be able to read emails and surf Facebook
    –    (Most likely, during our next trip)
●   Background info:
     –   Paid Wi-Fi usually resolves DNS just fine
     –   DNS packets can contain any payload
Thank you!




Codeborne is the only true extreme
programming company in the region.

Come and join us for an experience of
a lifetime you can't find elsewhere!

                job@codeborne.com

Weitere ähnliche Inhalte

Was ist angesagt?

Top Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To KnowTop Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To Know
Kathy Brown
 

Was ist angesagt? (13)

Top Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To KnowTop Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To Know
 
Making Strongly-typed NETCONF Usable
Making Strongly-typed NETCONF UsableMaking Strongly-typed NETCONF Usable
Making Strongly-typed NETCONF Usable
 
Detangling Your JavaScript
Detangling Your JavaScriptDetangling Your JavaScript
Detangling Your JavaScript
 
J9: Under the hood of the next open source JVM
J9: Under the hood of the next open source JVMJ9: Under the hood of the next open source JVM
J9: Under the hood of the next open source JVM
 
XPDays Ukraine: Legacy
XPDays Ukraine: LegacyXPDays Ukraine: Legacy
XPDays Ukraine: Legacy
 
It's all about behaviour, also in php - phpspec
It's all about behaviour, also in php - phpspecIt's all about behaviour, also in php - phpspec
It's all about behaviour, also in php - phpspec
 
Refactoring Legacy Code
Refactoring Legacy CodeRefactoring Legacy Code
Refactoring Legacy Code
 
Test Driven Development Powered by LEGO
Test Driven Development Powered by LEGOTest Driven Development Powered by LEGO
Test Driven Development Powered by LEGO
 
Javascript Tests with Jasmine for Front-end Devs
Javascript Tests with Jasmine for Front-end DevsJavascript Tests with Jasmine for Front-end Devs
Javascript Tests with Jasmine for Front-end Devs
 
invokedynamic: Evolution of a Language Feature
invokedynamic: Evolution of a Language Featureinvokedynamic: Evolution of a Language Feature
invokedynamic: Evolution of a Language Feature
 
Oh the compilers you'll build
Oh the compilers you'll buildOh the compilers you'll build
Oh the compilers you'll build
 
How we tested our code "Google way"
How we tested our code "Google way"How we tested our code "Google way"
How we tested our code "Google way"
 
FOSDEM 2017 - Open J9 The Next Free Java VM
FOSDEM 2017 - Open J9 The Next Free Java VMFOSDEM 2017 - Open J9 The Next Free Java VM
FOSDEM 2017 - Open J9 The Next Free Java VM
 

Ähnlich wie Choose a pattern for a problem

DevOps Days Vancouver 2014 Slides
DevOps Days Vancouver 2014 SlidesDevOps Days Vancouver 2014 Slides
DevOps Days Vancouver 2014 Slides
Alex Cruise
 
Software Engineering Advice from Google's Jeff Dean for Big, Distributed Systems
Software Engineering Advice from Google's Jeff Dean for Big, Distributed SystemsSoftware Engineering Advice from Google's Jeff Dean for Big, Distributed Systems
Software Engineering Advice from Google's Jeff Dean for Big, Distributed Systems
adrianionel
 
Infrastructure as code might be literally impossible part 2
Infrastructure as code might be literally impossible part 2Infrastructure as code might be literally impossible part 2
Infrastructure as code might be literally impossible part 2
ice799
 
Cerebro general overiew eng
Cerebro general overiew engCerebro general overiew eng
Cerebro general overiew eng
CineSoft
 

Ähnlich wie Choose a pattern for a problem (20)

Making A Game Engine Is Easier Than You Think
Making A Game Engine Is Easier Than You ThinkMaking A Game Engine Is Easier Than You Think
Making A Game Engine Is Easier Than You Think
 
DevOps Days Vancouver 2014 Slides
DevOps Days Vancouver 2014 SlidesDevOps Days Vancouver 2014 Slides
DevOps Days Vancouver 2014 Slides
 
Software Engineering Advice from Google's Jeff Dean for Big, Distributed Systems
Software Engineering Advice from Google's Jeff Dean for Big, Distributed SystemsSoftware Engineering Advice from Google's Jeff Dean for Big, Distributed Systems
Software Engineering Advice from Google's Jeff Dean for Big, Distributed Systems
 
Linux para iniciantes
Linux para iniciantesLinux para iniciantes
Linux para iniciantes
 
Reading Notes : the practice of programming
Reading Notes : the practice of programmingReading Notes : the practice of programming
Reading Notes : the practice of programming
 
Cloud accounting software uk
Cloud accounting software ukCloud accounting software uk
Cloud accounting software uk
 
Preventing Complexity in Game Programming
Preventing Complexity in Game ProgrammingPreventing Complexity in Game Programming
Preventing Complexity in Game Programming
 
Introduction to multicore .ppt
Introduction to multicore .pptIntroduction to multicore .ppt
Introduction to multicore .ppt
 
Creating great Unity games for Windows 10 - Part 2
Creating great Unity games for Windows 10 - Part 2Creating great Unity games for Windows 10 - Part 2
Creating great Unity games for Windows 10 - Part 2
 
Facets Of Fragmentation by Mark Murphy
Facets Of Fragmentation by Mark MurphyFacets Of Fragmentation by Mark Murphy
Facets Of Fragmentation by Mark Murphy
 
Basics of C
Basics of CBasics of C
Basics of C
 
Memory models
Memory modelsMemory models
Memory models
 
Microservices, the lean way - Bruno Bossola - Codemotion Amsterdam 2016
Microservices, the lean way - Bruno Bossola - Codemotion Amsterdam 2016Microservices, the lean way - Bruno Bossola - Codemotion Amsterdam 2016
Microservices, the lean way - Bruno Bossola - Codemotion Amsterdam 2016
 
Microservices, the lean way
Microservices, the lean wayMicroservices, the lean way
Microservices, the lean way
 
Infrastructure as code might be literally impossible part 2
Infrastructure as code might be literally impossible part 2Infrastructure as code might be literally impossible part 2
Infrastructure as code might be literally impossible part 2
 
EuroMPI 2013 presentation: McMPI
EuroMPI 2013 presentation: McMPIEuroMPI 2013 presentation: McMPI
EuroMPI 2013 presentation: McMPI
 
Cerebro general overiew eng
Cerebro general overiew engCerebro general overiew eng
Cerebro general overiew eng
 
Uc13.chapter.05
Uc13.chapter.05Uc13.chapter.05
Uc13.chapter.05
 
Management Information System 8/E | Chapter 8 |
Management Information System 8/E | Chapter 8 | Management Information System 8/E | Chapter 8 |
Management Information System 8/E | Chapter 8 |
 
Full stack development
Full stack developmentFull stack development
Full stack development
 

Mehr von Anton Keks

Mehr von Anton Keks (16)

Java Course 14: Beans, Applets, GUI
Java Course 14: Beans, Applets, GUIJava Course 14: Beans, Applets, GUI
Java Course 14: Beans, Applets, GUI
 
Java Course 13: JDBC & Logging
Java Course 13: JDBC & LoggingJava Course 13: JDBC & Logging
Java Course 13: JDBC & Logging
 
Java Course 12: XML & XSL, Web & Servlets
Java Course 12: XML & XSL, Web & ServletsJava Course 12: XML & XSL, Web & Servlets
Java Course 12: XML & XSL, Web & Servlets
 
Java Course 11: Design Patterns
Java Course 11: Design PatternsJava Course 11: Design Patterns
Java Course 11: Design Patterns
 
Java Course 10: Threads and Concurrency
Java Course 10: Threads and ConcurrencyJava Course 10: Threads and Concurrency
Java Course 10: Threads and Concurrency
 
Java Course 9: Networking and Reflection
Java Course 9: Networking and ReflectionJava Course 9: Networking and Reflection
Java Course 9: Networking and Reflection
 
Java Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsJava Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and Streams
 
Java Course 7: Text processing, Charsets & Encodings
Java Course 7: Text processing, Charsets & EncodingsJava Course 7: Text processing, Charsets & Encodings
Java Course 7: Text processing, Charsets & Encodings
 
Java Course 6: Introduction to Agile
Java Course 6: Introduction to AgileJava Course 6: Introduction to Agile
Java Course 6: Introduction to Agile
 
Java Course 5: Enums, Generics, Assertions
Java Course 5: Enums, Generics, AssertionsJava Course 5: Enums, Generics, Assertions
Java Course 5: Enums, Generics, Assertions
 
Java Course 4: Exceptions & Collections
Java Course 4: Exceptions & CollectionsJava Course 4: Exceptions & Collections
Java Course 4: Exceptions & Collections
 
Java Course 3: OOP
Java Course 3: OOPJava Course 3: OOP
Java Course 3: OOP
 
Java Course 2: Basics
Java Course 2: BasicsJava Course 2: Basics
Java Course 2: Basics
 
Java Course 1: Introduction
Java Course 1: IntroductionJava Course 1: Introduction
Java Course 1: Introduction
 
Java Course 15: Ant, Scripting, Spring, Hibernate
Java Course 15: Ant, Scripting, Spring, HibernateJava Course 15: Ant, Scripting, Spring, Hibernate
Java Course 15: Ant, Scripting, Spring, Hibernate
 
Being a Professional Software Developer
Being a Professional Software DeveloperBeing a Professional Software Developer
Being a Professional Software Developer
 

Kürzlich hochgeladen

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Kürzlich hochgeladen (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 

Choose a pattern for a problem

  • 1. Agile Saturday VI Choose a pattern for a problem! Anton Keks anton@codeborne.com
  • 2. The Increasing Complexity Complexity of software systems Time New programming paradigms Higher level of abstraction HW Assembler Structural (objects+functions?) CPUs Procedural <OOP> ...
  • 3. What are design patterns? ● Anywhere in the world you can find recurring patterns ● Design patterns – are building blocks of a system's architecture – are recurring solutions to design problems that you see over – identify and specify abstractions that are above the level of single classes and instances
  • 4. Pattern classification The GOF book defines 3 major types of patterns: – Creational patterns – substitute the new keyword. This gives your program more flexibility in deciding which objects need to be created for a given case – Structural patterns - compose groups of objects into larger structures, such as complex user interfaces or accounting data – Behavioral patterns - define the communication between objects and how the flow is controlled in a complex program.
  • 5. Decorator Adapter Composite Strategy State Observer Factory Iterator Builder Prototype
  • 6. Software Design: The Good ● Loose coupling ● Immutability ● Encapsulation ● Short code blocks ● Appropriate typing ● Duplication avoidance ● Simplicity ● Consistent terminology ● Clear naming
  • 7. Bad, bad, bad! ● Loose coupling Tight coupling ● Immutability Mutable data structures ● Encapsulation Tramp data ● Short code blocks Monster functions/methods ● Appropriate typing String/Integer overuse ● Duplication avoidance Copy-Paste ● Simplicity Over-engineering ● Consistent terminology Mixture of terms ● Clear naming Runtime surprises
  • 8. Let's get to business! ● Next slides describe problems – What is given (existing code) – What we want to achieve (using a pattern) ● As usual, the code is on github: http://github.com/angryziber/patterns
  • 9. Problem 1: Pizza ● We have: – A pizzeria – Multitude of options for pizzas: name, toppings, thickness, size, delivery address, etc ● We want: – Allow users to “order” custom pizzas – Disallow changing the order once the pizza is already in the oven – Keep the ordering code readable
  • 10. Problem 2: Unzipper ● We have: – unzip() method – It is able to decompress a single compressed stream ● We need: – Support multiple-volume archives – Compressed data is split into multiple floppies
  • 11. Problem 3: Maps ● We have: – Map data of entire Tallinn with all the streets, buildings, etc – The MapVisualizer class that can draw the full map on the screen ● We want: – User to see only a section of the map at any given time – User to be able to move around the map
  • 12. Problem 4: CD Player ● We have: – A CD player with buttons play, stop, next, eject ● We want: – Play to switch the player on – Play again to pause playback, again to resume – Stop to turn off the player – Eject to open the disk tray (if no disk – no playback possible) – etc, etc, etc
  • 13. Problem 5: Vending Machine ● We have: – A vending machine that can sell any small enough items ● We want: – To deploy several such machines selling bottles of pepsi, sushi boxes, and Hintai magazines – Each machine to sell items of one type
  • 14. Problem 6: Spreadsheet ● We have: – A spreadsheet-type program – Containing a table for entering data and formulas ● We want: – The program to support charts – The charts to be updated automatically if user changes the data in the table – To sell the chart add-on separately for only $99.99
  • 15. Problem 7: Battlefield ● We have: – A tank – Several types of bullets – Lots of enemies around, e.g. airplanes, other tanks, guys with Molotov-coctails ● We want: – To survive – To kill 'em all
  • 16. Problem 8: TCP over DNS ● We have: – A paid Wi-Fi network (e.g. in an airport) – Lots of spare time, but no credit card ● We want: – To be able to read emails and surf Facebook – (Most likely, during our next trip) ● Background info: – Paid Wi-Fi usually resolves DNS just fine – DNS packets can contain any payload
  • 17. Thank you! Codeborne is the only true extreme programming company in the region. Come and join us for an experience of a lifetime you can't find elsewhere! job@codeborne.com