Did I do something wrong in my code organization ? I still find my own program difficult to follow. I tried to decompose my program on small, easy to understand classes and functions, still I find myself jumping around to follow action process.
I can't post my entire project here, so here is a sample of a process. My code is a nodejs app, using an M (model) C (controller) T (template) organization. Those are specific to the project, and I have a 4th section of "utilities" classes and functions that I reuse from project to project.
The project is a web directory where user can post links. Here is the process with all intervening actors of a user post:
- Controller post handler: gets the post request.
- Controller post handler: form.parse is executed to get field inputs
- Model validationResult function: instantiate model
- Model Validation Error: receives the instance, calls for StringValidation in utility file, and return validation errors or confirmation to move on if there are no errors.
- Model validationResult function: gets back the result from 4). If there are no error, returns this info to the controller
- Controller : slugifies the title from an utility file, then create entry by calling a database utility from the utility directory.
- Redirects.
So for creating an entry, lots of methods spread out in controller, model and utilities are used. When I must fix a problem or add a feature, I must track back and reunderstand the whole process between 3 files and probably twice methods and classes.
I'm a bit stuck here: I tried to create a modular architecture of small, legible and reusable parts, but I'm not sure I created something easier to maintain that a huge linear structure.
How would you have organized this structure ? If decomposing a program into small, reusable and single purpose components is what we should do as most books advocates, we inherently must jump from methods to classes and I don't see how this makes the process any easier.