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

Advanced Design Patterns in Ruby

Igbanam
August 08, 2020

Advanced Design Patterns in Ruby

Yet another take on design patterns, focusing on the Visitor and Bridge patterns.

Code snippets are here https://github.com/RubyConf-NG/meeetup-snippets/tree/master/ruby-virtual-meetup-2020/advanced-design-patterns-with-ruby

Igbanam

August 08, 2020
Tweet

More Decks by Igbanam

Other Decks in Programming

Transcript

  1. @igbanam Rubyist — been cheating on Ruby with Java, Crystal,

    Scala, and Python RubyConf-NG/openemrs 2 poet. person. programmer.
  2. contents 3 design patterns Advanced design patterns. Benefits of code

    structure. Decoupling. the bridge and the visitor The whens and when-nots. The rumours; the pit-falls. Storytelling with design patterns. demo 1 2 3
  3. from concept to distribution automation, optimization… brains are naturally lazy

    why? What are the groupings? What purpose do they serve? categories? Repeatable solutions to recurring problems what? the language has some barriers ruby? code patterns, application, infrastructure, application domains? 5
  4. Repeatable solutions to recurring problems • started by architects •

    adopted into software ◦ “software architects” what are design patterns?
  5. categories of design patterns 7 creational The most efficient way

    to create objects for certain use cases: singleton, factory, abstract factory, prototype, etc structural Ways to layout code for the least pain when maintaining it: composite, adapter, façade, bridge, etc behavioural Organizing dynamic interactions: null object, observer, iterator, command, blackboard, visitor, etc.
  6. how does Ruby fare? The good… • flexibility with constructs

    • robust standard library • no interfaces (fixed in Sorbet) The bad… • no interfaces …currently The ugly… • modules as interfaces 8
  7. Application Patterns Event Sourcing, CQRS, Saga, Shared Database/Schema, and so

    on Architecture Monolith, MVC, HMVC, Microservices, Blackboard, and so on Infrastructure Serverless (lambdas), VMs, CI/CD Patterns, and so on. Communication Service Registry, RPC, and so on 9 patterns could span multiple development domains
  8. concepts behind the visitor pattern • Inheritance ◦ Basic OO

    • Composition ◦ A Ruby way to feign interfaces • Double Dispatch ◦ Allowing objects define their interaction on other objects at runtime 11