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

Viking Code School Presents Christopher Hendrix of Pivotal Labs

Viking Code School Presents Christopher Hendrix of Pivotal Labs

A materials science engineer by training, a developer by profession, and a designer by passion, Chris will be speaking about object orientation in Ruby.

Viking Education

July 10, 2015
Tweet

More Decks by Viking Education

Other Decks in Technology

Transcript

  1. @materialdesignr #goodobjects This talk’s • 5 Family Member “Guiding Principles”

    • Quote • Theory/Introduction • Code Examples • Summary • Extra Reading • Q&A Structure
  2. @materialdesignr #goodobjects Think like a • Values vs Entities •

    Colors/Numbers vs People
 • Can a Person be a Value Type? • Is teleportation murder? Teenager
  3. @materialdesignr #goodobjects Think like a • Separate Fundamental Attributes from

    Computed Properties • Think of a single Designated Initializer • Use Custom Initializers which delegate • Hide your “Subtyping” Teenager
  4. @materialdesignr #goodobjects • f(x) = x^2 • A transformation •

    What makes f(x) a Good Function? Think like a Child
  5. @materialdesignr #goodobjects “A function is a relation between a set

    of inputs and a set of permissible outputs with the property that each input is related to exactly one output.” All Integer 1 2 3 ⋮ + Integer 1 4 9 ⋮
  6. @materialdesignr #goodobjects • f(x) = x^2 • A Good Function

    has • Consistent Input Types • Consistent Output Types • Well defined relation from each input to output Think like a Child Integer 1 2 3 ⋮ Integer 1 4 9 ⋮
  7. @materialdesignr #goodobjects Think like a • Think of your function’s

    Type Signatures • Have consistent outputs • Use Arrays to encode potential failure Child
  8. @materialdesignr #goodobjects Think like an • Not everyone else makes

    good functions • Function dependencies are 
 sources of uncertainty Adult
  9. @materialdesignr #goodobjects Think like an • Say No to bad

    dependencies • Earliest Possible Rejection • Wrap External Objects in Confident Values Adult
  10. @materialdesignr #goodobjects Think like a • Is it really Data?

    • Functions vs. Methods vs. Messages Senior @materialdesignr Sally Bob Age:
 24 24
  11. @materialdesignr #goodobjects Think like a • Is it really Data?

    • Functions vs. Methods vs. Messages Senior Sally Bob Age:
 24 29 Age? def age if trying_to_impress? return @age + 5 else return @age end end
  12. @materialdesignr #goodobjects Think like a • Is it really Data?

    • Functions vs. Methods vs. Messages • Same Message, Different Methods Senior Sally Harry Age:
 32 32 Age? def age # I’m honest return @age end
  13. @materialdesignr #goodobjects Think like a • There is No Data,

    Only Zuul Messages • Ask Nicely instead of grabbing internals • Tell Confidently instead of DIY Senior
  14. @materialdesignr #goodobjects Think like a • What’s so special about

    me? • Everything is message sending • Messages to Self Baby
  15. @materialdesignr #goodobjects Think like a • Other Methods should be

    treated like Other Objects • Hide your own data Baby
  16. @materialdesignr #goodobjects This talk’s • Teenager — Make your constructors

    matter • Child — Think about function signatures • Adult — Use errors to prevent unknown state • Senior — Send messages to other objects • Baby — Send messages to yourself Summary
  17. @materialdesignr #goodobjects Reading is Practical Object Oriented Design in Ruby


    ―Sandi Metz Confident Ruby
 ―Avdi Grimm Refactoring
 ―Martin Fowler Fundamental