‚Üź Back to Upcase

Ways to break up a class?

(George Ulmer) #1

I have a user class with High total complexity. What are some good ways of breaking it up?

(Jason Draper) #2

It is hard to answer that kind of question without seeing the code directly.

That is a great blog post on the most obvious ways to clean up models. When it comes to the user model be extra proactive about ripping out anything that is not directly related to saving the user model. Try to extract away everything you can into something that is more appropriate for the behavior.

(Noah Clark) #3

Can you identify things that the user might be masking? For example, does your user have an address, contact info, or profile? Could you pull that out?

Does your user do things that can be pulled out? For example, are there long methods that build up something or make requests or tell other objects what to do? Is there a user merger function or some other user admin functionality that could be pulled out?

Does your user do a bunch of stuff for the view? Could that be pulled out?

(George Ulmer) #4

This is very helpful. Thank you!

BTW, I got the smell from Code Climate.