Wednesday, February 8, 2012

Cross-platform problem solving: how an Android Pro Tip helps our web app design

Separation of concerns is a challenge in a web application. The quick, straightforward way to control a page winds up being messy, with business logic and application logic and view logic all mushed together.

Here at my Stealth-Mode Startup, we're using the Sitebricks web framework on top of Guice. One pain point in our webapps' code is that the Sitebricks Page objects wind up serving too many purposes. They control what's displayed to the user, what actions are taken on an HTTP request, and what data is available to the view. We grimace when we think too hard about them.

Last month at CodeMash, I saw a presentation by Michael Pardo on Android Pro Tips. Android's Activity objects have something in common with our Sitebricks Page objects: they control and populate the view as well as performing application tasks. One pattern Michael presented in the Android talk was the ViewHolder: an inner class inside the Activity takes responsibility for interacting with the view. The ViewHolder knows about the IDs of the particular components in the layout, isolating this from the rest of the activity.

We're going to try implementing this ViewHolder pattern in our web application. I love that a solution designed for one platform solves the same problem on another platform. Also, this shows how attending development conferences and learning about various technologies is relevant to my job in unexpected ways.

No comments:

Post a Comment