RubyOnRails

MVC Antipatterns : Models Antipatterns

Here are some excepts from Rails Antipattern book that I have reading lately. Even though the examples are specific to rails, the fundamental principles applies to pretty much any MVC framework. In this post, I list out various Model Antipatterns & their potential solutions. I would be writing about other anti-patterns in next posts …

Antipattern # 1 : Voyeuristic Models

  • Solution: Follow the Law of Demeter

  • Solution: Push All find() Calls into Finders on the Model

  • Solution: Keep Finders on Their Own Model

AntiPattern # 2 : Fat Models

  • Solution: Delegate Responsibility to New Classes

  • Solution: Make Use of Modules

  • Solution: Reduce the Size of Large Transaction Blocks

AntiPattern # 3 : Spaghetti SQL

  • Solution: Use Your Active Record Associations and Finders Effectively

  • Solution: Learn and Love the Scope Method

  • Solution: Use a Full-Text Search Engine

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s