Object-Oriented Lessons for a Service-Oriented World

Object-Oriented Lessons for a Service-Oriented World

Many of the same principles that guide our software design can guide our software architecture. Rarely, though, do we see the same practices applied to our services and APIs, leaving us with tightly coupled and difficult to extend service-oriented architectures. Consider looking at your services as objects and your APIs as messages. Service-oriented applications are complex, and the best way to fend off complexity is though object-oriented design.

96a846bf1220d8e02ee5b5040e825bb5?s=128

Chris Kelly

April 22, 2013
Tweet

Transcript

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

    Poland RailsConf 2013 - Portland, Oregon
  2. Chris Kelly in meatspace

  3. amateurhuman on the interwebs

  4. None
  5. This is a conversation about ideas. It is not a

    prescription for how you have to do it.
  6. San Francisco Krakow Portland Crieff Hydro Warsaw Denver

  7. 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
  8. None
  9. animated gifs

  10. None
  11. MONORAIL

  12. SOFTWARE SO WHAT YOU WANT IS ARCHITECTURE

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

    myself?
  14. NETWORK-BASED APPLICATION SOFTWARE

  15. Monorail Cache Database

  16. Monorail Cache Database

  17. Monorail Cache Database

  18. Monorail Cache Database

  19. Special Snowflake YouR is a application

  20. Special Snowflake YouR is a application that breaksevery time you

    change anything
  21. None
  22. DEPENDENCIES

  23. OBJECT ORIENTED DESIGN D E P E NDE N C

    I E S
  24. State Behavior a thorough and complete analysis of objects* *100%

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

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

    MORE *100% accurate 0% of the time
  27. Cool story, bro. But we’re talking about applications talking over

    http.
  28. HELLO my name is HTTP Object Model

  29. HELLO my name is REST

  30. DRY SOLID LAW OF DEMETER seperation of concerns Single-responsibility principle

    Open-Closed Liskov Substitution Interface Segregation Dependency Inversion Don’t Repeat Yourself Encapsulation
  31. 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.
  32. Repeat Yourself Every piece of knowledge within a system must

    have single, unambiguous, authoritative representation
  33. Depend on Behavior not on data

  34. Dependency Inversion Dependency Inversion

  35. DEMETER LAW OF More like guidelines of Demeter

  36. Dependency Injection

  37. Service Database Service Service Service Service Service

  38. 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.
  39. MESSAGES

  40. 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
  41. Nouns VERBS In object-oriented design, classes are And our messages

    are often
  42. /getUsers /verifyEmailAddress /getOrders /updateShippingAddress

  43. GET PUT POST DELETE HTTP already has some verbs But

    they’re kind of crudy
  44. What about hypermedia?

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

  46. REST HYPERMEDIA COMBINES A MEDIA TYPE & LINK RELATIONS

  47. { “_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
  48. { “_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
  49. Approaching a Behavioral API

  50. 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,
  51. Close an issue PATCH /repos/:owner/:repo/issues/:number { "state": "closed" }

  52. 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",
  53. Merge Button PUT /repos/:owner/:repo/pulls/:number/merge { # Optional Message "message": "YOLO"

    } TM
  54. 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
  55. Thanks for the chat. @amateurhuman