Tuesday, March 01, 2005

Algorithms, Patterns and Duties

An Algorithm is a concise definition of how a piece of work is to be performed.

The term Pattern is a currently popular way to describe commonly-occuring algorithms in a generalized fashion that can be easily adapted to any problem the pattern is suited to solve. It is an algorithm abstracted almost to the point of being a meta-algorithm.

A Duty is the complement to a Pattern. It describes a problem or piece of work in terms of what is to be accomplished rather than how it should be done. A Duty can be implemented by any number of patterns whose outcome, when applied to the case at hand, is equivalent. Likewise, Patterns can be thought of as being an organized set of duties and the algorithmic relationships between them.

As an example that illustrates these two concepts, consider the list pattern: In the list pattern, one of the things that must be done is that the list of elements must be traversed. Exactly how it is traversed is not important to the definition of what a list pattern is and does; only that some portion of the pattern is responsible for having traversal occur on demand. List traversal is a duty. Since there are any number of ways list traversal can be implemented, the traversal pattern or algorithm that is used to actually implement the traversal duty can be considered separately according to additional criteria without impacting the contractual behavior of the list pattern.

Why is this interesting? Because with this distinction, we take another step towards uniform composability of patterns as problem-solving tools. We can weigh alternate algorithms which are isomorphisms of a particular duty, choosing the best fit for a particular application based on comparison of criteria.

No comments: