Coder Social home page Coder Social logo

fatmodels's Introduction

Lean and Mean Domain Objects in Active Record

Rails apps that have been extensively enhanced and maintained over the last few years are starting to fall apart under their own weight. Developers have struggled trying to find the most appropriate area to place logic within the system. Initially the ease of writing views in ERB led many developers to stow code at the front of the application. Then we began finding the views too difficult to maintain so we moved the logic into controllers or helpers. Eventually this also became difficult to maintain so "best practices" espoused skinny controllers and fat models. Active Record domain models naturally became the dumping ground of logic within the system but sooner or later this also leads to brittle, unmaintainable, bug filled systems.

Coupling persistence, validation, advanced querying, and business logic all into the same class inevitably leads to extremely fat models with any system of significance. Skinny controllers are definitely worth striving for, but shoveling all of the business logic into a class that is already overburdened with with three other concerns is a recipe for disaster. When you find yourself using factories, fixtures, or mocks to construct 8 different class dependencies, it's time to admit that fat models are not a solution worth aspiring to.

This talk will cover some different approaches for segregating the multiple concerns of fat Active Record models into loosely coupled, cohesive classes with single responsibilities. We'll dive into both the process for refactoring these plump classes along with some better patterns to helo avoid AR bloat.

fatmodels's People

Contributors

jasonkarns avatar tkaufman avatar

Watchers

 avatar  avatar

Forkers

blocktator

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.