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:
- Keeping the parsed path as an attribute in the controller.
- Additionally to the above I tried adding three more controller methods: 'action_name', 'action_args' and 'action_postfix'.
- 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:
- having the path as attribute is handy for code retrieving the record
- the additional controller methods help with writing custom dispatchers
- 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
- the the additional dispatcher methods are less useful for that more clean architecture
- 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
- overriding 'handle' is actually simpler - because it is a very simple method
No comments:
Post a Comment