Jump to content

Feature-oriented programming: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
MaD70 (talk | contribs)
m AHEAD: Deleted spurious tags that confounded the parser generating garbage as result.
change paradigms template to navbox (see Template talk:Programming paradigms#too long)
 
(75 intermediate revisions by 27 users not shown)
Line 1: Line 1:
{{primary sources|date=March 2018}}
{{Programming paradigms}}
In [[computer programming]], '''feature-oriented programming''' ('''FOP''') or '''feature-oriented software development''' ('''FOSD''') is a [[programming paradigm]] for program generation in [[software product lines]] (SPLs) and for incremental development of programs.


== History ==
'''''Feature Oriented Programming (FOP)''''' or '''''Feature Oriented Software Development (FOSD)''''' is a general paradigm for program synthesis in [[software product lines]].
[[File:StackingLayers.jpg|thumb|upright=0.4|right|alt=vertical stacking of layers|Connection between layer stacks and transformation compositions]]
FOSD arose out of layer-based designs and levels of abstraction in network protocols and extensible database systems in the late-1980s.<ref name="genvoca">{{cite web | title=Design and Implementation of Hierarchical Software Systems with Reusable Components | url=ftp://ftp.cs.utexas.edu/pub/predator/tosem-92.pdf}}</ref> 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 (a [[program transformation]]) 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 (layers). The figure to the left illustrates the stacking of layers i, j, and h (where h is on the bottom and i is on the top). The algebraic notations i(j(h)), 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.<ref name="selinger">{{cite book | title=Access Path Selection In Relational Databases | date=30 May 1979 | pages=23–34 | doi=10.1145/582095.582099 | isbn=9780897910019 | s2cid=8537523 | url=http://portal.acm.org/citation.cfm?id=582099}}</ref> 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.
[[Image:StackingLayers.jpg|thumb|Connection Between Layer Stacks and Transformation Compositions]]


The second generation of FOSD research was on feature interactions, which originated in telecommunications. Later, the term ''feature-oriented programming'' was coined;<ref name="FOP">{{cite web | title=Feature-Oriented Programming: A Fresh Look at Objects | url=http://www4.informatik.tu-muenchen.de/papers/ecoop_prehofer_1997_Publication.html | access-date=2015-12-16 | archive-url=https://web.archive.org/web/20030803215756/http://www4.informatik.tu-muenchen.de/papers/ecoop_prehofer_1997_Publication.html | archive-date=2003-08-03 | url-status=dead }}</ref> this work exposed interactions between layers. Interactions require features to be adapted when composed with other features.
FOSD arose out of layer-based designs and levels of abstraction in network protocols and extensible database systems in the late-1980s <ref name="genvoca">{{cite web | title=Design and Implementation of Hierarchical Software Systems with Reusable Components | url=ftp://ftp.cs.utexas.edu/pub/predator/tosem-92.pdf}}</ref>. 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 function (program transformation) 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 (layers). The figure to the right illustrates the stacking of layers h, j, and i (where h is on the bottom and i is on the top). The algebraic notations i(j(h))and i•j•h expressed these designs.


A third generation of research focussed on the fact that every program has multiple representations (e.g., source, makefiles, documentation, etc.) 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 (or derived) from others. In the sections below, the mathematics of the three most recent generations of FOSD, namely [[#GenVoca|GenVoca]],<ref name="genvoca"/> [[#AHEAD|AHEAD]],<ref name="ahead">{{cite web | title=Scaling Step-Wise Refinement | url=ftp://ftp.cs.utexas.edu/pub/predator/TSE-AHEAD.pdf}}</ref> and [[#FOMDD|FOMDD]]<ref name="fomdd"/><ref name="genmeta"/> 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.
Over time, the idea of layers was generalized to features, where a '''''feature''''' is an increment in program development or functionality. The paradigm for program design and synthesis was recognized to be a generalization of relational query optimization, where query evaluation programs were defined as relational algebra expressions, and query optimization was expression evaluation <ref name="selinger">{{cite web | title=Access Path Selection In Relational Databases | url=http://portal.acm.org/citation.cfm?id=582099}}</ref>.A '''''[[Software product lines|software product line]] (SPL)''''' is a family of programs where each program is defined by a unique composition of features, and no two programs have the same combination. FOSD has since evolved into the study of feature modularity, tools, analyses, and design techniques to support feature-based program synthesis.

Further advances in FOSD arose from recognizing the following facts: Every program has multiple representations (e.g., source, makefiles,
documentation, etc.) and adding a feature to a program should
elaborate each of its representations so that all representations are consistent. Additionally, some of these representations could be generated (or derived)
from other representations. In this article, the mathematics of the
three most recent generations of FOSD, namely [[#GenVoca|GenVoca]]<ref name="genvoca"/>, [[#AHEAD|AHEAD]]<ref name="ahead">{{cite web | title=Scaling Step-Wise Refinement | url=ftp://ftp.cs.utexas.edu/pub/predator/TSE-AHEAD.pdf}}</ref>, and [[#FOMDD|FOMDD]]<ref name="fomdd"/><ref name="genmeta"/>, 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 presented elsewhere:
[[FOSD metamodels|MetaModels]],
[[FOSD Program Cubes|Program Cubes]],
[[FOSD Feature Algebras|Feature Algebras]], and [[FOSD Feature Interactions|Feature Interactions]].


== GenVoca ==
== GenVoca ==
'''''GenVoca''''' (a meld of the names Genesis and Avoca)<ref name="genvoca"/> is a compositional paradigm for defining programs of a product lines. Base programs are 0-ary functions or transformations called '''''values''''':
'''GenVoca''' (a [[portmanteau]] of the names Genesis and Avoca)<ref name="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
f -- base program with feature f
h -- base program with feature h
h -- base program with feature h


and features are unary functions/transformations that elaborate (modify, extend, refine) a program:
and features are unary functions/transformations that elaborate (modify, extend, refine) a program:


i x -- adds feature i to program x
i + x -- adds feature i to program x
j x -- adds feature j 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.:
where + denotes function composition. The ''design'' of a program is a named expression, e.g.:


p<sub>1</sub> = j f -- program p<sub>1</sub> has features j and f
p<sub>1</sub> = j + f -- program p<sub>1</sub> has features j and f
p<sub>2</sub> = j h -- program p<sub>2</sub> has features j and h
p<sub>2</sub> = j + h -- program p<sub>2</sub> has features j and h
p<sub>3</sub> = i j h -- program p<sub>3</sub> has features i, j, and h
p<sub>3</sub> = i + j + h -- program p<sub>3</sub> has features i, j, and h


A '''''GenVoca model''''' of a domain or software product line is a collection of base programs and features (see [[FOSD metamodels|MetaModels]] and [[FOSD Program Cubes|Program Cubes]]).
A '''GenVoca model''' of a domain or software product line is a collection of base programs and features (see [[FOSD metamodels|MetaModels]] and [[FOSD program cubes|Program Cubes]]).
The programs (expressions) that can be created defines a product line. Expression optimization is ''program design optimization'', and expression evaluation is ''program synthesis''.
The programs (expressions) that can be created defines a product line. Expression optimization is ''program design optimization'', and expression evaluation is ''program generation''.


: Note: GenVoca is based on the stepwise development of programs: a process that emphasizes design simplicity and understandability, which are key to program comprehension and automated program construction. Consider program p<sub>3</sub> above: it begins with base program h, then feature j is added (read: the functionality of feature j is added to the codebase of h), and finally feature i is added (read: the functionality of feature i is added to the codebase of j•h).
: Note: GenVoca is based on the stepwise development of programs: a process that emphasizes design simplicity and understandability, which are key to program comprehension and automated program construction. Consider program p<sub>3</sub> above: it begins with base program h, then feature j is added (read: the functionality of feature j is added to the codebase of h), and finally feature i is added (read: the functionality of feature i is added to the codebase of j•h).
Line 44: Line 36:
: Note: not all combinations of features are meaningful. [[Feature Model|Feature models]] (which can be translated into propositional formulas) are graphical representations that define legal combinations of features.<ref name="splc">{{cite web | title=Feature Models, Grammars, and Propositional Formulas | url=ftp://ftp.cs.utexas.edu/pub/predator/splc05.pdf}}</ref>
: Note: not all combinations of features are meaningful. [[Feature Model|Feature models]] (which can be translated into propositional formulas) are graphical representations that define legal combinations of features.<ref name="splc">{{cite web | title=Feature Models, Grammars, and Propositional Formulas | url=ftp://ftp.cs.utexas.edu/pub/predator/splc05.pdf}}</ref>


: Note: A more recent formulation of GenVoca is '''''symmetric''''': there is only one base program, 0 (the empty program), and all features are unary functions. This suggests the interpretation that GenVoca composes program structures by '''''superposition''''', the idea that complex structures are composed by superimposing simpler structures.<ref name="amast08">{{cite web | title=An Algebra for Features and Feature Composition | url=http://www.infosun.fim.uni-passau.de/cl/publications/docs/AMAST2008.pdf}}</ref><ref name="symmetric">{{cite web | title=Superimposition: A Language-Independent Approach to Software Composition | url=http://www.infosun.fim.uni-passau.de/cl/publications/docs/SC2008.pdf}}</ref>. Yet another reformulation of GenVoca is as a [[monoid]]: a GenVoca model is a set of features with a composition operation (•); composition is associative and there is an identity element (namely 1, the identity function). Although all compositions are possible, not all are meaningful as mentioned above.
: Note: A more recent formulation of GenVoca is '''symmetric''': there is only one base program, 0 (the empty program), and all features are unary functions. This suggests the interpretation that GenVoca composes program structures by '''superposition''', the idea that complex structures are composed by superimposing simpler structures.<ref name="amast08">{{cite web | title=An Algebra for Features and Feature Composition | url=http://www.infosun.fim.uni-passau.de/cl/publications/docs/AMAST2008.pdf}}</ref><ref name="symmetric">{{cite web | title=Superimposition: A Language-Independent Approach to Software Composition | url=http://www.infosun.fim.uni-passau.de/cl/publications/docs/SC2008.pdf}}</ref> Yet another reformulation of GenVoca is as a [[monoid]]: a GenVoca model is a set of features with a composition operation (•); composition is associative and there is an identity element (namely 1, the identity function). Although all compositions are possible, not all are meaningful. That's the reason for [[Feature Model|feature models]].


GenVoca features were originally implemented using C preprocessor (<code>#ifdef feature ... #endif</code>) techniques. A more advanced technique, called [[FOSD Mixin Layers|mixin layers]], showed the connection of features to object-oriented collaboration-based designs.
GenVoca features were originally implemented using C preprocessor (<code>#ifdef feature ... #endif</code>) techniques. A more advanced technique, called [[FOSD Mixin Layers|mixin layers]], showed the connection of features to object-oriented collaboration-based designs.


== AHEAD ==
== AHEAD ==
'''Algebraic Hierarchical Equations for Application Design''' ('''AHEAD''')<ref name="ahead"/> 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 g<sub>f</sub>, Java source s<sub>f</sub>, and documentation d<sub>f</sub>. Parser f is modeled by the tuple f=[g<sub>f</sub>, s<sub>f</sub>, d<sub>f</sub>]. 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.


:: [[Image:Hierarchy.JPG|thumb|Hierarchical relationships among program artifacts]]
'''''Algebraic Hierarchical Equations for Application Design (AHEAD)''''' <ref name="ahead"/> 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 g<sub>f</sub>, Java source s<sub>f</sub>, and documentation d<sub>f</sub>. Program f is modeled by the tuple f=[g<sub>f</sub>, s<sub>f</sub>, d<sub>f</sub>]. 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 g<sub>f</sub> corresponds to a single BNF file, source s<sub>f</sub> corresponds to a tuple of Java files [c<sub>1</sub>…c<sub>n</sub>], and documentation d<sub>f</sub> is a tuple of HTML files [h<sub>1</sub>…h<sub>k</sub>]. A GenVoca value (nested tuples) 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 g<sub>f</sub> and subdirectories s<sub>f</sub> and d<sub>f</sub>. Similarly, directory s<sub>f</sub> contains files c<sub>1</sub>…c<sub>n</sub>, and directory df contains files h<sub>1</sub>…h<sub>k</sub>.


:: Note: Files can be hierarchically decomposed further. Each Java class can be decomposed into a tuple of members and other class declarations (e.g., initialization blocks, etc.). The important idea here is that the mathematics of AHEAD are recursive.
:: [[Image:Hierarchy.JPG|thumb|Hierarchical Relationships among Program Artifacts]] Example. Suppose terminal representations are files. In AHEAD, grammar g<sub>f</sub> corresponds to a single BNF file, source s<sub>f</sub> corresponds to a tuple of Java files [c<sub>1</sub>…c<sub>n</sub>], and documentation d<sub>f</sub> is a tuple of HTML files [h<sub>1</sub>…h<sub>k</sub>]. A GenVoca value (nested tuples) can be depicted as a directed graph: the graph for program 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 g<sub>f</sub> and subdirectories s<sub>f</sub> and d<sub>f</sub>. Similarly, directory s<sub>f</sub> contains files c<sub>1</sub>…c<sub>n</sub>, and directory df contains files h<sub>1</sub>…h<sub>k</sub>.


Second, AHEAD expresses features as nested tuples of unary functions called '''deltas'''. Deltas can be '''program refinements''' (semantics-preserving transformations), '''extensions''' (semantics-extending transformations),
:: Note: Files can be hierarchically decomposed further. Each Java class can be decomposed into a tuple of members and other class declarations (e.g., initialization blocks, etc.).
or '''interactions''' (semantics-altering transformations). 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 &Delta;g<sub>j</sub> (new rules and tokens are added), extends source code by &Delta;s<sub>j</sub> (new classes and members are added and existing methods are modified), and extends documentation by &Delta;d<sub>j</sub>. The tuple of deltas for feature j is modeled by j=[&Delta;g<sub>j</sub>,&Delta;s<sub>j</sub>,&Delta;d<sub>j</sub>], which we call a '''delta tuple'''. Elements of delta tuples can themselves be delta tuples. Example: &Delta;s<sub>j</sub> represents the changes that are made to each class in s<sub>f</sub> by feature j, i.e., &Delta;s<sub>j</sub>=[&Delta;c<sub>1</sub>…&Delta;c<sub>n</sub>].
Second, AHEAD expresses features as nested tuples of unary functions called '''''deltas'''''. Deltas can be
The representations of a program are computed recursively by nested vector addition. The representations for parser p<sub>2</sub> (whose GenVoca expression is j+f) are:
'''''program refinements''''' (semantics-preserving transformations), '''''extensions''''' (semantics-extending transformations),
or '''''interactions''''' (semantics-altering transformations). We use the neutral term “delta” to represent all of these possibilities, as each occurs in FOSD.


p<sub>2</sub> = j + f -- GenVoca expression
To illustrate, suppose feature j extends a grammar by <math>\Delta</math>g<sub>j</sub> (new rules and tokens are added), extends source code by <math>\Delta</math>s<sub>j</sub> (new classes and members are added and existing methods are modified), and extends documentation by <math>\Delta</math>d<sub>j</sub>. The tuple of deltas for feature j is modeled by j=[<math>\Delta</math>g<sub>j</sub>,<math>\Delta</math>s<sub>j</sub>,<math>\Delta</math>d<sub>j</sub>], which we call a '''''delta tuple'''''. Elements of delta tuples can themselves be delta tuples. As an example, <math>\Delta</math>s<sub>j</sub> represents the changes that are made to each class in s<sub>f</sub> by feature j, i.e., <math>\Delta</math>s<sub>j</sub>=[<math>\Delta</math>c<sub>1</sub>…<math>\Delta</math>c<sub>n</sub>].
= [&Delta;g<sub>j</sub>, &Delta;s<sub>j</sub>, &Delta;d<sub>j</sub>] + [g<sub>f</sub>, s<sub>f</sub>, d<sub>f</sub>] -- substitution
The representations of a program are computed recursively by composing tuples element-wise. The representations for parser p (whose GenVoca expression is j•f) are:
= [&Delta;g<sub>j</sub>+g<sub>f</sub>, &Delta;s<sub>j</sub>+s<sub>f</sub>, &Delta;d<sub>j</sub>+d<sub>f</sub>] -- compose tuples element-wise


That is, the grammar of p<sub>2</sub> is the base grammar composed with its extension (&Delta;g<sub>j</sub>+g<sub>f</sub>), the source of p<sub>2</sub> is the base source composed with its extension (&Delta;s<sub>j</sub>+s<sub>f</sub>), and so on. As elements of delta tuples can themselves be delta tuples, composition recurses, e.g., &Delta;s<sub>j</sub>+s<sub>f</sub>=
p<sub>2</sub> = j f -- GenVoca expression
= [<math>\Delta</math>g<sub>j</sub>, <math>\Delta</math>s<sub>j</sub>, <math>\Delta</math>d<sub>j</sub>] • [g<sub>f</sub>, s<sub>f</sub>, d<sub>f</sub>] -- substitution
[&Delta;c<sub>1</sub>…&Delta;c<sub>n</sub>]+[c<sub>1</sub>…c<sub>n</sub>]=[&Delta;c<sub>1</sub>+c<sub>1</sub>…&Delta;c<sub>n</sub>+c<sub>n</sub>].
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.
= [<math>\Delta</math>g<sub>j</sub>•g<sub>f</sub>, <math>\Delta</math>s<sub>j</sub>•s<sub>f</sub>, <math>\Delta</math>d<sub>j</sub>•d<sub>f</sub>] -- compose tuples element-wise


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. (This is evidenced by deltas for different artifact types above). The '''Principle of Scalability''' states all levels of abstractions are treated uniformly. (This gives rise to the hierarchical nesting of tuples above).
That is, the grammar of p is the base grammar composed with its extension (<math>\Delta</math>g<sub>j</sub>•g<sub>f</sub>), the source of p is the base source composed with its extension (<math>\Delta</math>s<sub>j</sub>•s<sub>f</sub>), and so on. As elements of delta tuples can themselves be delta tuples, composition recurses, e.g., <math>\Delta</math>s<sub>j</sub>•s<sub>f</sub>=
[<math>\Delta</math>c<sub>1</sub>…<math>\Delta</math>c<sub>n</sub>]•[c<sub>1</sub>…c<sub>n</sub>]=[<math>\Delta</math>c<sub>1</sub>•c<sub>1</sub>…<math>\Delta</math>c<sub>n</sub>•c<sub>n</sub>].
Summarizing, GenVoca values are nested tuples of program artifacts, and features are nested delta tuples, where recursively composes them. 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 refined in the same way. (This is evidenced by deltas for different artifact types above). The '''''Principle of Scalability''''' states all levels of abstractions are treated uniformly. (This gives rise to the hierarchical nesting of tuples above).


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
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
<ref name="CIDE">{{cite web| title=Guaranteeing Syntactic Correctness for all Product Line Variants: A Language-Independent Approach | url=ftp://ftp.cs.utexas.edu/pub/predator/Tools2009.pdf}}</ref>
<ref name="CIDE">{{cite web| title=Guaranteeing Syntactic Correctness for all Product Line Variants: A Language-Independent Approach | url=ftp://ftp.cs.utexas.edu/pub/predator/Tools2009.pdf}}</ref>
and FeatureHouse<ref name="FH">{{cite web| title=FeatureHouse: Language-Independent, Automated Software Composition | url=http://www.infosun.fim.uni-passau.de/cl/publications/docs/ICSE2009fh.pdf}}</ref>.
and FeatureHouse.<ref name="FH">{{cite web| title=FeatureHouse: Language-Independent, Automated Software Composition | url=http://www.infosun.fim.uni-passau.de/cl/publications/docs/ICSE2009fh.pdf}}</ref>


== FOMDD ==
== FOMDD ==
[[Image:CommutingDiagram.JPG|thumb|Derivational and refinement relationships among program artifacts]]
[[Image:CommutingDiagram.JPG|thumb|Derivational and Refinement Relationships among Program Artifacts]] '''''Feature Oriented Model Driven Design (FOMDD)''''' <ref name="fomdd">{{cite web| title=Feature Oriented Model Driven Development: A Case Study for Portlets | url=ftp://ftp.cs.utexas.edu/pub/predator/ICSE07.pdf}}</ref><ref name="genmeta">{{cite web| title=Generative Metaprogramming | url=http://portal.acm.org/citation.cfm?id=1289971.1289990}}</ref> combines the ideas of AHEAD with '''''Model Driven Design (MDD)''''' (a.k.a. '''''[[Model-Driven Architecture]] (MDA)'''''). 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 g<sub>f</sub> and its parser source s<sub>f</sub> is defined by a compiler-compiler tool, e.g., javacc. Similarly, the relationship between Java source s<sub>f</sub> and its bytecode b<sub>f</sub> 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 p<sub>3</sub> = i•j•h = [g<sub>3</sub>,s<sub>3</sub>,b<sub>3</sub>].
'''Feature-Oriented Model-Driven Design''' ('''FOMDD''')<ref name="fomdd">{{cite web| title=Feature Oriented Model Driven Development: A Case Study for Portlets | url=ftp://ftp.cs.utexas.edu/pub/predator/ICSE07.pdf}}</ref><ref name="genmeta">{{cite book |date = October 2007 |pages= 105–114 |doi = 10.1145/1289971.1289990| chapter-url=http://portal.acm.org/citation.cfm?id=1289971.1289990 |first1= Salvador |last1= Trujillo|first2= Maider |last2= Azanza|first3= Óscar|last3= Díaz|title = Proceedings of the 6th international conference on Generative programming and component engineering |chapter = Generative metaprogramming |isbn = 9781595938558 |s2cid = 236715 }}</ref> combines the ideas of AHEAD with '''Model-Driven Design''' ('''MDD''') (a.k.a. '''[[Model-Driven Architecture]]''' ('''MDA''')). 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 g<sub>f</sub> and its parser source s<sub>f</sub> is defined by a compiler-compiler tool, e.g., javacc. Similarly, the relationship between Java source s<sub>f</sub> and its bytecode b<sub>f</sub> 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 p<sub>3</sub> = i+j+h = [g<sub>3</sub>,s<sub>3</sub>,b<sub>3</sub>].


A fundamental property of a [[Commutative diagram|commuting diagram]] is that all paths between two objects are equivalent. For example, one way to derive the bytecode b<sub>3</sub> of parser p<sub>3</sub> (lower right object in the above figure) from
A fundamental property of a [[Commutative diagram|commuting diagram]] is that all paths between two objects are equivalent. For example, one way to derive the bytecode b<sub>3</sub> of parser p<sub>3</sub> (lower right object in the figure to the right) from grammar g<sub>h</sub> of parser h (upper left object) is to derive the bytecode b<sub>h</sub> and refine to b<sub>3</sub>, while another way refines g<sub>h</sub> to g<sub>3</sub>, and then derive b<sub>3</sub>, where + represents delta composition and () is function or tool application:
grammar g<sub>f</sub> of parser f (upper left object) is to derive the bytecode b<sub>f</sub> and refine to b<sub>3</sub>, while another way refines g<sub>f</sub> to g<sub>3</sub>, and then derive b<sub>3</sub>:


<math>\Delta</math>b<sub>i</sub> <math>\Delta</math>b<sub>j</sub> javac javacc = javac javacc • <math>\Delta</math>g<sub>i</sub> <math>\Delta</math>g<sub>j</sub>
: b<sub>3</sub> = &Delta;b<sub>j</sub> + &Delta;b<sub>i</sub> + {{mono|[[javacc]]}}( {{mono|[[javac]]}}( g<sub>h</sub> ) ) = {{mono|javac}}( {{mono|javacc}}( &Delta;g<sub>i</sub> + &Delta;g<sub>j</sub> + g<sub>h</sub> ) )


There are <math>\tbinom{4}{2}</math> possible paths to derive the bytecode b<sub>3</sub> of parser p<sub>3</sub> from the grammar g<sub>f</sub> of parser f. Each path represents a [[Meta-programs|metaprogram]] whose execution synthesizes the target object (b<sub>3</sub>) from the starting object (g<sub>f</sub>).
There are <math>\tbinom{4}{2}</math> possible paths to derive the bytecode b<sub>3</sub> of parser p<sub>3</sub> from the grammar g<sub>h</sub> of parser h. Each path represents a [[Metaprogramming|metaprogram]] whose execution generates the target object (b<sub>3</sub>) from the starting object (g<sub>f</sub>).
There is a potential optimization: traversing each arrow of a [[commuting diagram]] has a cost. The cheapest (i.e., shortest) 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.
There is a potential optimization: traversing each arrow of a [[commuting diagram]] has a cost. The cheapest (i.e., shortest) 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.


: Note: A “cost metric” need not be a monetary value; cost may be measured in production time, peak or total memory requirements, some informal metric like “ease of explanation”, or a combination of the above (e.g., [[Multiobjective optimization|multi-objective optimization]]). The idea of a geodesic is quite general, and should be understood and appreciated from this more general context.
: Note: A “cost metric” need not be a monetary value; cost may be measured in production time, peak or total memory requirements, power consumption, or some informal metric like “ease of explanation”, or a combination of the above (e.g., [[Multiobjective optimization|multi-objective optimization]]). The idea of a geodesic is general, and should be understood and appreciated from this more general context.


: Note: It is possible for there to be m starting objects and n ending objects in a geodesic; when m=1 and n>1, this is the [[Steiner tree|Directed Steiner Tree Problem]], which is NP-hard.
: Note: It is possible for there to be m starting objects and n ending objects in a geodesic; when m=1 and n>1, this is the [[Steiner tree problem|Directed Steiner Tree Problem]], which is NP-hard.


[[Commuting diagram]]s are important for at least two reasons: (1) there is the possibility of optimizing the synthesis of artifacts (e.g., geodesics) and (2) they specify different ways of constructing a target object from a starting object.<ref name="fomdd"/><ref name="testing">{{cite web | title=Testing Software Product Lines Using Incremental Test Generation | url=ftp://ftp.cs.utexas.edu/pub/predator/ISSRE08.pdf }}</ref> A path through a diagram corresponds to a tool chain: for an FOMDD model to be consistent, it should be proven (or demonstrated through testing) that all tool chains that map one object to another in fact yield equivalent results. (If different paths/tool chains yield different results, then either there is a bug in one or more of the tools or the FOMDD model is wrong).
[[Commuting diagram]]s are important for at least two reasons: (1) there is the possibility of optimizing the generation of artifacts (e.g., geodesics) and (2) they specify different ways of constructing a target object from a starting object.<ref name="fomdd"/><ref name="testing">{{cite web | title=Testing Software Product Lines Using Incremental Test Generation | url=ftp://ftp.cs.utexas.edu/pub/predator/ISSRE08.pdf }}</ref> A path through a diagram corresponds to a tool chain: for an FOMDD model to be consistent, it should be proven (or demonstrated through testing) 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.


: Note: the above ideas were inspired by [[category theory]] <ref name="fomdd"/><ref name="genmeta"/>.
: Note: the above ideas were inspired by [[category theory]].<ref name="fomdd"/><ref name="genmeta"/>


== Applications ==
== Applications ==

* [ftp://ftp.cs.utexas.edu/pub/predator/tosem-92.pdf Network Protocols]
* [ftp://ftp.cs.utexas.edu/pub/predator/tosem-92.pdf Network Protocols]
* [ftp://ftp.cs.utexas.edu/pub/predator/tosem-92.pdf Extensible Database Systems]
* [ftp://ftp.cs.utexas.edu/pub/predator/tosem-92.pdf Extensible Database Systems]
Line 109: Line 99:


== See also ==
== See also ==
*[[FOSD metamodels|FOSD MetaModels]] -- product lines of product lines
* [[FOSD metamodels]] product lines of product lines
* [[FOSD origami]]
*[[FOSD Program Cubes]] -- multi-dimensional product lines
* [[FOSD program cubes]] multi-dimensional product lines
*[[FOSD Feature Algebras]] -- basic operations from which FOSD features (0-ary and 1-ary) functions are defined
* [[Very high-level programming language]]
*[[FOSD Feature Interactions]] -- general concepts for feature interactions


== References ==
== References ==
<references/>
<references/>


{{DEFAULTSORT:Feature-Oriented Programming}}
{{Programming paradigms navbox}}
[[Category:Programming paradigms]]


[[de:Feature Oriented Programming]]
{{DEFAULTSORT:Feature-Oriented Programming}}
[[Category:Feature-oriented programming| ]]
[[uk:Функціонально-орієнтоване програмування]]

Latest revision as of 23:02, 1 February 2024

In computer programming, feature-oriented programming (FOP) or feature-oriented software development (FOSD) is a programming paradigm for program generation in software product lines (SPLs) and for incremental development of programs.

History

[edit]
vertical stacking of layers
Connection between layer stacks and transformation compositions

FOSD arose out of layer-based designs and levels of abstraction in network protocols and extensible database systems in the late-1980s.[1] 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 (a program transformation) 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 (layers). The figure to the left illustrates the stacking of layers i, j, and h (where h is on the bottom and i is on the top). The algebraic notations i(j(h)), 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.[2] 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;[3] 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 (e.g., source, makefiles, documentation, etc.) 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 (or derived) from others. In the sections below, the mathematics of the three most recent generations of FOSD, namely GenVoca,[1] AHEAD,[4] and FOMDD[5][6] 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

[edit]

GenVoca (a portmanteau of the names Genesis and Avoca)[1] 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 (modify, extend, refine) 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 (see MetaModels and Program Cubes). The programs (expressions) that can be created defines a product line. Expression optimization is program design optimization, and expression evaluation is program generation.

Note: GenVoca is based on the stepwise development of programs: a process that emphasizes design simplicity and understandability, which are key to program comprehension and automated program construction. Consider program p3 above: it begins with base program h, then feature j is added (read: the functionality of feature j is added to the codebase of h), and finally feature i is added (read: the functionality of feature i is added to the codebase of j•h).
Note: not all combinations of features are meaningful. Feature models (which can be translated into propositional formulas) are graphical representations that define legal combinations of features.[7]
Note: A more recent formulation of GenVoca is symmetric: there is only one base program, 0 (the empty program), and all features are unary functions. This suggests the interpretation that GenVoca composes program structures by superposition, the idea that complex structures are composed by superimposing simpler structures.[8][9] Yet another reformulation of GenVoca is as a monoid: a GenVoca model is a set of features with a composition operation (•); composition is associative and there is an identity element (namely 1, the identity function). Although all compositions are possible, not all are meaningful. That's the reason for feature models.

GenVoca features were originally implemented using C preprocessor (#ifdef feature ... #endif) techniques. A more advanced technique, called mixin layers, showed the connection of features to object-oriented collaboration-based designs.

AHEAD

[edit]

Algebraic Hierarchical Equations for Application Design (AHEAD)[4] 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=[gf, sf, df]. 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.

Hierarchical relationships among program artifacts

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 [c1…cn], and documentation df is a tuple of HTML files [h1…hk]. A GenVoca value (nested tuples) 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.

Note: Files can be hierarchically decomposed further. Each Java class can be decomposed into a tuple of members and other class declarations (e.g., initialization blocks, etc.). The important idea here is that the mathematics of AHEAD are recursive.

Second, AHEAD expresses features as nested tuples of unary functions called deltas. Deltas can be program refinements (semantics-preserving transformations), extensions (semantics-extending transformations), or interactions (semantics-altering transformations). 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 (new rules and tokens are added), extends source code by Δsj (new classes and members are added and existing methods are modified), and extends documentation by Δdj. The tuple of deltas for feature j is modeled by j=[Δgj,Δsj,Δdj], 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=[Δc1…Δcn]. The representations of a program are computed recursively by nested vector addition. The representations for parser p2 (whose GenVoca expression is j+f) are:

  p2 = j + f                           -- GenVoca expression
     = [Δgj, Δsj, Δdj] + [gf, sf, df]   -- substitution
     = [Δgj+gf, Δsj+sf, Δdj+df]         -- compose tuples element-wise

That is, the grammar of p2 is the base grammar composed with its extension (Δgj+gf), the source of p2 is the base source composed with its extension (Δsj+sf), and so on. As elements of delta tuples can themselves be delta tuples, composition recurses, e.g., Δsj+sf= [Δc1…Δcn]+[c1…cn]=[Δc1+c1…Δcn+cn]. 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. (This is evidenced by deltas for different artifact types above). The Principle of Scalability states all levels of abstractions are treated uniformly. (This gives rise to the hierarchical nesting of tuples above).

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 [10] and FeatureHouse.[11]

FOMDD

[edit]
Derivational and refinement relationships among program artifacts

Feature-Oriented Model-Driven Design (FOMDD)[5][6] combines the ideas of AHEAD with Model-Driven Design (MDD) (a.k.a. Model-Driven Architecture (MDA)). 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 = [g3,s3,b3].

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 (lower right object in the figure to the right) from grammar gh of parser h (upper left object) 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( gh ) ) = javac( javacc( Δgi + Δgj + gh ) )

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 (b3) from the starting object (gf). There is a potential optimization: traversing each arrow of a commuting diagram has a cost. The cheapest (i.e., shortest) 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.

Note: A “cost metric” need not be a monetary value; cost may be measured in production time, peak or total memory requirements, power consumption, or some informal metric like “ease of explanation”, or a combination of the above (e.g., multi-objective optimization). The idea of a geodesic is general, and should be understood and appreciated from this more general context.
Note: It is possible for there to be m starting objects and n ending objects in a geodesic; when m=1 and n>1, this is the Directed Steiner Tree Problem, which is NP-hard.

Commuting diagrams are important for at least two reasons: (1) there is the possibility of optimizing the generation of artifacts (e.g., geodesics) and (2) they specify different ways of constructing a target object from a starting object.[5][12] A path through a diagram corresponds to a tool chain: for an FOMDD model to be consistent, it should be proven (or demonstrated through testing) 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.

Note: the above ideas were inspired by category theory.[5][6]

Applications

[edit]

See also

[edit]

References

[edit]
  1. ^ a b c "Design and Implementation of Hierarchical Software Systems with Reusable Components" (PDF).
  2. ^ Access Path Selection In Relational Databases. 30 May 1979. pp. 23–34. doi:10.1145/582095.582099. ISBN 9780897910019. S2CID 8537523.
  3. ^ "Feature-Oriented Programming: A Fresh Look at Objects". Archived from the original on 2003-08-03. Retrieved 2015-12-16.
  4. ^ a b "Scaling Step-Wise Refinement" (PDF).
  5. ^ a b c d "Feature Oriented Model Driven Development: A Case Study for Portlets" (PDF).
  6. ^ a b c Trujillo, Salvador; Azanza, Maider; Díaz, Óscar (October 2007). "Generative metaprogramming". Proceedings of the 6th international conference on Generative programming and component engineering. pp. 105–114. doi:10.1145/1289971.1289990. ISBN 9781595938558. S2CID 236715.
  7. ^ "Feature Models, Grammars, and Propositional Formulas" (PDF).
  8. ^ "An Algebra for Features and Feature Composition" (PDF).
  9. ^ "Superimposition: A Language-Independent Approach to Software Composition" (PDF).
  10. ^ "Guaranteeing Syntactic Correctness for all Product Line Variants: A Language-Independent Approach" (PDF).
  11. ^ "FeatureHouse: Language-Independent, Automated Software Composition" (PDF).
  12. ^ "Testing Software Product Lines Using Incremental Test Generation" (PDF).