Grouping up functions for controllers and models. |
(10-22-2019, 05:04 PM)daveĀ friend Wrote: 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.) What i meant by a big pile of mess is that a single php file(controller/model) having too many functions that are for different specific purposes. I'll just give out a practical example. I'm developing an website for story sharing online. An example would be www.royalroadl.com where users can browse and read stories at the same time they can also upload their own so there's really no technical difference between a reader and an author. Anyway, i have a story controller. I have all functions inside them that are related to my story like for publishing a new story, reading a story, bookmarking a story, liking a story, adding a new chapter to a story, i have a function that tracks which chapter a user has last read - last read function(chapter), BASIC CRUD functions. Anyways, as stated above in my story controller, as much as possible i would like to separate the story functions from the chapter functions. So in short, i want to divide my current story controller into two - story and chapter controller wherein each controller handles their corresponding functions(story and chapter), so basic crud function for story would go into the story controller and basic crud functions for chapters would go into chapter controller. I also forgot to mention that i still would have to divide the functions from private and public ones, private ones for those functions that require credentials(logged on user - creating a new story, adding a chapter[user must be author of said story], etc.) and public ones for not(like browsing, reading a story, etc.). Is what i'm asking for logical in this sense? All in all, what i want is a clean project regardless of how many files it has wherein i just have to read their file names and function names for each file and i would already have a grasp of my project. In essence, i basically just want to organize my project so it is readable. In light of this, i also avoid writing shorthand codes, i prefer the long ones like an if statement i would write out the whole if statement code or if using php in my html i would write the whole php code like <?php echo $name; ?> instead of <?=$name;?> This is because i have other projects that i completely abandoned because i couldn't get into them after i stopped for awhile and have a look at my project that is messy(in my opinion) that i would rather restart the whole thing from the groundup than to continue them. I would like to avoid the above situation. I gave it some thought. Although chapters are part of the story, if i think about it. A story is a class of its own with its own attributes. While a chapter is a part of the story, it can also be a class of its own with its own attribute right?( i just remembered my OOP classes with parent class and child classes with inheritance, but this is Codeigniter, so i don't really have to do inheritance and what not, i can just create a different class(controller) for chapters right? |
Messages In This Thread |
Grouping up functions for controllers and models. - by dweenator - 10-22-2019, 01:46 PM
RE: Grouping up functions for controllers and models. - by dave friend - 10-22-2019, 05:04 PM
RE: Grouping up functions for controllers and models. - by dweenator - 10-23-2019, 11:37 PM
RE: Grouping up functions for controllers and models. - by PaulD - 10-24-2019, 04:10 AM
RE: Grouping up functions for controllers and models. - by dweenator - 10-24-2019, 04:46 AM
RE: Grouping up functions for controllers and models. - by PaulD - 10-24-2019, 06:18 AM
|