Slide 1

Slide 1 text

More than you wanted to know about Service Objects Zero One × RUBYFUZA & FRIENDS

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 × RUBYFUZA & FRIENDS

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 × RUBYFUZA & FRIENDS

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. Let's raid. Zero One × RUBYFUZA & FRIENDS

Slide 5

Slide 5 text

A story about the bad old days More than you wanted to know about Service objects Zero One × RUBYFUZA & FRIENDS

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

M Models are the perfect place for my logic More than you wanted to know about Service objects Zero One × RUBYFUZA & FRIENDS

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 × RUBYFUZA & FRIENDS

Slide 10

Slide 10 text

Developer, meet Service Object. Service Object, meet developer. More than you wanted to know about Service objects Zero One × RUBYFUZA & FRIENDS

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 × RUBYFUZA & FRIENDS

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

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 × RUBYFUZA & FRIENDS

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 × RUBYFUZA & FRIENDS

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 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 × RUBYFUZA & FRIENDS

Slide 21

Slide 21 text

05 Any clearer now? More than you wanted to know about Service objects Zero One × RUBYFUZA & FRIENDS

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 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 × RUBYFUZA & FRIENDS

Slide 27

Slide 27 text

Controllers become super boring. 0 resist the temptation to send params as primary argument Zero One × RUBYFUZA & FRIENDS

Slide 28

Slide 28 text

06 Let's build one More than you wanted to know about Service objects Zero One × RUBYFUZA & FRIENDS

Slide 29

Slide 29 text

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

Slide 30

Slide 30 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 × RUBYFUZA & FRIENDS

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

More than you wanted to know about Service objects Sidekiq Workers Service Objects W Hybrid Service Object × Async Worker Zero One × RUBYFUZA & FRIENDS

Slide 34

Slide 34 text

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