Slide 1

Slide 1 text

object-oriented lessons for a service-oriented world Railsberry 2013 Krakow, Poland

Slide 2

Slide 2 text

Chris Kelly in meatspace

Slide 3

Slide 3 text

amateurhuman on the interwebs

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

This is a conversation about ideas. It is not a prescription for how you have to do it.

Slide 6

Slide 6 text

San Francisco Krakow Portland Crieff Hydro Warsaw Denver

Slide 7

Slide 7 text

Lynx (web browser) - Wikipedia, the free encyclopedia (p1 of 26) #Edit this page Wikipedia (en) copyright Wikipedia Atom feed Lynx (web browser) From Wikipedia, the free encyclopedia Jump to: navigation, search Not to be confused with Links (web browser) or LynxOS. Original author(s) Lou Montulli, Michael Grobe, Charles Rezac Developer(s) Thomas Dickey Initial release 1992 (1992) Lynx is a highly configurable text-based web browser for use on cursor-addressable character cell terminals.^[1]^[2] It is the oldest web browser currently in general use and development,^[3] having started in 1992 and as of 2013^[update], 21 years later, still in use and development. Arrow keys: Up and Down to move. Right to follow a link; Left to go back. H)elp O)ptions P)rint G)o M)ain screen Q)uit /=search [delete]=history list

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

animated gifs

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

MONORAIL

Slide 12

Slide 12 text

SOFTWARE SO WHAT YOU WANT IS ARCHITECTURE

Slide 13

Slide 13 text

Software architecture? Did you just tell me to go F*@< myself?

Slide 14

Slide 14 text

NETWORK-BASED APPLICATION SOFTWARE

Slide 15

Slide 15 text

Monorail Cache Database

Slide 16

Slide 16 text

Monorail Cache Database

Slide 17

Slide 17 text

Monorail Cache Database

Slide 18

Slide 18 text

Monorail Cache Database

Slide 19

Slide 19 text

Special Snowflake YouR is a application

Slide 20

Slide 20 text

Special Snowflake YouR is a application that breaksevery time you change anything

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

DEPENDENCIES

Slide 23

Slide 23 text

OBJECT ORIENTED DESIGN D E P E NDE N C I E S

Slide 24

Slide 24 text

State Behavior a thorough and complete analysis of objects* *100% accurate 0% of the time

Slide 25

Slide 25 text

State Behavior a thorough and complete analysis of objects* *100% accurate 0% of the time

Slide 26

Slide 26 text

State Behavior a thorough and complete analysis of objects* ^ MORE *100% accurate 0% of the time

Slide 27

Slide 27 text

Cool story, bro. But we’re talking about applications talking over http.

Slide 28

Slide 28 text

HELLO my name is HTTP Object Model

Slide 29

Slide 29 text

HELLO my name is REST

Slide 30

Slide 30 text

DRY SOLID LAW OF DEMETER seperation of concerns Single-responsibility principle Open-Closed Liskov Substitution Interface Segregation Dependency Inversion Don’t Repeat Yourself Encapsulation

Slide 31

Slide 31 text

Single Responsibility Do one thing, and do it well. Do the smallest thing possible, and nothing more. Make things as simple as possible, but not simpler. Cohesive, everything it does should be related to its purpose.

Slide 32

Slide 32 text

Repeat Yourself Every piece of knowledge within a system must have single, unambiguous, authoritative representation

Slide 33

Slide 33 text

Depend on Behavior not on data

Slide 34

Slide 34 text

Dependency Inversion Dependency Inversion

Slide 35

Slide 35 text

DEMETER LAW OF More like guidelines of Demeter

Slide 36

Slide 36 text

Dependency Injection

Slide 37

Slide 37 text

Service Database Service Service Service Service Service

Slide 38

Slide 38 text

Public Service Announcement Cache is King Network-based software applications mean more overhead. Serialization is expensive, do yourself a favor and don’t do it when you don’t have to. Cache-control and etag headers are a services best friend. Caching is a first order feature.

Slide 39

Slide 39 text

MESSAGES

Slide 40

Slide 40 text

class Orders < ApplicationController::Base def index @orders = Order.all respond_to do |format| format.html format.json { render json: @orders } end end end Not a Application Programming Interface

Slide 41

Slide 41 text

Nouns VERBS In object-oriented design, classes are And our messages are often

Slide 42

Slide 42 text

/getUsers /verifyEmailAddress /getOrders /updateShippingAddress

Slide 43

Slide 43 text

GET PUT POST DELETE HTTP already has some verbs But they’re kind of crudy

Slide 44

Slide 44 text

What about hypermedia?

Slide 45

Slide 45 text

This is not your Rails’ REST https://api.example.org/accounts/23/orders/37

Slide 46

Slide 46 text

REST HYPERMEDIA COMBINES A MEDIA TYPE & LINK RELATIONS

Slide 47

Slide 47 text

{ “_links”: { “self”: { “href”: “/orders” }, “next”: { “href”: “/orders?page=2” }, “find”: { “href”: “/orders/{id}”, “templated”: true }, “_embedded”: { “orders”: [{ “_links”: { “self”: { “href”: “/orders/123” } }, “total”: 1337.00 Behavior { { State

Slide 48

Slide 48 text

{ “_links”: { “self”: { “href”: “/orders” }, “next”: { “href”: “/orders?page=2” }, “find”: { “href”: “/orders/{id}”, “templated”: true }, “_embedded”: { “orders”: [{ “_links”: { “self”: { “href”: “/orders/123” }, “cancel”: { “href”: “/orders/123/cancel” } }, Behavior { { State

Slide 49

Slide 49 text

Behavioral API by Example

Slide 50

Slide 50 text

Get a single issue GET /repos/:owner/:repo/issues/:number { "url": "https://api.github.com/repos/octocat/Hello-World/issues/134 "html_url": "https://github.com/octocat/Hello-World/issues/1347", "number": 1347, "state": "open", "title": "Found a bug", "body": "I'm having a problem with this.", "user": { "login": "octocat", "id": 1,

Slide 51

Slide 51 text

Close an issue PATCH /repos/:owner/:repo/issues/:number { "state": "closed" }

Slide 52

Slide 52 text

Get a pull request GET /repos/:owner/:repo/pulls/:number { "url": "https://api.github.com/octocat/Hello-World/pulls/1", "html_url": "https://github.com/octocat/Hello-World/pulls/1", "diff_url": "https://github.com/octocat/Hello-World/pulls/1.diff", "patch_url": "https://github.com/octocat/Hello-World/pulls/1.patch "issue_url": "https://github.com/octocat/Hello-World/issue/1", "number": 1, "state": "open", "title": "new-feature", "body": "Please pull these awesome changes",

Slide 53

Slide 53 text

Merge Button PUT /repos/:owner/:repo/pulls/:number/merge { # Optional Message "message": "YOLO" } TM

Slide 54

Slide 54 text

The Good The Bad The Ugly Link relations are already appearing in media types You can implement custom media types The necessary HTTP verb is a missing

Slide 55

Slide 55 text

Thanks for the chat. @amateurhuman