Origami Book
Origami Book
Origami Book
1. Introduction
Over the last thirty years, program modularity has been
dominated by object-orientation (OO): method, class, and
package encapsulations are standard concepts. Over this
same period, another form of program modularity has
arisen. The concept is feature refinement that is, a module that encapsulates the implementation of a feature,
which is a product characteristic that customers view as
important in describing and distinguishing programs
within a family of related programs (e.g., a product-line)
[15].
Feature refinement is a very general concept and many
different implementations of it have been proposed, each
with different names, capabilities, and limitations: layers
[2], features [18], collaborations [25, 35, 21], subjects
classes
c3
c2
r1
layers r2
r3
Figure 1. Classes and Refinements (Layers)
layers
r3
r2
f1
facets
f2
f3
Figure 2. Facets
2. A Motivating Problem
An Integrated Development Environment (IDE) is a suite
of applications (i.e., a product-family) that allow users to
write, debug, visualize, and document programs. Among
the programs, here called tools, of an IDE are a compiler,
debugger, editor, formatter, and document generator (e.g,
Javadoc). Figure 3a depicts some of these tools, each of
which is implemented in a different package.
The problem we consider is generating IDE tools that all
work on the same language dialect or Domain-Specific
Language (DSL). The use of DSLs have shown benefits in
terms of understandability, maintainability, and extensibility in software design and development processes [11].
Providing IDE tools to support DSL program compilation,
editing, debugging, and document generation is essential
(a)
compiler debugger
document
(b)
compiler
document
debugger
Java
Sm
Tmpl
Figure 3. IDE Tools and Cross-Cutting
Language Features
for the successful adoption of DSL technology. In particular, our work focuses on dialects of Java.
An example of a Java dialect is the one we are using to
write fire-support simulators for the U.S. Army [6]. As a
brief summary, fire support programs are a set of collaborating state machines. Figure 4a depicts a state machine of
three states (s1, s2, s3) and three edges (e1, e2, e3),
where an edge denotes a transition from one state to
another. For example, edge e3 begins at state s1 and ends
at state s3. Wide spectrum languages, like Java, are typically used to implement state machines. The resulting
code, even when using the state machine design pattern
[14], is often ugly, involving nested switch statements,
large numbers of methods or classes. This places a burden
on maintenance engineers because they must re-engineer
the simple abstractions of state machines (e.g., Figure 4a)
from the code in order to understand and modify it. In contrast, Figure 4b shows the specification of Figure 4a in our
extended Java language. Highlighted are state declarations
and edge declarations. We have found that state-machineextended Java programs are about half the size of their
pure-Java counterparts, and this in turn simplifies the writing, maintenance, and understanding of domain-specific
programs. Similar benefits accrue when other extensions,
such as templates, are added to Java.
In the future, we expect to work in other domains, each
requiring their own specific extensions to Java. This
means that we need to be able to construct IDE tools targeted for a particular Java dialect, or more generally, we
need to define a product-line for a product-family of IDE
tools. The novelty of our work is that we are using refinements (layers) as the unit of modularity.
Figure 3b revisits our IDE tools, but this time we expose
the layers from which they were constructed. One layer,
Java, encapsulates a cross-cut of the compiler, debugger,
and document generation packages that is specific to the
Java language. A second layer, Sm, encapsulates another
cross-cut of these tools; the encapsulated code fragments
(a)
s1
e1
s2
e2
e3
s3
(b)
state_machine example {
event_delivery receive_message(M m);
no_transition { error( -1, m ); }
otherwise_default { ignore_msg(m); }
states
edge e1 : s1 -> s2
conditions !booltest() do
{ /* e1 action */ }
edges
edge e2 : s2 -> s3
conditions booltest() do
{ /* e2 action */ }
edge e3 : s1 -> s3
conditions true do
{ /* e3 action */ }
// Java class data members and
// methods from here
boolean booltest() { ... }
example() { current_state = start; }
}
3. GenVoca
GenVoca is a design methodology for creating productlines and building architecturally-extensible software
k1(x)
k2(x)
//
//
//
//
resulting in two classes being extended. In general, a forest of inheritance hierarchies is created as layers are composed, and this forest grows progressively broader and
deeper as the number of layers increase [4].
i
ai
aj
bi
ci
di
cj
dj
ck
dk
ej
Extended-Java
Program
Pure-Java
Program
Jak
Extended-Java
Parse Tree
Parse
Reduce
Pure-Java
Parse Tree
(2)
(3)
tomized to a particular language dialect. Another is a Javadoc-like tool that harvests comments from specific
program constructs and displays them neatly on HTML
pages. Obviously, Sun Microsystems Javadoc [17] cant
be used directly, as it only understands pure-Java programs (and documenting generated pure-Java programs
typically isnt all that useful). So we created a language
extensible version of Javadoc called Jedi (Java Extensible
DocumentatIon). Jedi, like Jak, is produced by JTS
using a GenVoca model, called D. The lone constant is
JavaDoc, which encapsulates the code that parsers, harvests, and documents comments in pure-Java programs.
Functions of this model extend JavaDoc with the capabil-
HTML
Page
Jedi
Extended-Java
Parse Tree
Harvest
(6)
Extended-Java
Program
Parse
(5)
Comment
Repository
Doclet
5. Gluons
Language features are orthogonal to tool features. This
means that we can understand the modularity of Jak and
Jedi in terms of matrices, where rows correspond to language features and columns correspond to tool features.
(7)
Each IDE tool has an equation. The equations for Jak and
Jedi are given below:
Jak
(8)
(9)
Doclet
(a)
Tmpl
Java
Reduce
Jprint
Jreduce
Parse
Jparse
Sm
Sreduce
Sparse
Tmpl
Treduce
Tparse
Reduce
n.reduce();
Reduce
n.print();
Print
}
(b)
Parse
Sm
The matrix for Jak is shown in Figure 11, and has a similar
interpretation. There is a difference: there are no Sm and
Tmpl row entries for the Print column. The reason is
simple: consider the interpretation of Sreduce: it is a
module that transforms parse trees on state machines into
parse trees of pure Java. The Jprint module prints parse
trees of pure Java. So once the Sreduce module performs
its task, the Jprint module is invoked. Thus there is no
need for a module that prints state machine parse trees.
The same argument applies for templates. Once again, a
composition of these modules implements the Jak tool.
Main
Parse
parser treeNode
classes classes
Harvest
Java
Java
Sm
Tmpl
Ds
...
Doclet
Jdoclet
Sdoclet
Tdoclet
Ddoclet
...
Harvest
Jharvest
Sharvest
Tharvest
Dharvest
...
Parse
Jparse
Sparse
Tparse
Dparse
...
(10)
(11)
Reduce
Jreduce
Sreduce
Treduce
Dreduce
...
Print
Jprint
...
...
...
...
...
...
...
Doclet
Jdoclet
Sdoclet
Tdoclet
(c)
Doclet
Sm o Sdoclet o
Java
Jdoclet
Tmpl
Tdoclet
Harvest
Jharvest
Sharvest
Tharvest
7. An Application of Origami
Recall the GUI for the IDE generator of Figure 5: users
select a set of optional language features and a set of tools,
and the generator produces this set of tools for the speci5. In effect, gluons make our model more powerful without additional
complexity as the existing row and column rules can be used without
modification.
(b)
Doclet
Harvest
Sm o Java Sdoclet o Sharvest o
Jdoclet
Jharvest
Tmpl
Tdoclet
Tharvest
Parse
Jparse
Sparse
Tparse
Harvest o
Parse
Sharvest o
Jharvest o
Sparse o
Jparse
Tharvest o
Tparse
Java row, and then fold the Sm row and Tmpl rows in any
order, as prescribed by the language feature models J and
D. The reason for this is that language features and tool
(d)
Sm o
Java
Tmpl
Doclet o
Harvest o
Parse
Sdoclet o
Jdoclet o
Sharvest o
Jharvest o
Sparse o
Jparse
Tdoclet o
Tharvest o
Tparse
(e)
Tmpl o
Sm o
Java
Parse
Sparse o
Jparse
Tparse
Doclet o
Harvest o
Parse
Tdoclet o
Tharvest o
Tparse o
Sdoclet o
Jdoclet o
Sharvest o
Jharvest o
Sparse o
Jparse
Tool
Jak
Jedi
Mixin
JamPack
UnMixin
8. Implementation
We currently have five tools that are language-dialect sensitive: Jedi, Jak, Mixin and Jampack (two different
Java
Sm
Tmpl
Doclet
Jdoclet
Sdoclet
Tdoclet
Harvest
Jharvest
Sharvest
Tharvest
Parse
Jparse
Sparse
Tparse
Reduce
Jreduce
Sreduce
Treduce
Print
Jprint
-
...
...
...
...
Parse
Tparse o
Sparse o
Jparse
Reduce
Treduce o
Sreduce o
Jreduce
Print
Jprint
...
...
11. Conclusions
Features have proven their value in raising the level of
abstraction in modularity in building and customizing
individual programs. The question is: do features scale to
larger program organizations, such as program families?
We showed that they do in the context of GenVoca generators, which has not been done before. We discovered that
features themselves have internal structures features of
features which we called gluons. Gluons are arranged
and composed in very regular ways, so that compositions
of gluons yields both familiar and formerly atomic features, as well as an interesting and what we now believe is
a common phenomena of facets. Facets cross-cut features
and compositions of them yield fully-formed features. In
essence, we have identified a new class of composition
relationships among features that were not previously
known.
There is anecdotal evidence that supports our work. Engineers have repeated the observation that there is something about program scale that introduces complexity one
doesnt find in small programs. Our work reveals one reason: there are relationships and constraints that exist
among gluons when building program families. If there is
no way (or only ad hoc ways) of expressing and satisfying
these constraints, it is no wonder why scaling programs
introduces complexity. At least now we have a way to
express and reason about such constraints. Undoubtedly
there are even more relationships to be discovered.
The key to our success is how we represent and manipulate these relationships. Using GenVoca formulations
allows us to capture these regularity relationships as matrices of functions and constants that can be folded into
equations. That is, we can reason about software designs
as equations. We explained that our results are not GenVoca-specific, in particular, how Origami has direct relationships to AOP and MDSC models. We believe Origami
is important, because others will encounter it as feature
refinement models scale to produce more complex systems.
Acknowledgements. We thank Jack Sarvela for pointing
out the relationship of Origami to internationalization customizations of Windows programs. We also thank anonymous referees for helping us to better clarify our
presentation.
12. References
[1] AspectJ. Programming Guide. http://aspectj.org/doc/
proguide