Title: Software Variability, Generative Programming and Software Product Lines Neil Loughran
1Software Variability, Generative Programming and
Software Product Lines
Neil Loughran
- Varietys the very spice of life William
Cowper 1731-1800
2Introduction
- Things I will cover
- Variability
- Software product line
- Generative programming
- Code generation
- Framed aspects
- Things I wont cover in detail if at all
- Variability mechanisms
- Component models
- ADLs
3Software variability
- An emerging trend in software development
- Reuse
- Configuration
- Product line development
- Move from hardware to software
- Delaying design decisions
- Motivation is primarily economic
- Save time
- Costs
- Improve quality
- Lessen defects due to consistency
- Flexibility
4Where does variability occur?
- Variability in reuse
- Code
- Designs
- Tests
- Requirements
- Variability in configuration
- Trade offs
- Optimisations
- Different requirements
- Facilitating future evolution
- Leave hooks in the software to ease evolution
- Variability of bind time
- Delaying of design decisions to the last possible
moment
5Types of variabilities
- Change in function
- Change in data
- Control flow between objects
- Technology and platforms
- Quality (e.g. performance v security)
- Environment
6Reuse
- Variability is strongly related to reuse
- Basically 2 types
- As-is Where code or components are reused as-is,
without modification. (e.g. reuse an existing
class or library function) - Adaptive Where code/component is adapted to a
different context using variability mechanisms.
(e.g. conditional compilation, templates, code
generator)
7Software product lines
- First touted as early as 1976 by David L Parnas
- Product lines
- The move from one of a kind software development
to reusable software architectures. - Pizza analogy
- Pizza base different toppings
8Product lines I
- Product lines
- a set of software-intensive systems sharing
a common, managed set of features that satisfy
the specific needs of a particular market segment
or mission and that are developed from a common
set of core assets. (Paul Clements of SEI) - Examples of product lines
- Reservation/Booking systems
- Call and response systems
- Philips audio-visual systems (Koala)
- Volkswagen engine control systems (Bosch)
9Product lines II
- Creating a product line of software applications
is not simply just a matter of finding useful
pieces of code and bolting them together in an
ad-hoc fashion. - Domain engineering has emerged as a means to
define families and assemble the required assets. - Commonality and variability analysis is a process
of identifying common and variable parts in the
domain.
10Domain engineering
- Move from creating one of a kind systems to a
software architecture which models product
families
11Commonality and variability analysis
12Modelling variability
- Feature diagrams using Feature Oriented Design
Analysis (FODA ) - Allow mapping of requirements and variabilities
to a model
13Software product line implementation approaches
- Configuration management
- Generally considered the wrong approach for
configuration of variants in SPL - Component models
- Koala, Darwin et al
- OO Frameworks
- A collection of classes with hotspots (variation
points) left abstract - Generative Programming
14Generative Programming
- Generative programming, or as it now more
commonly known, generative software development,
is an approach to building software for a
particular application domain. - Raising the abstraction to more human readable
terms. - Examples
- Feature oriented programming
- GENVOCA / AHEAD
- Template meta-programming
- Frame Technology
- MDA
15Code Generation
- What is code generation?
- Programs that create programs
- Higher level abstraction
- DRY principle (Dont repeat yourself!)
- Consistency
- EJB Database example
- Deployment descriptors
- Cuts down on time and reduce lines of code
- Examples of code generators
- Frame Technology
- Macro
- Wizard
- Dreamweaver
16Code Generation Example
Generic Code Templates
High Level Specification
Appplication
General Purpose Generator
17Frame Technology
- A code generation technology
- Originally COBOL dependant but modern techniques
such as XVCL employ language independent XML - Conceived in the 1970s by Paul Bassett
- Adaptive reuse
- Parameterisation
- Conditional Compilation
- Templates
- Language Independent
- Textual documents
- Any programming language
- UML scripts (Jarzabek, et al)
18Frames
- Frame technology organises concerns into a
hierarchy, where lower order frames refine the
ones above.
19Essential Frame Commands
- ltsetgt, ltset-multigt, ltvalue-ofgt
- allows frame values to be created and set
- ltwhilegt
- creates a loop around repeating code
- ltadaptgt
- instructs processor to process a frame
- ltbreakgt
- creates a point of interest that we can add
variant code to - ltoptiongt ltselectgt ltifdefgt
- creates and select an option
20Code Generation with Frames
Specification
ltset multi-var Object value String,
Document, Integer, Hashtable/gt ltadapt frame
CustomVector/gt
Custom Vector
Output
ltwhile using-items in _at_Objectgt class
lt_at_ObjectgtVector extends Vector public
boolean add(lt_at_Objectgt o) if(o
instanceof lt_at_Objectgt) return super.add(o)
else return
false lt/whilegt
class StringVector extends Vector
public boolean add(String o)
if(o instanceof String) return
super.add(o) else return
false class DocumentVector
extends Vector public boolean
add(Document o) if(o instanceof
Document) return super.add(o)
else return false
// etc..
produces
Note Examples uses simplified XVCL constructs
for clarity
21Caching Example
class Editor extends JEditorPane implements
HyperlinkListener private Network network
//.. constructor and editor initialisation
//.. various methods public void
hyperlinkUpdate(HyperlinkEvent e) if
(e.getEventType() HyperlinkEvent.EventType.ACTI
VATED) String url
e.getURL().toString() network.requestInfo(this
, url)
Simple Editor Pane When user clicks on a
hyperlink, call the requestInfo method in the
Network class
22Caching Example
class Editor extends JEditorPane implements
HyperlinkListener private Network network
private Hashtable cache new Hashtable() //
.. methods for adding and retrieving data to/from
cache //.. constructor and editor
initialisation public void
hyperlinkUpdate(HyperlinkEvent e) if
(e.getEventType() HyperlinkEvent.EventType.ACTI
VATED) String url
e.getURL().toString() Document cachedPage
(Document)getFromCache(url)
if(cachedPage null)
network.requestInfo(this, url)
addToCache(url, this.getDocument)
else // get record from cache
and display it this.setDocument((Document)
cachedPage.getContent())
Code shown in bold is code added by the
integration of a caching feature
23Identifying Cache Concern with Frames
class Editor extends JEditorPane implements
HyperlinkListener private Network network
ltoption cachegt private Hashtable cache new
Hashtable() // .. methods for adding and
retrieving data to/from cache lt/optiongt
//.. constructor and editor initialisation
public void hyperlinkUpdate(HyperlinkEvent e)
if (e.getEventType() HyperlinkEvent.Event
Type.ACTIVATED) String url
e.getURL().toString() ltoption cachegt
Document cachedPage (Document)getFromCache(url)
if(cachedPage null)
lt/optiongt network.requestInfo(this,
url) ltoption cachegt
addToCache(url, this.getDocument)
else // get record from cache
and display it this.setDocument((Document)
cachedPage.getContent())
lt/optiongt
Using frame meta tags to identify caching concern
24Integrating a cache with AOP
- Using AspectJ as representative AOP technology
- aspect CacheAspect
-
- private Hashtable cache new Hashtable()
-
- void around(Editor g, String url) args
(g,url) - call (public void Network.requestInfo(Editor,
String)) -
- Document cachedPage(Document) cache.get(url)
- if(cachedPagenull)
-
- proceed(g,url)
- Document page new Document(g.getDocument(
)) - addToCache(url,page)
-
- else
-
- g.setDocument(cachedPage.getContent())
-
-
- Modularity preserved making it easier to retract
from code base, and also evolve - However AOP is not easy to reuse in the main
- Cant use parameterisation, generics, templates
- to store other types of information other than
Document objects or - operate on classes other than Network and
Editor - alter advice call to an alternative method
25Frames Merits/Demerits
- Strengths
- Easy to learn
- Natural to use see a variation point tag it!
- Language independent
- Very flexible configuration
- Highly reusable
- Weaknesses
- Ineffective when dealing with tangled and
crosscutting concerns - Invasive approach can lead to heavily tagged code
26Variability and AspectJ
- In addition to the Java language variability
mechanisms Aspect J also adds the following. - Introductions
- Advice
- Abstract pointcuts
27Variability using Introductions and Advice
- Introductions allows refinements to be added
staticly to existing classes without explicitly
affecting the underlying code. - Advice allows new code to be added at defined
points of execution in the code.
public void A.printMsg() // method
introduction public int B.number 77 // field
introduction // advice after() execution (void
C.printInvoice())
28Variability using abstract pointcuts and
inheritance
Create abstract pointcut and advice in a base
class
- abstract aspect Base
- abstract pointcut myPCT()
- after() myPCT() code
Inherit the base class and implement the pointcut
aspect A extends Base pointcut myPCT()
execution (void MyClass.method())
29AspectJ as a product line technology
- Crosscutting variable features can be modularised
separately from common ones. - Reuse is possible via abstract poincuts and
inheritance. - No parameterisation, conditional compilation and
template facilities - Difficult to adapt aspect to different contexts
without affecting the code directly - Use of abstract aspects via inheritance may not
be fine grained enough - Cannot use aspect in a black box fashion
30Other variability mechanisms for AspectJ?
- Conditional Compilation
- Not supported
- Java style conditional compilation doesnt work
on advice - Generics (Java 1.5)
- Work by instantiation
- Wont work on AOP specific constructs (pointcuts,
advice, introductions etc.) - Patterns
- May not always be a pattern that fits the problem
31Merits/Demerits of AOP
- Strengths
- Advanced separation of concerns
- Non invasiveness
- Dynamic approaches
- Some techniques can weave into bytecode
- Weaknesses
- Limited reusability
- No parameterisation
- Templates
- Conditional compilation
32Comparison
The negatives of one approach are the merits of
the other and vice versa.. therefore..
33Comparison
The negatives of one approach are the merits of
the other and vice versa.. therefore..
34Framed Aspects
- Combine Frames and AOP together to enhance
- Configurability
- Reusability
- Modularity
- Readability (due to reduction in meta tags)
- Evolvability
- Development of Lancaster Frame Processor (LFP)
- Essentially a refined and simpler version of
frame technology - Removal of break command to encourage
modularisation via AOP advice. - Addition of composition rules module
35Initial Approach to Framing Aspects
Multi dimensional refinements
Generalised cache using framed aspects
36Second Approach
- Made up of three elements
- Specification
- The developers customisation requirements
- Composition Rules
- Checks for specification validity
- Binds the framed aspects together
- Framed Aspects
- Parameterised, generic aspects that can be bound
- to new specifications
37Methodology
- Reusable plug in cache for SQL caching and Web
caching
Cache
DB
Web
Deletion Scheme
Manual Cache Clear
Access
Date
Size
WebUpdate
Writable
Manual
Automatic
DBUpdate
Key
Mandatory
Time Based
Optional
EveryWrite
Alternative
1. Create feature diagram using FODA
38Frame Delineation
Delineating frame boundaries of a) mandatory,
b) optional and c) alternative features.
39Delineated Frames
Frame Boundary
2. Delineate the frames
40Framed Aspect Module
- private int MAX_CACHE_SIZE lt_at_MAX_CACHE_SIZEgt
- private int PERCENTAGE_TO_DEL lt_at_PERC_TO_DELgt
- private Hashtable cache new Hashtable(MAX_CACHE_
SIZE) - public void addToCache(String key, lt_at_DOC_TYPEgt
data) - //..impl..
- pointcut QUERY_PCT(String key, lt_at_CONN_CLASSgt c)
this(c) args - (key) call(public void lt_at_CONN_CLASSgt.lt_at_SEND_QU
ERYgt(String)) -
- pointcut RESULT_PCT(lt_at_DOC_TYPEgt data,
lt_at_CONN_CLASSgt c) - !within(Cache) this(c) args(data)
- call (public void lt_at_CONN_CLASSgt.lt_at_REPLY_CLIENTgt(
lt_at_DOC_TYPEgt)) - class CacheDS
-
- private lt_at_DOC_TYPEgt data
- public CacheDS(lt_at_DOC_TYPEgt d)
Code for Cache frame
41Composition Rules Module
- ltconstrain option "CACHE_TYPE" toSet
"DATABASE,WEB" /gt - ltconstrain var "PERC_TO_DEL" toBoundary
"25,100" /gt - ltconstrain option "DELETION_SCHEME" toSet
"ACCESS,DATE,SIZE" /gt - ltconstrain option "DB_UPDATE_SCHEME" toSet
"EVERY_WRITE,TIME_BASED" /gt - ltconstrain option "WEB_UPDATE_SCHEME" toSet
"AUTOMATIC,MANUAL" /gt - ltadapt frame "CACHE.frame" /gt
- ltadapt frame "CACHE_TYPE /gt
- ltif option "MANUAL_CACHE_CLEAR" value "TRUE"gt
- ltadapt frame "MANUAL_CACHE_CLEAR.frame" /gt
- lt/ifgt
- ltif option "CACHE_TYPE" value "DATABASE"gt
- ltif option "WRITABLE" value "TRUE"gt
- ltadapt frame "WRITABLE.frame" /gt
- ltadapt frame "DB_UPDATE_SCHEME /gt
- lt/ifgt
- lt/ifgt
42Specification Module
ltselect option "CACHE_TYPE" value "DATABASE"
/gt ltset var "MAX_CACHE_SIZE" value "1000" /gt
ltselect option "DELETION_SCHEME" value
"ACCESS" /gt ltset var "PERC_TO_DEL" value
"50" /gt ltset var "CONN_CLASS" value
"DBConnection" /gt ltset var "SEND_QUERY" value
"sendQuery" /gt ltset var "REPLY_CLIENT" value
"replyToClient" /gt ltset var "DOC_TYPE" value
"String" /gt ltselect option "WRITABLE" value
"TRUE" /gt ltselect option "DB_UPDATE_SCHEME"
value "EVERYWRITE" /gt ltadapt frame
"CACHE_RULES"/gt
43Projects which used Framed Aspects approach
- Applied to
- AspectJ
- Persistence aspect
- Guide system
- Mobile phone games
- Aspectwerkz/JAC
- Dynamic autonomic adaptation
44Reflection on Framed Aspects
- AOP lacks mechanisms for enabling reuse, making
them limited in high reuse domains such as
product lines. - Frame technology cannot modularise crosscutting
features adequately, leading to spaghetti code
and explosion of meta tags which limits
understanding. - Framed aspects combine the respective strengths
of AOP and frames thus providing reuse mechanisms
for AOP and improving crosscutting support for
frame technology.
45Pointers
- Books
- Generative Programming (K. Czarnecki)
- Domain Engineering
- FODA
- Templates
- Code Generation (J. Herrington)
- XML and Ruby based code generation
- Web
- Software Engineering Institute (SEI)
- http//www.sei.cmu.edu/
- XVCL Frame Processor
- http//xvcl.comp.nus.edu.sg/overview_brochure.php
- Papers
- Framed Aspects (2 papers)
- Managing Variability Throughout the Software
Lifecycle - All located at Lancaster AOSD site
- http//www.comp.lancs.ac.uk/computing/aose