Daily ArchiveFriday, September 16th, 2005
Uncategorized 16 Sep 2005 08:09 am
Design of a Rails application
Over the summer I quickly developed an application to take registrations online (clubrs.org in the sidebar). It worked and now we’re between registration periods and I have a chance to step back and do some work at a little more leisurely pace.
Now I’m looking to do two things:
- implement incomplete functionality
- refactor some of the design
I’d like to start with the design refactor so that the new areas are developed using the new design patterns. One goal is to make the application configurable as I’m considering commercial applications. Each club that uses it will likely have different requirements in regard to registration, team building and game scheduling.
One area which has nagged at me from the start is where to put the various bits of business logic.
Initially I put quite a bit in the controller. For example, in the payment controller, there’s a method to check if a registration should be complimentary (for some volunteers).
As I went along I started moving more logic like that into the models, which is better. But that still is less configurable than I’d like.
Now what I’m considering is this:
Controller: only application flow
Model: only persistence and associations
Modules: add modules for major areas of functionality – Payments, Registrations, Team Building, Game Scheduling.
The view/view helpers would be used as normal.
I think the main change will be to move most business logic out into modules. This will let me swap out modules to change the configuration.
For example, now we are considering a whole different way to put the teams together. Currently we have a group of volunteers who take all the registered players and put them onto teams. It turns out to be very hard and we get a lot of complaints from parents (if a kid isn’t on a team with a friend, doesn’t get the right coach, etc).
So we’re considering letting the parents place the child on a team at registration time. I’m thinking that if the team building functionality is encapsulated in a module I can swap which one is mixed in to the controllers and substantially change the application, even at run time.
This particular example of team building may be particularly difficult to solve as it will likely impact the flow of the application as well as the logic.
I’ll update this thread as I go along with any lessons learned. Please add any comments if you’ve come across similar design decisions and what you may have learned.