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

Better OO Design in Rails

Better OO Design in Rails

Slides from a discussion I introduce at Rails Camp 14 and again at rorosyd on 12 November, 2013. Note that these slides only provide a glimpse as they don't include the before and after code examples nor, obviously, the discussion that ensued.

Keith Pitty

November 13, 2013
Tweet

More Decks by Keith Pitty

Other Decks in Programming

Transcript

  1. www.cockatoosoftware.com.au
    Better OO Design in Rails
    Keith Pitty
    @keithpitty

    View Slide

  2. www.cockatoosoftware.com.au
    I have a confession …

    View Slide

  3. www.cockatoosoftware.com.au
    which class should be responsible?

    View Slide

  4. www.cockatoosoftware.com.au
    is this class adhering to the
    Single Responsibility Principle?

    View Slide

  5. www.cockatoosoftware.com.au
    “A class should do the smallest possible thing;
    that is, it should have a single responsibility.”

    View Slide

  6. www.cockatoosoftware.com.au
    a better attempt …

    View Slide

  7. www.cockatoosoftware.com.au

    View Slide

  8. www.cockatoosoftware.com.au
    other OO design principles …

    View Slide

  9. www.cockatoosoftware.com.au
    managing dependencies

    View Slide

  10. www.cockatoosoftware.com.au
    creating flexible interfaces

    View Slide

  11. www.cockatoosoftware.com.au
    duck typing

    View Slide

  12. www.cockatoosoftware.com.au
    using inheritance appropriately

    View Slide

  13. www.cockatoosoftware.com.au
    sharing role behaviour with modules

    View Slide

  14. www.cockatoosoftware.com.au
    composition

    View Slide

  15. www.cockatoosoftware.com.au
    how well does Rails support
    good OO design?

    View Slide

  16. www.cockatoosoftware.com.au
    what about functional programming?

    View Slide

  17. www.cockatoosoftware.com.au
    what do you think?

    View Slide

  18. www.cockatoosoftware.com.au
    Some resources
    “Practical Object-Oriented Design in Ruby” by Sandi Metz
    "Objects on Rails" by Avdi Grimm
    "Designing Object-Oriented Software" by Rebecca Wirfs-Brock et al
    "Refactoring: Ruby Edition" by Jay Fields, Shane Harvie and Martin
    Fowler
    "Design Patterns in Ruby" by Russ Olsen

    View Slide