CodeIgniter Forums
Which method you prefer?fat model or thin model? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: Which method you prefer?fat model or thin model? (/showthread.php?tid=63390)

Pages: 1 2


Which method you prefer?fat model or thin model? - arma7x - 10-25-2015

I'm have change my coding style from fat controller to thin controller & fat model in my latest project. It's really helps me reduce from repeating during same works. How you done your work using CI & which method you prefer?


RE: Which method you prefer?fat model or thin model? - PaulD - 10-25-2015

My next project with CI will be done with truly anorexic controllers, a business logic model layer, a database model layer, and views that are (fingers crossed) free from php other than minimal echoing and simple loops. That is the plan.


RE: Which method you prefer?fat model or thin model? - ignitedcms - 10-25-2015

Definitely fat models, although I realise this practise is not set in stone.

When you've got a lot of business logic in your controllers although it helps because you don't have to keep switching to different php files it actually makes it more easier for bugs to creep in.

Let's say you have two controllers which do the same thing, you would have to make sure any business logic in each controller is identical. If you move all the business logic into the model you only have one place to look for potential bugs.

This may not seem like much on small apps but when you start using 10's if not 100's of controllers you soon realise the benefit.


RE: Which method you prefer?fat model or thin model? - dmyers - 10-26-2015

I prefer, thin controllers & fat models with business logic in libraries since they tend to need to work with 1 or more models at a time and it makes the code more reusable in multiple controllers and/or other libraries.

DMyers


RE: Which method you prefer?fat model or thin model? - mwhitney - 10-27-2015

If a fat model is causing duplication of work/code, it would probably be worth splitting it up into multiple models and/or a library to reduce the duplication. I can't really think of a situation in which moving any of the code into controllers would improve code reuse.


RE: Which method you prefer?fat model or thin model? - skunkbad - 10-27-2015

I don't think it matters. I've done both and tend to have leaner controllers than I used to. Unless your working with a team or on a really large project, the end result will be the same.


RE: Which method you prefer?fat model or thin model? - ivantcholakov - 10-28-2015

For a request: A thin controller; and a bunch of thin models, probably with hierarchy.
Edit: And if you use HMVC, as a generalized result a request will be served by several thin controllers and several thin models.


RE: Which method you prefer?fat model or thin model? - includebeer - 10-30-2015

Duplication of code is really bad practice. Even if it's only 5 line of code. In all my projects I use a base controller class and a base model class that every controllers and models extends. Everything needed by more than one controller or one model goes in there.


RE: Which method you prefer?fat model or thin model? - solidcodes - 11-01-2015

@includebeer

yup I do the same.


RE: Which method you prefer?fat model or thin model? - marcopl - 11-26-2016

(10-30-2015, 08:59 PM)includebeer Wrote: Duplication of code is really bad practice. Even if it's only 5 line of code. In all my projects I use a base controller class and a base model class that every controllers and models extends. Everything needed by more than one controller or one model goes in there.

Good approach ...