Summary
It is a simple idea requiring simple code but offering huge benefits.
View objects enable a programmer to build as many presentations of data as required without having to create and maintain multiple copies.
When writing a view class, remember the underlying behaviors of view objects:
- The view contains links to the underlying data, not copies of it
- Only the data that qualifies for the view can be accessed via the view
- The view can reference multiple underlying data containers
This article has described just one possible implementation of view objects, but there are others. A complete view class, using the techniques described in this article, is available for download and can be used in your own code. Alternatively, you can create your own. But whichever you use, views are a powerful programming tool that can be applied to solving a variety of problems from the large scale to the small scale.
In my experience I've found that wherever data is being manipulated or presented, view objects have something to offer.