Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Design Patterns: Consultant Hype or Best Pra...

Avatar for Bob Bloom Bob Bloom
November 14, 2016

Design Patterns: Consultant Hype or Best Practices?

It is not always obvious that we should use design patterns. We have to use our professional judgement, with an eye to simplicity. Presented at the second York Region PHP Group on Nov 14, 2016

Avatar for Bob Bloom

Bob Bloom

November 14, 2016
Tweet

Other Decks in Programming

Transcript

  1. Design Patterns: Consultant Hype or Best Practices? York Region PHP

    Group November 14, 2016 Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca) 2
  2. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    3 Over Engineered? Pad Invoice? Engender Perception of Expert? Programming Purity?
  3. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    4 If you remember just one word from this presentation, remember…
  4. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    8 Laravel Conference Europe 2015 (aka Laracon EU 2016) Jeffrey Way Writing Software is Hard -> see 8m20s
  5. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    9 Design Patterns are supposed to make programming easier for you
  6. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    11 Design Patterns: Elements of Reusable Object-Oriented Software is a software engineering book describing software design patterns. The book's authors are Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides with a foreword by Grady Booch. The book is divided into two parts, with the first two chapters exploring the capabilities and pitfalls of object-oriented programming, and the remaining chapters describing 23 classic software design patterns. The book includes examples in C++ and Smalltalk. It has been influential to the field of software engineering and is regarded as an important source for object-oriented design theory and practice. More than 500,000 copies have been sold in English and in 13 other languages. The authors are often referred to as the Gang of Four (GoF).[1] https://en.wikipedia.org/wiki/Design_Patterns
  7. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    13 Re-usable = create once, use often = no having to write any code! not really….
  8. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    14 Design patterns provide solutions to common software design problems. In the case of object- oriented programming, design patterns are generally aimed at solving the problems of object generation and interaction, rather than the larger scale problems of overall software architecture. They give generalised solutions in the form of templates that may be applied to real-world problems. http://www.blackwasp.co.uk/gofpatterns.aspx
  9. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    15 Design patterns are a powerful tool for software developers. However, they should not be seen as prescriptive specifications for software. It is more important to understand the concepts that design patterns describe, rather than memorising their exact classes, methods and properties. It is also important to apply patterns appropriately. Using the incorrect pattern for a situation or applying a design pattern to a trivial solution can overcomplicate your code and lead to maintainability issues. http://www.blackwasp.co.uk/gofpatterns.aspx
  10. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    16 The Book describes 23 Design Patterns, each within one of three categories
  11. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    17 Creational Patterns Instantiate single objects or groups of related objects. 1. Abstract factory 2. Builder 3. Factory method 4. Prototype 5. Singleton http://www.blackwasp.co.uk/gofpatterns.aspx
  12. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    18 Structural Patterns Define relationships between classes or objects. 1. Adaptor 2. Bridge 3. Composite 4. Decorator 5. Facade 6. Flyweight 7. Proxy http://www.blackwasp.co.uk/gofpatterns.aspx
  13. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    19 Behaviour Patterns Communication between classes or objects. 1. Chain of responsibility 2. Command 3. Interpreter 4. Iterator 5. Mediator 6. Memento 7. Observer 8. State 9. Strategy 10.Template Method 11.Visitor http://www.blackwasp.co.uk/gofpatterns.aspx
  14. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    20 Download this UML reference sheet at http://www.blackwasp.co.uk/GangOfFour.aspx
  15. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    21 Re-usable code? Well, not quite… A design pattern is not a detailed spec. Rather, one may think of it as a description of the accumulated experience…
  16. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    22 Each pattern describes a problem which occurs over and over… and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice. Christopher Alexander AIS, 1977 https://en.wikipedia.org/wiki/Christopher_Alexander
  17. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    25 Design Patterns in Laravel (list compiled for L4, current version L5.3) 1. Iterators 2. Observer 3. Dispatcher 4. Singleton 5. Alias Loader 6. Façade 7. Decorator 8. Repository 9. Builder 10. Factory (list not exhaustive) Phill Sparks - Software Design Patterns in Laravel 4 LaraConEU2013 https://www.youtube.com/watch?v=qkIsTtIcTBE
  18. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    26 Anti Pattern: An anti-pattern is a common response to a recurring problem that is usually ineffective and risks being highly counterproductive. The term, coined in 1995 by Andrew Koenig,[3] was inspired by a book, Design Patterns, which highlights a number of design patterns in software development that its authors considered to be highly reliable and effective. (https://en.wikipedia.org/wiki/Anti-pattern)
  19. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    27 9 Anti-Patterns Every Programmer Should Be Aware Of 1. Premature Optimization 2. Bikeshedding 3. Analysis Paralysis 4. God Class 5. Fear of Adding Classes 6. Inner-platform Effect 7. Magic Numbers and Strings 8. Management by Numbers 9. Useless (Poltergeist) Classes (http://sahandsaba.com/nine-anti-patterns-every-programmer-should-be-aware-of-with- examples.html)
  20. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    28 Best Practices or Bravo Sierra? What If… It took more code to do the design pattern than the actual thing you are coding? You were told that you suck as a programmer because you did not use a well known design pattern? You could code faster sticking with how a framework does it, but you are sure that you would be better off with a “framework agnostic” solution that uses a better implementation of an established design pattern?
  21. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    29 Does blind adherence to design patterns impart guaranteed benefits? If it did, then IMO I doubt this subject would be controversial enough to be debated so passionately for over 2 decades. And, I suspect that I would have been subject to major grief for the title of this talk.
  22. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    30 Professional Judgement • Knowledge • Experience • Objectivity It’s not always obvious what design patterns to introduce into your software. You have to make decisions.
  23. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    31 Technical Debt The extra development work that arises when code that is easy to implement in the short run is used instead of applying the best overall solution. (https://www.techopedia.com/definition/27913/technical-debt)
  24. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    32 Technical Debt Technical debt is a metaphor that equates software development to financial debt. Imagine that you have a project that has two potential options. One is quick and easy but will require modification in the future. The other has a better design, but will take more time to implement. In development, releasing code as a quick and easy approach is like incurring debt - it comes with the obligation of interest, which, for technical debt, comes in the form of extra work in the future. Taking the time to refactor is equivalent to paying down principal. While this takes time in the short run, it also decreases future interest payments. (https://www.techopedia.com/definition/27913/technical-debt)
  25. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    33 Technical Debt Ward Cunningham, a programmer who is also known for developing the first wiki, describes this concept in 1992: "Shipping first-time code is like going into debt. A little debt speeds development so long as it is paid back promptly with a rewrite… The danger occurs when the debt is not repaid. Every minute spent on not-quite-right code counts as interest on that debt. Entire engineering organizations can be brought to a stand-still under the debt load of an unconsolidated implementation, object-oriented or otherwise." (https://www.techopedia.com/definition/27913/technical-debt)
  26. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    35 Automated Software Testing, the Composer Eco-System, and Continuous Integration It’s not 1994. As Chris Hartjes said at our inaugural meet-up, we need to think about Continuous Integration. We have to think about the software pipeline. Getting code from commit to production. Software has to be test-able. With the composer eco-system exploding, when do we use external packages?
  27. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    36 Jeffrey Way’s Laracast Snippet Podcasd: Developer Arrogance First two minutes! https://laracasts.simplecast.fm/36
  28. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    37 Full Stack Radio #52: Taylor Otwell – Patterns for Simplifying Laravel Applications (http://www.fullstackradio.com/52) Taylor’s summary at 68:50
  29. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    38 Excellent video: Brandon Savage – Design Patterns Workshop Sunshine PHP 2014 https://www.youtube.com/watch?v=0L1pgDPt8U8
  30. Nov 14, 2016 York Region PHP -- Design Patterns (https://yorkregionphp.ca)

    39 Thank you! Questions? Contact me at: • @bobbloom • LaSalleSoftware.com • [email protected] • Github.com/LaSalleCMS This presentation was created using Powerpoint (!) This presentation created for the November 14, 2016 York Region PHP Group meet-up. See YorkRegionPHP.ca and Meetup.com/York-region-php-user-group. Design Patterns: Consultant Hype or Best Practice? Copyright 2016 South LaSalle. This work is licensed under Creative Commons Attribution ShareAlike 4.0 International. For uses not covered under this license, please contact the author.