1

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.

1 Answers1

4

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.

Mage Xy
  • 188
  • 11