Slide 1

Slide 1 text

More than you wanted to know about Service Objects Zero One × Rubyconf TH

Slide 2

Slide 2 text

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 × Rubyconf TH

Slide 3

Slide 3 text

01 More than you wanted to know about Service objects 4 Things About Me My Family My Dogs My Company Zero One × Rubyconf TH

Slide 4

Slide 4 text

01 Too much Destiny More than you wanted to know about Service objects Hit me up on gee-forr on PSN. gee_forr on Steam. Let's raid. Zero One × Rubyconf TH

Slide 5

Slide 5 text

A story about the bad old days More than you wanted to know about Service objects Zero One × Rubyconf TH

Slide 6

Slide 6 text

V Logic in your views More than you wanted to know about Service objects Zero One × Rubyconf TH

Slide 7

Slide 7 text

C What about controllers? More than you wanted to know about Service objects Zero One × Rubyconf TH

Slide 8

Slide 8 text

M Models are the perfect place for my logic, right? More than you wanted to know about Service objects Zero One × Rubyconf TH

Slide 9

Slide 9 text

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 × Rubyconf TH

Slide 10

Slide 10 text

Developer, meet Service Object. Service Object, meet developer. More than you wanted to know about Service objects Zero One × Rubyconf TH

Slide 11

Slide 11 text

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 × Rubyconf TH

Slide 12

Slide 12 text

03 More than you wanted to know about Service objects What makes a Service Object great? 7 Preferably via a single public method like call() 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 × Rubyconf TH

Slide 13

Slide 13 text

03 Let's get meta More than you wanted to know about Service objects Two types typically found in the wild: Actions & Composers Zero One × Rubyconf TH

Slide 14

Slide 14 text

What changed when I started using Service Objects in my code? More than you wanted to know about Service objects Zero One × Rubyconf TH

Slide 15

Slide 15 text

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 × Rubyconf TH

Slide 16

Slide 16 text

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 × Rubyconf TH

Slide 17

Slide 17 text

04 What Changed? More than you wanted to know about Service objects Clear codepath Linear logic flow Self-documenting sequencing Flattened structure with no or minimal nesting Explicit Flow C     Zero One × Rubyconf TH

Slide 18

Slide 18 text

05 More than you wanted to know about Service objects What can I expect if I use Service Objects? Zero One × Rubyconf TH

Slide 19

Slide 19 text

05 What is this? More than you wanted to know about Service objects What does it do?

Slide 20

Slide 20 text

05 How about now? More than you wanted to know about Service objects

Slide 21

Slide 21 text

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 × Rubyconf TH

Slide 22

Slide 22 text

05 Any clearer now? More than you wanted to know about Service objects

Slide 23

Slide 23 text

05 Let's take a closer look More than you wanted to know about Service objects

Slide 24

Slide 24 text

IssuesJWT IssuesCookie FetchExistingUserForOpenIDPayload CreateUserForOpenIDPayload More than you wanted to know about Service objects 05 Simpler feature refactoring LogUserIn Zero One × Rubyconf TH

Slide 25

Slide 25 text

UpdateWhileYouWereGoneNotifications SendWelcomeBackEmail IssuesJWT FetchExistingUserForOpenIDPayload FetchExistingUserForOpenIDPayload More than you wanted to know about Service objects 05 Modular logic at the process layer LogUserIn Zero One × Rubyconf TH

Slide 26

Slide 26 text

Services have easily stubbable or mockable inputs, and easily testable outputs Organisers take code on a journey, traversing through a 'full stack'. They implement a process end to end. Treat like unit tests Services Treat like integration tests Organisers

Slide 27

Slide 27 text

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 × Rubyconf TH

Slide 28

Slide 28 text

Controllers become super boring. 0 resist the temptation to send params as primary argument Zero One × Rubyconf TH

Slide 29

Slide 29 text

06 Let's build one More than you wanted to know about Service objects Zero One × Rubyconf TH

Slide 30

Slide 30 text

Tip, Tricks, etc 07 More than you wanted to know about Service objects Zero One × Rubyconf TH

Slide 31

Slide 31 text

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 × Rubyconf TH

Slide 32

Slide 32 text

Not traditional. Publish/ Subscribe Framework Wisper ! Plenty of features. Responsive developer. Light-Service ^ Can be very powerful. D.R.Y? more like D.I.Y, amirite? Dry-rb B Battle-tested. Simple. Core features supported. Has plugins. Recommended. Interactor V 07 More than you wanted to know about Service objects Picking a Service Object Framework 01 02 03 04 Zero One × Rubyconf TH

Slide 33

Slide 33 text

07 Programatically generate action sequences

Slide 34

Slide 34 text

More than you wanted to know about Service objects Sidekiq Worker Service Object Hybrid Service Object × Async Worker

Slide 35

Slide 35 text

08 Khop khun krab! 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. Seriously, let's play Destiny. PSN: gee-forr. Steam: gee_forr Zero One × Rubyconf TH

Slide 36

Slide 36 text

Rubyfuza February 2020 Cape Town South Africa rubyfuza.org