Ways to Decompose Fat ActiveRecord Models
blog.codeclimate.com
Ways to Decompose Fat ActiveRecord Models
1–10 of 21 posts
Re: Ways to Decompose Fat ActiveRecord Models
#2Re: Ways to Decompose Fat ActiveRecord Models
#3Re: Ways to Decompose Fat ActiveRecord Models
#4I like Ruby on Rails, but "coming" from a Java background I find it odd to have lots of stuff in the models instead of using utility classes or services.
Re: Ways to Decompose Fat ActiveRecord Models
#5When doing a small, limited-use project, it seems often that trying to follow "best practices" like avoiding fat models would be more trouble than it's worth. And yet I've worked on larger enterprise-scale projects that have most certainly benefited from following this and other practices.
Anyone know of any research or work on where the tipping point is for following increasingly complicated patterns and practices?
Re: Ways to Decompose Fat ActiveRecord Models
#6Firstly, that doesn't look like the strategy pattern to me, isn't it back to front? And even if it were, what the hell are you doing? You do not pass the user to the authenticator, you'd pass the authenticator to the user constructor.
The way you've chosen is very brittle, it's a sure fire way to accidentally shoot yourself in the foot later on when someone accidentally deletes the authenticator or adds a new code path that doesn't contain one.
I also don't understand why you're creating a new class per object query? Ditto for the policy stuff. Why not just use a repository object if you don't want to clutter your main class. Like OrderRepository.GetByCompany(Id).
As for point 7, I don't understand why you're not completely extracting the facebook integration from the comment class. Does Ruby not have events? Why aren't you firing an event that the facebook integrator that initialized on the user object subscribed to? i.e. make a facebook integrator that registers itself on the user object creation.
Also, "View Model" not "View Object", that's what they're called, a lot of other frameworks already use them.
Re: Ways to Decompose Fat ActiveRecord Models
#7Is this a case of fixing the wrong problem?
Re: Ways to Decompose Fat ActiveRecord Models
#8This is more of a theoretical question, but at what point does a project become large enough that concerns like this begin to truly matter? When doing a small, limited-use project, it seems often that trying to follow "best practices" like avoiding fat models would be more trouble than it's worth. And yet I've worked on larger enterprise-scale projects that have most certainly benefited from following this and other…
It's important to have a meta-awareness while programming - how firm is your grasp on the code? How confident are you that your changes will do what you expect? At some point, you feel that grasp slipping, and then it's time to refactor.
Re: Ways to Decompose Fat ActiveRecord Models
#9Perhaps it's my lack of training or the projects I work on, but I've never seen a Rails model so large/cumbersome as to justify even one of these techniques. Is this a case of fixing the wrong problem?
Re: Ways to Decompose Fat ActiveRecord Models
#10I like Ruby on Rails, but "coming" from a Java background I find it odd to have lots of stuff in the models instead of using utility classes or services.
Coming from a java background to rails I found it entirely refreshing that everything wasn't in a utility class or service. Decomposition of a system using utility classes and services(in the n-tier style) is to make your system more procedural rather than more OO. This article is encouraging more OO patterns, closer in spirit to DDD. The article doesn't actually go into this but all of the techniques described can b…