The app I'm developing needs to display lists of items. Simple enough, but there are a number of things which can change based on user input:
- Items can be added to/removed from the list.
- The items in the list can be updated. Multiple items can be updated simultaneously!
- The filters can be updated. Multiple filters can be updated simultaneously!
- The sort order of the items can change.
Possibly relevant info:
- It's a multiplatform Java app.
- One of the platforms we distribute on is MIDP, so that limits which language features/libraries/etc we can use.
- The implementation is currently split into a model class (in the common code) and device-specific view/controller classes.
I've tried a couple of approaches to designing a suitable list implementation, but both have drawbacks:
The platform-specific controller implementations are responsible for calling a
refresh() method whenever anything happens which could change the list.
This approach keeps the list class (model) implementation fairly straightforward, but leaves much of the responsibility up to the platform-specific controller implementations. The more logic there is in these classes, the greater the chance of bugs creeping in. It also encourages the controllers to directly notifying the view of updates, which feels like poor design.
The model is entirely responsible for raising events to notify the platform-specific views of changes. The list items, filter, and sorters notify the model when they change, which then notifies the views of changes.
This keeps the platform-specific classes much simpler, and feels like a stronger design (less coupling between the classes, etc). However, the list class implementation becomes much more complicated.
My main problem with this approach is dealing with a proliferation of events when multiple items/filters are updated in a single operation.
- Is there other approaches I could/should be trying?
- Is there a recognised way to manage/avoid the explosion of events in approach #2?