Welcome Guest, Not a member yet? Register   Sign In
Grouping up functions for controllers and models.

(This post was last modified: 10-22-2019, 05:08 PM by dave friend.)

At each step of development, the question you need to ask at every turn is, "What is the main concern (purpose) for this class?". Where "class" and "file" are synonymous for our purposes here. In other words, we're talking about the concept called Separation of Concerns (SoC). (Also discussed here which also mentions the closely related topic of the Single Responsibility Principle.)

Using an MVC framework like CodeIgniter helps to maintain SoC to a certain degree. But, as you clearly understand, so does delegating responsibilities to the various pieces and parts. You cannot maintain SoC if you're trying to avoid a "big pile of mess" which I take to mean "a lot of files". The more focused any class is the easier it is to develop, test, use, and maintain. Tightly focused usually means lots of files. (It's not a bad thing - really!)

I tend to think of controllers as content displayed in the browser. IOW, almost every controller method generates output. So both users and products have at least one controller.

Models should be considered in terms of what data they handle and not which controller uses them. Any given model might be used by any number of controllers. There's no reason a controller cannot use more than one model. Come to think of it, there's no reason a model cannot use some other model. (Though that tends to indicate you sould use a common library.)

Speaking of which, don't forget about what CodeIgniter calls "libraries". These are just classes that are put in the /application/libraries/ folder. Many times a "library" will be the piece that provides logic needed by multiple controllers and/or models.

I'm not sure if any of the above fits into your concepts of "Purpose" or "Purpose+Target" but I hope it helps.

Messages In This Thread
RE: Grouping up functions for controllers and models. - by dave friend - 10-22-2019, 05:04 PM

Theme © iAndrew 2016 - Forum software by © MyBB