Sunday, March 11, 2012

WebNano - code experiments

WebNano is only a few hundreds lines - but you can arrange it in many many ways - and then you need to test it with all kinds of URL schemas and controller architecture. I do a lot of exploratory coding - testing all the possible arrangements. I feel that I keep forgetting about the things that suggested me to choose one design over others. Maybe I'll keep some notes here. In the past two weeks I tried a few things:
  1. Keeping the parsed path as an attribute in the controller.
  2. Additionally to the above I tried adding three more controller methods: 'action_name', 'action_args' and 'action_postfix'.
  3. I wrote two additional test controllers for the simple url schema, both redirecting handling to DvdDatabase::Controller::Dvd::Record for the case where we have a record to handle: overriding local_dispatch, overriding handle
The conclusions:
  1. having the path as attribute is handy for code retrieving the record
  2. the additional controller methods help with writing custom dispatchers
  3. splitting the processing to two controllers - one for the case where you have one object to work on (like viewing, editing, deleting), second for the case where we don't (like listing, creating) is very clean - you can have the object as controller attribute
  4. the the additional dispatcher methods are less useful for that more clean architecture
  5. the biggest problem was always preventing the methods that require the object to be called when we don't have the record id on the path (like '/view' when we assume that it should be '/1/view') - and the best method to do that is having the two controller classes
  6. overriding 'handle' is actually simpler - because it is a very simple method

No comments: