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

More than you wanted to know about Service Objects

More than you wanted to know about Service Objects

It’s high time junior developers reap the benefits of Service Objects that intermediate and senior developers have been enjoying for ages. This talk will reveal the techniques we use to make our apps simpler, more testable, and infinitely easier to refactor.

Gabriel Fortuna

February 07, 2019
Tweet

More Decks by Gabriel Fortuna

Other Decks in Programming

Transcript

  1. 4 Things About Me Coding In The Bad Old Days

    Meet Service Objects Service Object Nirvana What's In It For Me? Hey Kid, Wanna Build One? Tips & Tricks Questions & Closing I. II. III. IV. V. VI. VII. VIII. 00 Todays Agenda More than you wanted to know about Service objects Zero One × RUBYFUZA & FRIENDS
  2. 01 More than you wanted to know about Service objects

    4 Things About Me My Family My Dogs My Company Zero One × RUBYFUZA & FRIENDS
  3. 01 Too much Destiny More than you wanted to know

    about Service objects Hit me up on gee-forr on PSN. Let's raid. Zero One × RUBYFUZA & FRIENDS
  4. A story about the bad old days More than you

    wanted to know about Service objects Zero One × RUBYFUZA & FRIENDS
  5. V Logic in your views More than you wanted to

    know about Service objects Zero One × RUBYFUZA & FRIENDS
  6. C What about controllers? More than you wanted to know

    about Service objects Zero One × RUBYFUZA & FRIENDS
  7. M Models are the perfect place for my logic More

    than you wanted to know about Service objects Zero One × RUBYFUZA & FRIENDS
  8. Mixed concerns Single use context Hard to refactor Difficult to

    extend Painful to test More than you wanted to know about Service objects ⇣ The downside Zero One × RUBYFUZA & FRIENDS
  9. Developer, meet Service Object. Service Object, meet developer. More than

    you wanted to know about Service objects Zero One × RUBYFUZA & FRIENDS
  10. A Service Object is a Plain old Ruby Object, that

    is meant to decompose business logic into manageable classes and methods. Rob Race, Hackernoon (http://bit.ly/serv-objs-1) “ ” Zero One × RUBYFUZA & FRIENDS
  11. 03 More than you wanted to know about Service objects

    What makes a Service Object great? 7 Preferably via single public method It Does One Thing 8 Simple Services can compose together to implement complex processes They Can Chain Together F Gives you more than a simple boolean return value Complex Return Objects Zero One × RUBYFUZA & FRIENDS
  12. organisers 03 Let's get meta More than you wanted to

    know about Service objects Two types typically found in the wild: actions & Zero One × RUBYFUZA & FRIENDS
  13. What changed for me when I started using Service Objects

    in my code? More than you wanted to know about Service objects Zero One × RUBYFUZA & FRIENDS
  14. 04 What Changed? More than you wanted to know about

    Service objects Give some input Test some output Stub friendly Tests became easier     Change friendly architecture Limited blast radius for changes Logic can be swapped out easily Logic can be dropped easily Changes to reqs are simpler      Zero One × RUBYFUZA & FRIENDS
  15. 04 What Changed? More than you wanted to know about

    Service objects Logic reuse Reuse across situations Reuse became a reality    Objectively simpler code Most code fits in a screen More devs can contribute Less complexity → more quality Lower overall code complexity L     Zero One × RUBYFUZA & FRIENDS
  16. 05 What can I expect if I use Service Objects?

    Zero One × RUBYFUZA & FRIENDS More than you wanted to know about Service objects
  17. 05 What is this? More than you wanted to know

    about Service objects What does it do? Zero One × RUBYFUZA & FRIENDS
  18. 05 How about now? More than you wanted to know

    about Service objects Zero One × RUBYFUZA & FRIENDS What does it do?
  19. 05 Great if you're DHH More than you wanted to

    know about Service objects Not so great for the rest of us. Zero One × RUBYFUZA & FRIENDS
  20. 05 Any clearer now? More than you wanted to know

    about Service objects Zero One × RUBYFUZA & FRIENDS
  21. 05 Let's take a closer look More than you wanted

    to know about Service objects Zero One × RUBYFUZA & FRIENDS
  22. IssuesJWT IssuesCookie FetchExistingUserForOpenIDPayload CreateUserForOpenIDPayload More than you wanted to know

    about Service objects 05 Simpler feature refactoring LogUserIn Zero One × RUBYFUZA & FRIENDS
  23. UpdateWhileYouWereGoneNotifications SendWelcomeBackEmail IssuesJWT FetchExistingUserForOpenIDPayload CreateUserForOpenIDPayload More than you wanted to

    know about Service objects 05 Modular logic at the process layer LogUserIn Zero One × RUBYFUZA & FRIENDS
  24. Actions have easily stubbable or mockable inputs, and easily testable

    outputs Organisers take code on a journey, traversing through the whole stack. They implement a process end to end. Treat like unit tests Actions Treat like integration tests Organisers Zero One × RUBYFUZA & FRIENDS
  25. Web Controllers Async jobs Rake tasks 05 Use outside of

    just web requests More than you wanted to know about Service objects Your application is more than just a series of HTTP transactions Zero One × RUBYFUZA & FRIENDS
  26. Controllers become super boring. 0 resist the temptation to send

    params as primary argument Zero One × RUBYFUZA & FRIENDS
  27. 06 Let's build one More than you wanted to know

    about Service objects Zero One × RUBYFUZA & FRIENDS
  28. Tip, Tricks, etc 07 More than you wanted to know

    about Service objects Zero One × RUBYFUZA & FRIENDS
  29. 07 Name after steps in business process. Avoid naming after

    implementation details. InviteFriend is better than CreateLinkedUser Actions P Naming More than you wanted to know about Service objects Name after business processes Organisers f Zero One × RUBYFUZA & FRIENDS
  30. Not traditional. Publish/ Subscribe Framework Wisper Plenty of features, like

    rollbacks. Responsive developer. Light-Service Can be very powerful. D.R.Y? more like D.I.Y, amirite? Dry-rb Battle-tested. Simple. Core features supported. Has plugins. Recommended. Interactor 07 More than you wanted to know about Service objects Picking a Service Object Framework 01 02 03 04 Zero One × RUBYFUZA & FRIENDS
  31. 07 More than you wanted to know about Service objects

    Programatically generate action sequences Zero One × RUBYFUZA & FRIENDS
  32. More than you wanted to know about Service objects Sidekiq

    Workers Service Objects W Hybrid Service Object × Async Worker Zero One × RUBYFUZA & FRIENDS
  33. 08 Thank you! More than you wanted to know about

    Service objects Gabriel Fortuna / [email protected] / @gee_forr Zero One / zero-one.io / @we_are_zero_one Kill some mediocrity with us - We're hiring. Zero One × RUBYFUZA & FRIENDS Seriously, let's play some Destiny, PSN: gee-forr