Runtime Variability and Design Patterns PDF
Document Details
![SmilingHibiscus5596](https://quizgecko.com/images/avatars/avatar-15.webp)
Uploaded by SmilingHibiscus5596
Université de Fribourg
Timo Kehrer
Tags
Summary
This document discusses various aspects of runtime variability and design patterns in software product lines. The author, Timo Kehrer, explains concepts like configurations, runtime variability, realization, design patterns, implementation specifics and the significance of these topics in the context of software engineering.
Full Transcript
Part I: Ad-Hoc Approaches for Variability Part II: Modeling & Implementing Features Part III: Quality Assurance and Outlook 1. Introduction 4. Feature Modeling 9. Feature Interactions 2. Runtime Variability and Desi...
Part I: Ad-Hoc Approaches for Variability Part II: Modeling & Implementing Features Part III: Quality Assurance and Outlook 1. Introduction 4. Feature Modeling 9. Feature Interactions 2. Runtime Variability and Design Patterns 5. Conditional Compilation 10. Product-Line Analyses 3. Compile-Time Variability with 6. Modular Features 11. Product-Line Testing Clone-and-Own 7. Languages for Features 12. Evolution and Maintenance 8. Development Process 2a. Configuration of Runtime Variability 2b. Realization of Runtime Variability 2c. Design Patterns for Variability Variability and Binding Time Recap and Motivating Example Recap on Object Orientation Examples for Configuration Options Global Variables Recap on Design Patterns Command-Line Parameters Method Parameters Template Method Pattern Preference Dialogs Problems of Runtime Variability Abstract Factory Pattern Configuration Files Reconfiguration at Runtime Decorator Pattern Configuration Options and Runtime Variability Code Scattering Trade-Offs and Limitations Running Example: Graph Library Code Tangling Template Method and Abstract Factory Valid Combinations of Options Code Replication Diamond Problem and Decorator Summary Summary Summary FAQ 2. Runtime Variability and Design Patterns – Handout Software Product Lines | Timo Kehrer | September 24, 2024 2. Runtime Variability and Design Patterns 2a. Configuration of Runtime Variability Variability and Binding Time Examples for Configuration Options Command-Line Parameters Preference Dialogs Configuration Files Configuration Options and Runtime Variability Running Example: Graph Library Valid Combinations of Options Summary 2b. Realization of Runtime Variability 2c. Design Patterns for Variability Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2a. Configuration of Runtime Variability 2 Recap: Software Product Lines Software Product Line [Northrop et al. 2012, p. 5] “A software product line is a set of software-intensive systems (aka. products or variants) that share a common, managed set of features satisfying the specific needs of a particular market segment or mission (aka. domain) and that are developed from a common set of core assets in a prescribed way.” [Software Engineering Institute, Carnegie Mellon University] Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2a. Configuration of Runtime Variability 3 How to Implement Software Product Lines? Key Issues Systematic reuse of implementation artifacts Explicit handling of variability Variability [Apel et al. 2013, p. 48] “Variability is the ability to derive different products from a common set of artifacts.” Variability-Intensive System Any software product line is a variability-intensive sys- tem. Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2a. Configuration of Runtime Variability 4 Variability and Binding Times Binding Time (Bindungszeitpunkt) [Apel et al. 2013, p. 48] Variability offers choices Derivation of a product requires to make decisions (aka. binding) Decisions may be bound at different binding times When? By whom? How? Lecture 2a: when and by whom Lecture 2b: how Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2a. Configuration of Runtime Variability 5 Example: Command-Line Parameters Description of configuration options Two different instances? separator , in file sizes Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2a. Configuration of Runtime Variability 6 Example: Preference Dialogs Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2a. Configuration of Runtime Variability 7 Example: Configuration Files Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2a. Configuration of Runtime Variability 8 What do these examples have in common? Configuration Options Runtime Variability [Apel et al. 2013, p. 49] Behavior of a program is determined by configuration Runtime variability (Laufzeitvariabilität) is options being interpreted at runtime decided after compilation when the pro- Choices offered by variability are decided at runtime gram is started (aka. load-time variability) or during program execution. Configuration may happen interactively (command-line parameters, preference dialogs) or non-interactively (configuration files) Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2a. Configuration of Runtime Variability 9 Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2a. Configuration of Runtime Variability 10 [inspired by Lopez-Herrejon and Batory 2001] Example: Graph Library A simple library for graphs providing...... Data Structures... and Algorithms Directed/undirected edges Vertex numbering Weighted/unweighted edges Vertex coloring Colored/uncolored nodes Shortest path... Minimum spanning tree... Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2a. Configuration of Runtime Variability 11 Features of a Graph 3 3 3 3 2 6 2 6 2 6 2 6 1 1 1 1 3 3 3 3 2 6 2 6 2 6 2 6 1 1 1 1............ Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2a. Configuration of Runtime Variability 12 Features as Configuration Options Directed Weighted 3 3 3 3 2 6 2 6 2 6 2 6 1 1 1 1 Colored Weighted, Colored Configuration of Graph Data Structures 3 3 Typically, configuration options are flags 2 6 2 6 Their boolean value determines which features are activated / deactivated 1 1 Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2a. Configuration of Runtime Variability 13 Valid Combinations of Options Algorithm Graph type Weights Coloring Directed Weighted Vertex numbering * * * Vertex coloring undirected * colored 3 3 Shortest path directed weighted * 2 6 2 6 Minimum spanning tree undirected weighted * 1 1............ Colored Weighted, Colored Dependencies Between Features Must Be Checked 3 3 when configuration options are loaded at startup 2 6 2 6 whenever options are loaded/changed at runtime 1 1 Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2a. Configuration of Runtime Variability 14 Configuration of Runtime Variability – Summary Lessons Learned External setting of configuration options through command-line parameters, preference Practice dialogs, configuration files Do you know any practical examples making Validity of combinations may be affected by use of runtime variability? dependencies between features How does the configuration take place? Is the configuration checked for validity? Further Reading Apel et al. 2013, Chapter 3, pp. 47–49 — brief introduction of binding times Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2a. Configuration of Runtime Variability 15 2. Runtime Variability and Design Patterns 2a. Configuration of Runtime Variability 2b. Realization of Runtime Variability Recap and Motivating Example Global Variables Method Parameters Problems of Runtime Variability Reconfiguration at Runtime Code Scattering Code Tangling Code Replication Summary 2c. Design Patterns for Variability Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2b. Realization of Runtime Variability 16 Recap: Variability and Binding Times Binding Time (Bindungszeitpunkt) [Apel et al. 2013, p. 48] Variability offers choices Derivation of a product requires to make decisions (aka. binding) Decisions may be bound at different binding times When? By whom? How? Lecture 2a: when and by whom Lecture 2b: how Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2b. Realization of Runtime Variability 17 A Non-Variable Graph Implementation class Graph { class Node { class Edge { List nodes = new ArrayList(); int id = 0; Node a, b; List edges = new ArrayList(); Color color = new Color(); Weight weight; Edge add(Node n, Node m) { void print() { Edge(Node a, Node b) { Edge e = new Edge(n, m); Color.setDisplayColor(color); this.a = a; this.b = b; e.weight = new Weight(); System.out.print(id); } nodes.add(n); nodes.add(m); edges.add(e); } void print() { return e; } a.print(); b.print(); } weight.print(); Edge add(Node n, Node m, Weight w) { } Edge e = new Edge(n, m); class Color { } e.weight = w; static void setDisplayColor nodes.add(n); nodes.add(m); edges.add(e); (Color c) {...} return e; } class Weight { } void print() {...} void print() { } for (int i = 0; i < edges.size(); i++) { ((Edge) edges.get(i)).print(); } } } Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2b. Realization of Runtime Variability 18 “Symbolic” Feature Traces class Graph { class Node { class Edge { List nodes = new ArrayList(); int id = 0; Node a, b; List edges = new ArrayList(); Color color = new Color(); Weight weight; Edge add(Node n, Node m) { void print() { Edge(Node a, Node b) { Edge e = new Edge(n, m); Color.setDisplayColor(color); this.a = a; this.b = b; e.weight = new Weight(); System.out.print(id); } nodes.add(n); nodes.add(m); edges.add(e); } void print() { return e; } a.print(); b.print(); } weight.print(); Edge add(Node n, Node m, Weight w) { } Edge e = new Edge(n, m); class Color { } e.weight = w; static void setDisplayColor nodes.add(n); nodes.add(m); edges.add(e); (Color c) {...} return e; } class Weight { } void print() {...} void print() { } for (int i = 0; i < edges.size(); i++) { ((Edge) edges.get(i)).print(); } } } Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2b. Realization of Runtime Variability 19 Adding Variability class Node { Color color; The Basic Idea... Node() { Conditional statements... if (COLORED) { color = new Color(); } controlled by configuration options } void print() { if (COLORED) { Color.setDisplayColor(color); } class Graph { System.out.print(id);... } Edge add(Node n, Node m) { } Edge e = new Edge(n, m); if (WEIGHTED) { e.weight = new Weight(); } nodes.add(n); nodes.add(m); edges.add(e); class Edge { return e; Weight weight; }... Edge add(Node n, Node m, Weight w) { Edge(Node a, Node b) { if (!WEIGHTED) { throw new RuntimeException(); } this.a = a; this.b = b; Edge e = new Edge(n, m); } e.weight = w; void print() { nodes.add(n); nodes.add(m); edges.add(e); a.print(); b.print(); return e; if (WEIGHTED) { weight.print(); } } } } } Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2b. Realization of Runtime Variability 20 Global Variables public class Config { class Node { public static boolean COLORED = true; Color color;... public static boolean WEIGHTED = false; Node() { } if (Config.COLORED) { color = new Color(); } } void print() { class Graph { if (Config.COLORED) {... Color.setDisplayColor(color); Edge add(Node n, Node m) { } Edge e = new Edge(n, m); System.out.print(id); if (Config.WEIGHTED) { e.weight = new Weight(); } } nodes.add(n); nodes.add(m); edges.add(e); } return e; } Edge add(Node n, Node m, Weight w) { class Edge { if (!Config.WEIGHTED) { Weight weight;... throw new RuntimeException(); Edge(Node a, Node b) { } this.a = a; this.b = b; Edge e = new Edge(n, m); } e.weight = w; void print() { nodes.add(n); nodes.add(m); edges.add(e); a.print(); b.print(); return e; if (Config.WEIGHTED) { weight.print(); } } } } } Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2b. Realization of Runtime Variability 21 Special Case: Immutable Global Variables public class Config { public static final boolean COLORED = true; public static final boolean WEIGHTED = false; } Idea class Graph {... Use static configuration when configuration Edge add(Node n, Node m) { parameters are known at compile time Edge e = new Edge(n, m); if (Config.WEIGHTED) { e.weight = new Weight(); } nodes.add(n); nodes.add(m); edges.add(e); Discussion return e; } Advantage: Compiler optimizations may re- Edge add(Node n, Node m, Weight w) { move dead code if (!Config.WEIGHTED) { throw new RuntimeException(); } Disadvantage: No external configuration by Edge e = new Edge(n, m); e.weight = w; the end-user nodes.add(n); nodes.add(m); edges.add(e); return e; } } Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2b. Realization of Runtime Variability 22 Method Parameters Idea class Edge { boolean weighted; A class exposes its configuration parameters as Weight weight; part of its interface (i.e., method parameters)... Edge(Node a, Node b, boolean weighted) { Parameter values are passed along with each this.a = a; this.b = b; method invocation this.weighted = weighted; } void print() { class Graph { a.print(); b.print(); boolean weighted, colored; if (weighted) { weight.print(); }... } Graph(boolean weighted, boolean colored) { } this.weighted = weighted; this.colored = colored; } Edge add(Node n, Node m) { Discussion Edge e = new Edge(n, m, weighted); if (weighted) { e.weight = new Weight(); } Advantage: Different instantiations (e.g., colored nodes.add(n); nodes.add(m); edges.add(e); and uncolored graphs) within the same program return e; Disadvantage: May lead to methods with many } } parameters (code smell!) Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2b. Realization of Runtime Variability 23 Reconfiguration at Runtime? public class Config { Idea public static boolean COLORED = false; public static boolean WEIGHTED = false; Alter feature selection without stopping and restarting } the program public class Node { Color color; Though Experiment... Node(){ What happens when we change the value of COLORED if (Config.COLORED) { from false to true (at runtime)? color = new Color(); } } Discussion void print() { if (Config.COLORED) { Feature-specific code may depend on certain Color.setDisplayColor(color); initialization steps or assume certain invariants } Just updating the values of configuration options System.out.print(id); } does not update the current state of the program } (source of bugs!) [Wang et al. 2023] Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2b. Realization of Runtime Variability 24 Problem: Code Scattering (Verstreuung) public class Graph { public class Node {... Edge add(Node n, Node m) { Code ScatteringColor... color; Edge e = new Edge(n, m); Node(){ nodes.add(n); nodes.add(m); edges.add(e); if (Config.COLORED) { if (Config.WEIGHT ED) { e.weight = new Weight(); } color = new Color(); return e; } } } Edge add(Node n, Node m, Weight w) { void print() { if (!Config.WEIGHT ED) { throw new RuntimeException(); } if (Config.COLORED) { Edge e = new Edge(n, m); Color.setDisplayColor(color); nodes.add(n); nodes.add(m); edges.add(e); } e.weight = w; System.out.print(id); return e; } } }... } public class Edge { Weight weight; public class Color {... static void setDisplayColor(Color c) {...} Edge(Node a, Node b) { } a = a; b = b; if (Config.WEIGHT ED) { weight = new Weight(); } } void print() { a.print(); b.print(); public class Weight { if (Config.WEIGHT ED) { weight.print(); } void print() {...} } } } Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2b. Realization of Runtime Variability 25 Problem: Code Tangling (Vermischung) public class Graph { public class Node {... Color color; Edge add(Node n, Node m) {... Edge e = new Edge(n, m); Node(){ nodes.add(n); nodes.add(m); edges.add(e); if (Config.COLORED) { if (Config.WEIGHT ED) { e.weight = new Weight(); } color = new Color(); return e; } } } Edge add(Node n, Node m, Weight w) { void print() { if (!Config.WEIGHT ED) { throw new RuntimeException(); } if (Config.COLORED) { Edge e = new Edge(n, m); Color.setDisplayColor(color); nodes.add(n); nodes.add(m); edges.add(e); } e.weight = w; System.out.print(id); return e; } } }... } public class Edge { Weight weight; public class Color {... static void setDisplayColor(Color c) {...} Edge(Node a, Node b) { } a = a; b = b; Code Tangling } if (Config.WEIGHT ED) { weight = new Weight(); } void print() { a.print(); b.print(); public class Weight { if (Config.WEIGHT ED) { weight.print(); } void print() {...} } } } Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2b. Realization of Runtime Variability 26 Problem: Code Replication (aka. Code Clones) public class Graph { public class Node {... Edge add(Node n, Node m) { Code Replication Color color;... Edge e = new Edge(n, m); Node(){ nodes.add(n); nodes.add(m); edges.add(e); if (Config.COLORED) { if (Config.WEIGHT ED) { e.weight = new Weight(); } color = new Color(); return e; } } } Edge add(Node n, Node m, Weight w) { void print() { if (!Config.WEIGHT ED) { throw new RuntimeException(); } if (Config.COLORED) { Edge e = new Edge(n, m); Color.setDisplayColor(color); nodes.add(n); nodes.add(m); edges.add(e); } e.weight = w; System.out.print(id); return e; } } }... } public class Edge { Weight weight; public class Color {... static void setDisplayColor(Color c) {...} Edge(Node a, Node b) { } a = a; b = b; if (Config.WEIGHT ED) { weight = new Weight(); } } void print() { a.print(); b.print(); public class Weight { if (Config.WEIGHT ED) { weight.print(); } void print() {...} } } } Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2b. Realization of Runtime Variability 27 Realization of Runtime Variability – Summary Lessons Learned Global (immutable) variables or (lengthy) parameter lists Reconfiguration at runtime is possible (in Practice principle) Why are code scattering, tangling and Variability is spread over the entire program replication problematic? Variable parts are always delivered What are the problems of variable parts being always delivered? Further Reading Apel et al. 2013, Chapter 4 Meinicke et al. 2017, Section 17.1 Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2b. Realization of Runtime Variability 28 2. Runtime Variability and Design Patterns 2a. Configuration of Runtime Variability 2b. Realization of Runtime Variability 2c. Design Patterns for Variability Recap on Object Orientation Recap on Design Patterns Template Method Pattern Abstract Factory Pattern Decorator Pattern Trade-Offs and Limitations Template Method and Abstract Factory Diamond Problem and Decorator Summary FAQ Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2c. Design Patterns for Variability 29 Recap: Object Orientation Key Concepts Encapsulation: abstraction and information hiding Composition: nested objects Message Passing: delegating responsibility Distribution of Responsibility: separation of concerns Inheritance: conceptual hierarchy, polymorphism, reuse Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2c. Design Patterns for Variability 30 Recap: Design Patterns [Gang of Four] Design Patterns (Entwurfsmuster) Document common solutions to concrete yet frequently occurring design problems Suggest a concrete implementation for a specific object-oriented programming problem Design Patterns for Variability Many Gang of Four (GoF) design patterns for designing soft- ware around stable abstractions and interchangeable (i.e., variable) parts, e.g. Template Method Abstract Factory Decorator Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2c. Design Patterns for Variability 31 Recap on Design Patterns – Template Method Pattern Template Method [Gang of Four, pp. 325–330] Intent: “Define the overall structure of an algorithm, while allowing subclasses to refine, or redefine, certain steps.” Motivation: Avoid code replication by implementing the general workflow of an algorithm once, while allowing for necessary variations. Idea: A template method defines the skeleton of an algorithm. Concrete methods override the hook methods. Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2c. Design Patterns for Variability 32 Recap on Design Patterns – Abstract Factory Pattern Abstract Factory [Gang of Four, pp. 87–95] $EVWUDFW)DFWRU\ $EVWUDFW3URGXFW$ ^DEVWUDFW` ^DEVWUDFW` Intent: “Provide an interface for creating families of related or FUHDWH3URGXFW$ ^DEVWUDFW` dependent objects without FUHDWH3URGXFW% ^DEVWUDFW` 3URGXFW$ 3URGXFW$ specifying their concrete classes.” Motivation: Avoid case distinctions when creating objects of certain $EVWUDFW3URGXFW% kind, consistently create objects of a ^DEVWUDFW` &RQFUHWH)DFWRU\ &RQFUHWH)DFWRU\ particular kind. FUHDWH3URGXFW$ FUHDWH3URGXFW$ Idea: Create classes for the FUHDWH3URGXFW% FUHDWH3URGXFW% 3URGXFW% 3URGXFW% consistent creation of objects. Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2c. Design Patterns for Variability 33 Recap on Design Patterns – Decorator Pattern &RPSRQHQW ^DEVWUDFW` FRPSRQHQW Decorator [Gang of Four, pp. 175–184] RSHUDWLRQ ^DEVWUDFW` Intent: “Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.” &RQFUHWH&RPSRQHQW 'HFRUDWRU ^DEVWUDFW` Motivation: Avoid explosion of static RSHUDWLRQ classes when combining all additional RSHUDWLRQ behaviors with all applicable classes. Idea: Create decorators and components with the same interface, whereas decorators forward behavior whenever &RQFUHWH'HFRUDWRU$ &RQFUHWH'HFRUDWRU% feasible. DGGHG$WWULEXWH RSHUDWLRQ RSHUDWLRQ DGGHG2SHUDWLRQ Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2c. Design Patterns for Variability 34 Object-Oriented Design of our Graph Library Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2c. Design Patterns for Variability 35 Instantiation Through Template Method Pattern class Graph {... Edge add(Node n, Node m) { Edge e = createEdge(); nv.add(n); nv.add(m); ev.add(e); return e; } // hook method (with default implementation) Edge createEdge(Node n, Node m) { return new Edge(n, m); } } class WeightedGraph extends Graph {... // override hook method Edge createEdge(Node n, Node m) { Edge e = new WeightedEdge(n, m); e.weight = new Weight(); return e; } } Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2c. Design Patterns for Variability 36 Instantiation Through Abstract Factory Pattern class Graph { EdgeFactory edgeFactory;... Graph(EdgeFactory edgeFactory) { this.edgeFactory = edgeFactory; } Edge add(Node n, Node m) { Edge e = edgeFactory.createEdge(n, m); nodes.add(n); nodes.add(m); edges.add(e); return e; } } class WeightedEdgeFactory extends EdgeFactory { Edge createEdge(Node a, Node b) { class EdgeFactory { Edge e = new WeightedEdge(n, m); Edge createEdge(Node a, Node b) { e.weight = new Weight(); return new Edge(a, b); return e; } } } } Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2c. Design Patterns for Variability 37 Feature Combinations? Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2c. Design Patterns for Variability 38 Diamond Problem Multiple Inheritance most object-oriented programming languages do not support multiple inheritance (or only provide workarounds) critical: how to handle name clashes Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2c. Design Patterns for Variability 39 Static Modeling of Feature Combinations Even if multiple inheritance is supported, statically combining features through inheritance is tedious (or infeasible). Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2c. Design Patterns for Variability 40 Decorator Pattern as a Solution? abstract class GraphDecorator implements IGraph { IGraph graph; GraphDecorator(IGraph graph) { this.graph = graph; } } class WeightedGraph extends GraphDecorator { WeightedGraph(IGraph graph) { super(graph); } Edge add(Node n, Node m) { WeightedEdge e = (WeightedEdge) graph.add(n, m); e.weight = new Weight(); return e; }... } Example Usage IGraph graph = new WeightedGraph(new ColoredGraph(new Graph(new WeightedEdgeFactory()))); Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2c. Design Patterns for Variability 41 Delegation Instead of Inheritance Discussion Extensions (i.e., features) can be combined dynamically, but... must be independent of each other cannot add public methods runtime overhead due to indirections several physical objects are forming a conceptual one (e.g., problems with object identity) Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2c. Design Patterns for Variability 42 Design Patterns for Variability – Summary Lessons Learned Variability through object-orientation and Practice design patterns What characterizes a modular software design Extension through delegation vs. inheritance and why can it support variability? Limitations and drawbacks w.r.t. feature In which sense are object-oriented solutions combinations more modular than simple conditional statements? Further Reading Do you know of other design patterns Meyer 1997, Chapter 3–4 supporting variability? Gang of Four, Chapter 1–4 Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2c. Design Patterns for Variability 43 FAQ – 2. Runtime Variability and Design Patterns Lecture 2a Lecture 2b Lecture 2c What is variability, runtime How to realize runtime variability in What are design patterns (used variability, and binding time? source code? for)? What is the connection between What is the best strategy? Why are design patterns relevant for variability, variability-intensive How can (immutable) global variable software? systems, and software product lines? Which design patterns are relevant variables and method parameters be How can configuration options be used to realize variability? for variable software? supplied? Why is the development of runtime What are intent, motivation, and How can command-line parameters, variability challenging? idea for template method, abstract preference dialogs, and configuration What are code scattering, code factory, and decorator pattern? files be used to offer variability? Given an example class diagram, tangling, and code replication? What is the principle behind which pattern is applied or should Does runtime variability allow configuration options and when be applied? Why? reconfiguration at runtime? does the configuration happen? What is the diamond problem? How How to develop new features or What are potential features of a does it affect variable software? variants with runtime variability? graph library? Is multiple inheritance useful to Exemplify! What are examples for runtime combine features? Exemplify! What are (dis)advantages of variability? When are configuration What are limitations of design runtime variability? options specified? By whom? When (not) to use runtime patterns (for variable software)? When is the validity of configuration variability? options checked? Timo Kehrer Software Product Lines – 2. Runtime Variability and Design Patterns – 2c. Design Patterns for Variability 44