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… read them below or add one }

iain September 14, 2011 at 8:24 pm

I don’t see the audio element :’(

Reply

nolink_nowink September 15, 2011 at 1:44 am

+1

Reply

Where is mp3? September 15, 2011 at 2:07 pm

+1

Reply

Dennis Major September 16, 2011 at 11:00 am

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.

Reply

Mike West September 16, 2011 at 11:26 am

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!!

Reply

Jesse September 18, 2011 at 2:13 am

Best episode so far!

Keep up the great work

Reply

Eric g September 25, 2011 at 9:19 pm

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?

Reply

Samnang Chhun October 16, 2011 at 11:21 am

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?

Reply

Leave a Comment

{ 4 trackbacks }

Previous post:

Next post: