Saturday, December 22, 2007

OO Technology and Reuse

One of the major benefits of OO technology, as claimed by its proponents, is that it enables reuse. Whenever we can reuse existing components for a product we potentially gain additional time which can then be used to address the novel aspects of our application, or simply deliver it earlier. But what is meant by reuse?

The most common kind of reuse is through libraries. The user of the library is presented with a black box and a description of its interface. One is supposed to be able to use the API (application programmers interface) without a deep understanding of the implementation details of the library. The various widget components in the foundation classes for a windowing system are examples of this kind of low level fine-grained reuse.

Another form of reuse concerns low level architectural details, that is at the level of algorithms and data structures. All of us are familiar with the generic description of an algorithm, like quick sort, which we then code in language chosen for the application. We all know about binary trees, and we do not have to re-invent them for every application. Design patterns are also an example of this level of reuse. There is still substantial scope for inventiveness in new patterns, or in adapting and combining existing patterns.

Software components are self-contained modules that can be connected together using some protocol, such as CORBA or DCOM. They are more than just an implementation, since the also reflect a design philosophy. Arbitrary components can be connected only if they share the same connection, communication, and control architecture.

The highest form of reuse occurs at the sweeping architecture level composed of many pieces plus a philosophy. Here we try to reuse good designs. This is potentially the most profitable kind of reuse because good designs are costly to develop. The current technique for high level design reuse is via application frameworks.

An application framework provides a generic design within a given domain, and a reusable implementation of that design. An object-oriented application framework presents its generic design and reusable implementation of a system through a set of classes and their collaborations. Applications are built from frameworks by extending or customizing parts of the framework, while retaining the original design. Frameworks solve larger grained problems then individual components, and this makes the effort of finding and reusing them more cost effective than for small components.

The notion of reuse even makes sense in terms of the features of a language. You can evaluate various features in terms of "what does this feature let me reuse in my programs?". For example, parameterizing a function (e.g. qsort) lets you reuse it in many contexts, inheritance lets you reuse the behaviour of your ancestor classes, templates let you reuse design.

We can locate the various kinds of reuse on a reuse plane, which reflects what is being reused and the granularity of the reuse. OO technologies start to pay off at medium to high levels of reuse --- which is exactly the granularity at which iterative and incremental development occurs.

No comments: