Managing big applications
Hey guys!
I have an application here that is growing bigger and bigger. The address is this: www.aquitanda.com [brazilian portuguese].
Basically, it's a website where you can buy and sell stuff on your own, which means people can create their own webstores.
I have, for this project, 4 big "interfaces". One of them is the commom interface, where anyone can browser, register as a user or as a store and so on. I have another interface where people manage their preferences, their profile and so on, this is the user interface. There is the store management interface, where people add products, categories, check out orders and so on. The last one is the interface of the stores.
This means that I have a lot of code that share same models and same controllers, but my controllers are getting huge and maintanence is getting harder and harder to make.
See, I have fat models. It's not because actions are getting to much code. It's just because I have a lot of actions.
So I moved my code into plugins, but that isn't feeling very "right" to me anymore as I want to use plugins for other stuff instead of interfaces actions.
Is there a suggestion in order to organize this any better? Should I just use prefixes and let my controllers huge? Should I stick with plugins [maybe with custom paths]? Will v.1.3 introduce anything new on this subject? Should I wait the stable version? Any other alternatives?
Thanks in advanced ;)
Asked by eberfreitas, on 23/11/09
1 Answer
Without knowing a lot more about your app, I can only offer tricks I like to use. Look at your code and try to follow DRY (Don't Repeat Yourself). If you find yourself with a large handful of actions in a single controller that do mostly the same thing consider making yourself a private method to slim down those controller actions, or use some routes magic to eliminate one all together. An example of the latter is merging edit and add together. The first thing I do when I make a new controller (almost always) is merge edit and add, they're practically identical and this makes it so I only have to deal with one view.
In 1.3 they're adding more prefixes to use. This may result in more controller actions, but they're much more specific to what you're trying to accomplish (which is what I prefer). I don't mind large controllers (lots of actions) if each one serves a unique and distinct purpose. As long as most of your logic is in the model (wherever possible) you're practicing good standards.
I don't know how helpful that was, but I hope it gave you something to think about,
Nick
Answered by webtechnickon 25/11/09
Agree with webtechnick on this one. I would also consider using Components to share functionality between controllers as well as the private methods in the controllers to share functionality within a controller.
If your IDE uses "markers" then I would suggest organizing your controller actions into specific marked grouping that your IDE can quickly jump to. I usually start out with a marker for /* !Public methods */, /* !Admin methods */, and /* !Private methods */ to help segment the controller and break it down from there (using Coda from Panic.com for my markers).
davidwu - on 29/12/09
Tagged with
Rating
4
Viewed
2293 times
Last Activity
on 29/12/09