Use fat models.

Move your business logic down to your models.

Fat models are preferable to fat controllers. As part of the Model-View-Controller pattern, the View handles the user interface, the Controller routes traffic, and the Model contains the business objects. In the interests of keeping controllers simple, one should move business logic out of the controllers and into the models. So if you have to choose between a fat model and a fat controller, go for the fat model. Here, “fat” refers to the size of the class.

However, models don’t have to be large. In fact, it is preferable to have several thin models instead of one large model. By moving separate concerns to other classes, you can reduce the size of the models. Models can call other models.

Not all models need to be data access objects. Sometimes models only contain logic or work with intermediate objects that aren’t persisted in a database.

Some people prefer to keep the data access in a repository class, separate from the business logic, which slims down the models even more.

Ultimately, as things get separated out, the fat leaves the system.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: