I have a legacy code containing some behaviour classes, like services and controllers. My model is pretty anaemic. It's just a repository of getters and setters, and I want to refactor it. There is a thin line between Rich Model and God Class. I'm afraid to refactor my anaemic model into a god class.

I want some opinion about how many lines is acceptable into a model class, and how many methods should I use without separating.

I know it's a unique perception from project to project, but I want to know some global opinions.

  • @NikG You may want to make your comment into an answer – Dan Pichelman Oct 23 '15 at 15:47
  • @DanPichelman Sure thing, I've posted it now. – Mage Xy Oct 23 '15 at 16:03

Whether or not you have a god class has nothing to do with how many lines of code the class is, although that can certainly be used as an indication of a code smell of some sort.

A god class is one that does way too much (i.e., it has more than one main responsibility). If this is the case, it should be split into smaller classes which each have their own responsibility.

As an example, if you have a single class which handles a bunch of different things like file IO, business logic, and displaying a GUI, chances are it's a god class and needs to be refactored.

For more reading, see the Single Responsibility Principle or God Object.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.