As in the world of mobile and embedded aggressive changes in technology and devices’ capabilities occur at a high frequency, I decided to make Tinymail‘s API very flexible or adaptive.
Yet I wanted to provide a certain functionality, which means a message view component that also shows the typical message headers.
What if the developer wants to wrap the message view in a scrolled window, have a message viewer as a new window or put the thing that displays the header in an expander? On a mobile device with a limited screen height it is a waste of space to show four or five lines of information. If the user wants this info, he can decide to expand it.
Imagine the same software vendor want to adjust the E-mail client for another device? However, nowadays software development must be fast. The change is something that should not destabilize everything that was already working. It must be easy to develop a new version of the message view component that perhaps behaves in a new way. Who knows what the screen will be capable of?
This diagram shows the flexibility of Tinymail‘s types. I’m using the decorator pattern here. Decorator is also used by the streams API of Java, .NET and GVFS. I explained Tinne about decorator by simply referring to a painting and its borders. When decorating a painting with borders, you can still look at the painting. Nothing about its functionality really changes, but you add things to it, you decorate it.
In stead of subclassing TnyGtkMsgView, I decided to decorate it with a new implementation of the TnyMsgView interface. This one wraps the TnyGtkMsgView instance (it makes a composition with it). I did the same thing for TnyGtkHeaderView that implements the TnyHeaderView interface.
Because TnyGtkMsgView‘s method for creating its TnyHeaderView is abstract, I inherited it as TMutTnyGtkMsgView (which will be the type that we’ll decorate). The TnyGtkHeaderView is decorated by TMutHeaderView. This TMutHeaderView is then created by the TMutTnyGtkMsgView.
TMutHeaderView decorates TnyGtkHeaderView by surrounding it with a GtkExpander. TMutMsgView decorates TnyGtkMsgView (TMutTnyGtkMsgView, actually) by surrounding it with a GtkScrolledWindow.