Implementing Design Patterns as Declarative Code Generators

Kris De Volder

Department of Computer Science
The University of British Columbia
309-2366 Main Mall
Vancouver, B.C. V6T 1Z4

Abstract

The implementation of a design pattern typically cannot be reused. Consequently implementing design patterns is a tedious, repetitive and error-prone activity with ample opportunities to make the same mistakes over and over again.

We address this issue by automating design-pattern implementation by means of code generators which are defined as declarative logic meta programs generating Java code and are therefore called declarative code generators.

While a reusable code-generator is typically somewhat harder to implement than a single instance of a design pattern, it is worth the effort because:

  1. It avoids tedious and error prone copy-paste-edit implementation.
  2. The extra effort is not prohibitive because declarative code generation allows the code-generators to be implemented relatively easily.
  3. Declarative code generators combine naturally and thus allow for generation of combinations of design patterns.

(download)