Current Version:
0.67
|
Pattern Brewery
|
|
The pattern language definition
is based on the following assumptions:
- The pattern definition is created by a human.
- The definition is consumed by a computer or by
a human.
- The definition is derived from existing program code.
Goals
The goals of the pattern language
definition are:
- It must be easy for a user to create a pattern definition
from existing program code. The whole idea of the Pattern Brewery
is based on the assumption that you find patterns while writing (and
reading!) program code. The existing program code that a user has
identified to be one of the patterns in her/his problem domain should
be the base to create a pattern definition with as little modifications
as possible.
- The pattern language definition takes into account that one
of the must important issues about patterns is a proper documentation.
The documentation serves two main purposes:
- It helps the consumer of a pattern to select the
correct pattern to solve her/his problem.
- It tells the consumer of a pattern how to combine the
pattern with the existing code.
Again, it should be very easy for the person making the pattern to
derive the documentation of new pattern from already existing stuff
that documents the existing code like:
- UML diagrams
- Textual descriptions
- Drawings
- The pattern language must be readable by a computer.
A computer
program should be able to show the user the a list of available
patterns. It should also be able to display information about a pattern
so that a user is able to decide which of the patterns matches her/his
problem best. A computer program should also be able to generate
code from the pattern. The code should be "ready-to-use". Depending on
the type of pattern, this may require to parameterize the pattern (like
class names...).
The pattern description must allow a program to generate code for
different programming languages.
Overview
The following figure gives an overview of the
pattern definition language.

The XML Description file
serves as a kind of root, holding the pieces of the pattern description
together. It contains information about the pattern like:
- The name of the pattern like "Session Bean".
- A grouping information like "EJB Stuff".
- Information how the pattern can be
parameterized.
- The location of the code files, the help file and the
preview file.
The XML scheme of the description file can be found here.
The Code Files are containing
the parameterized implementation of the pattern in a specific
programming language. A pattern can consist of one or more code files
for each implementation of a pattern. The parameterization of the code
file works using a macro language. In the most simple case, your are
just some text strings like class names:
Original
Code
|
Parameterized
Code
|
public class
MMSingleton{
// Create
instance using device Id
public MMSingleton(int Id){
...
}
// Create instance using device name
public MMSingleton(String Name){
...
}
}
|
public class $classname{
// Create
instance using device Id
public $classname(int Id){
...
}
// Create instance using device name
public $classname(String Name){
...
}
} |
The selected macro language is language defined by the Velocity template engine. It
supports everything you to parameterize a code file including
- If-then-else statements
- Includes
- foreach loops
- Macros
- ...
The Help File is a HTML file
containing the description of the pattern with (hopefully) all the
details a consumer of the pattern needs to parameterize the
pattern correctly and to include it into her/his own code.
The Preview file is HTML of an
image file used to give the user of the pattern library a quick
overview about what a pattern is good for. In addition to the name of
the pattern, this overview shall help the user of the pattern library
to select the correct pattern to solve her/his problem best.
|