Feature-oriented programming
In computer programming, feature-oriented programming or feature-oriented software development is a programming paradigm for program generation in software product lines and for incremental development of programs.
History
FOSD arose out of layer-based designs and levels of abstraction in network protocols and extensible database systems in the late-1980s. A program was a stack of layers. Each layer added functionality to previously composed layers and different compositions of layers produced different programs. Not surprisingly, there was a need for a compact language to express such designs. Elementary algebra fit the bill: each layer was a function that added new code to an existing program to produce a new program, and a program's design was modeled by an expression, i.e., a composition of transformations. The figure to the left illustrates the stacking of layers i, j, and h. The algebraic notations i, i•j•h, and i+j+h have been used to express these designs.Over time, layers were equated to features, where a feature is an increment in program functionality. The paradigm for program design and generation was recognized to be an outgrowth of relational query optimization, where query evaluation programs were defined as relational algebra expressions, and query optimization was expression optimization. A software product line is a family of programs where each program is defined by a unique composition of features. FOSD has since evolved into the study of feature modularity, tools, analyses, and design techniques to support feature-based program generation.
The second generation of FOSD research was on feature interactions, which originated in telecommunications.
Later, the term feature-oriented programming was coined; this work exposed interactions between layers. Interactions require features to be adapted when composed with other features.
A third generation of research focussed on the fact that every program has multiple representations and adding a feature to a program should elaborate each of its representations so that all are consistent. Additionally, some of representations could be generated from others. In the sections below, the mathematics of the three most recent generations of FOSD, namely GenVoca, [|AHEAD], and [|FOMDD] are
described, and links to product lines that have been developed using FOSD tools are provided.
Also, four additional results that apply to all generations of FOSD are: FOSD metamodels, FOSD program cubes, and FOSD feature interactions.
GenVoca
GenVoca is a compositional paradigm for defining programs of product lines. Base programs are 0-ary functions or transformations called values:f -- base program with feature f
h -- base program with feature h
and features are unary functions/transformations that elaborate a program:
i + x -- adds feature i to program x
j + x -- adds feature j to program x
where + denotes function composition. The design of a program is a named expression, e.g.:
p1 = j + f -- program p1 has features j and f
p2 = j + h -- program p2 has features j and h
p3 = i + j + h -- program p3 has features i, j, and h
A GenVoca model of a domain or software product line is a collection of base programs and features.
The programs that can be created defines a product line. Expression optimization is program design optimization, and expression evaluation is program generation.
GenVoca features were originally implemented using C preprocessor techniques. A more advanced technique, called mixin layers, showed the connection of features to object-oriented collaboration-based designs.
AHEAD
Algebraic Hierarchical Equations for Application Design generalized GenVoca in two ways. First it revealed the internal structure of GenVoca values as tuples. Every program has multiple representations, such as source, documentation, bytecode, and makefiles. A GenVoca value is a tuple of program representations. In a product line of parsers, for example, a base parser f is defined by its grammar gf, Java source sf, and documentation df. Parser f is modeled by the tuple f=. Each program representation may have subrepresentations, and they too may have subrepresentations, recursively. In general, a GenVoca value is a tuple of nested tuples that define a hierarchy of representations for a particular program.Example. Suppose terminal representations are files. In AHEAD, grammar gf corresponds to a single BNF file, source sf corresponds to a tuple of Java files , and documentation df is a tuple of HTML files . A GenVoca value can be depicted as a directed graph: the graph for parser f is shown in the figure to the right. Arrows denote projections, i.e., mappings from a tuple to one of its components. AHEAD implements tuples as file directories, so f is a directory containing file gf and subdirectories sf and df. Similarly, directory sf contains files c1…cn, and directory df contains files h1…hk.
Second, AHEAD expresses features as nested tuples of unary functions called deltas. Deltas can be program refinements, extensions,
or interactions. We use the neutral term “delta” to represent all of these possibilities, as each occurs in FOSD.
To illustrate, suppose feature j extends a grammar by gj, extends source code by sj, and extends documentation by dj. The tuple of deltas for feature j is modeled by j=, which we call a delta tuple. Elements of delta tuples can themselves be delta tuples. Example: sj represents the changes that are made to each class in sf by feature j, i.e., sj=.
The representations of a program are computed recursively by nested vector addition. The representations for parser p2 are:
p2 = j + f -- GenVoca expression
= + -- substitution
= -- compose tuples element-wise
That is, the grammar of p2 is the base grammar composed with its extension, the source of p2 is the base source composed with its extension, and so on. As elements of delta tuples can themselves be delta tuples, composition recurses, e.g., sj+sf=
+=.
Summarizing, GenVoca values are nested tuples of program artifacts, and features are nested delta tuples, where + recursively composes them by vector addition. This is the essence of AHEAD.
The ideas presented above concretely expose two FOSD principles. The Principle of Uniformity states that all program artifacts are treated and modified in the same way.. The Principle of Scalability states all levels of abstractions are treated uniformly. .
The original implementation of AHEAD is the AHEAD Tool Suite and Jak language, which exhibits both the Principles of Uniformity and Scalability. Next-generation tools include CIDE
and FeatureHouse.
FOMDD
Feature-Oriented Model-Driven Design combines the ideas of AHEAD with Model-Driven Design . AHEAD functions capture the lockstep update of program artifacts when a feature is added to a program. But there are other functional relationships among program artifacts that express derivations. For example, the relationship between a grammar gf and its parser source sf is defined by a compiler-compiler tool, e.g., javacc. Similarly, the relationship between Java source sf and its bytecode bf is defined by the javac compiler. A commuting diagram expresses these relationships. Objects are program representations, downward arrows are derivations, and horizontal arrows are deltas. The figure to the right shows the commuting diagram for program p3 = i+j+h = .A fundamental property of a commuting diagram is that all paths between two objects are equivalent. For example, one way to derive the bytecode b3 of parser p3 from
grammar gh of parser h is to derive the bytecode bh and refine to b3, while another way refines gh to g3, and then derive b3, where + represents delta composition and is function or tool application:
b3 = bj + bi + javacc = javac
There are possible paths to derive the bytecode b3 of parser p3 from the grammar gh of parser h. Each path represents a metaprogram whose execution generates the target object from the starting object.
There is a potential optimization: traversing each arrow of a commuting diagram has a cost. The cheapest path between two objects in a commuting diagram is a geodesic, which represents the most efficient metaprogram that produces the target object from a given object.
Commuting diagrams are important for at least two reasons: there is the possibility of optimizing the generation of artifacts and they specify different ways of constructing a target object from a starting object. A path through a diagram corresponds to a tool chain: for an FOMDD model to be consistent, it should be proven that all tool chains that map one object to another in fact yield equivalent results. If this is not the case, then either there is a bug in one or more of the tools or the FOMDD model is wrong.