020 RR Object Oriented Programming in Rails with Jim Weirich

by Charles Max Wood on September 14, 2011

Panelists

Discussed in this Episode

  • What is Object Oriented Programming?
  • If Ruby or Rails programmers aren’t programming in an object oriented way does it matter?
  • The goal isn’t to do OO for OO’s sake.
  • Polymorphism
  • Tell, don’t ask
  • Encapsulation
  • Case switching on the object’s class can be refactored to take advantage of Polymorphism
  • Law of Demeter: Am I allowed to know this?
  • Single Responsibility Principle
  • Ask “What does this object do?” rather than building around the data contained in the object.
  • Presenters (The Presenter Pattern)
  • Steven Kabnik’s Post on Object Oriented Programming and the Presenter Pattern in Rails
  • The problem with Helpers
  • In OO, you’re allowed to add more Objects (or Classes)
  • Building your models without referencing ActiveRecord
  • Business objects that reference ActiveRecord data access objects
  • Object Thinking
  • The database is the last bastion of non-object oriented thinking
  • Behavior centric vs data centric design
  • The impedance mismatch between the database and the object oriented designs
  • Inheritance
  • Object Oriented Design centers around maintainability and complexity
  • Don’t use generators
  • Create classes and evolve them into models as you need the persistence
  • Rather than asking for data, tell a class to do something for you
  • Three small things to watch out for:
    • Switch/case on class
    • Arrays and hashes or arrays of hashes of arrays (Primitive Obsession)
    • Subclassing Array or Hash
  • forwardable
  • delegate
  • Don’t inherit from String
  • Enumerable module
  • Rake’s FileList
  • Skinny Controllers
  • Is REST simply a way of pulling the impedance mismatch from the database all the way up to URL’s?

Picks

8 comments
Samnang Chhun
Samnang Chhun

Great podcast! I heard you guys discuss about creating plain old ruby objects in Rails application, and place them in app/model, and not in lib directory. I see many people place custom classes that they created in lib directory, so I'm kind like confuse what is different use for these two directories?

Eric g
Eric g

Great episode. I like the fact that on many of the key questions there was disagreement! Keeps us from assuming there is one true way. Given a lot of the problems seem to center on ActiveRecord and its conventions, I am curious what the panelists think of the 2 other main ruby orms, DataMapper and Sequel, both of which avoid many of AR's problems and in my experience promote more of a domain model approach. What is stopping us from using these instead?

Jesse
Jesse

Best episode so far! Keep up the great work

Mike West
Mike West

You guys are doing an awesome job, the quality and depth of topics discussed are second to none. Love David Brady's enthusiasm and metaphors when putting his point across, brilliant!!! Keep up the excellent work chaps!! P.S: Kudos on getting Kent Beck on the show!!

Dennis Major
Dennis Major

Writing Solid Code - goes 404 which if I put a definition to it is: " happening in the opposite way to what is expected, and typically causing wry amusement" :) BTW - despite the nit picking on my part, these podcasts are *very* good indeed - very much appreciated for just how educational they are - to Charles and all the panelists - thank you.

Trackbacks

  1. [...] anyway? I won’t go into that, go read Steve Klabnik’s blog posts or listen to the Ruby Rogues episode on that [...]

  2. [...] anyway? I won’t go into that, go read Steve Klabnik’s blog posts or listen to the Ruby Rogues episode on that [...]

  3. [...] Objects in Rails part 1 (with Jim Weirich) [...]

  4. [...] The Ruby Rogues have been discussing Object-Oriented Programming in Rails with Jim Weirick. [...]

Previous post:

Next post: