Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I try to follow a gradual approach to decomposition. When I start to get a lot of related methods I wrap them in a module, but still within the model definition(I just include the module immediately after definition). From there I might just move it to a separate file as is or perhaps I turn into a decorator and add an accessor for it on the model e.g.

  class Retailer
    ...
    def metrics
      RetailerMatrics.new(self)
    end
  end

  class RetailerMetrics < Struct.new(:retailer)
    def profit
      # devious stat twisting
    end
  end
The biggest danger with any of the patterns from the article is that you start using them before you actually need them. Then you just end up with a lot of complexity for no benefit.


Yes! Gradual is they key. Your architecture should scale up gradually to handle the app complexity.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: