Henrik Bærbak Christensen1 Frameworks / Product Lines The frame for reuse.

Slides:



Advertisements
Similar presentations
Object-Oriented Application Frameworks Much of the cost and effort stems from the continuous re- discovery and re-invention of core concepts and components.
Advertisements

Main issues: • Why is reuse so difficult • How to realize reuse
1 Copyright 1998 by Dragos Manolescu and Joseph W. Yoder Building Frameworks With Patterns “An Active Object-Model For A Dynamic Web-Based Application”
Framework is l Reusable Code, often domain specific (GUI, Net, Web, etc) l expressed as l a set of classes and l the way objects in those classes collaborate.
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
Design Patterns for Object Oriented systems CSC 515 Ashwin Dandwate.
Introduction To System Analysis and Design
R R R CSE870: Advanced Software Engineering: Frameworks (Cheng, Sp2003)1 Frameworks A Brief Introduction.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Developed by Reneta Barneva, SUNY Fredonia Component Level Design.
Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 1 Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 Design Patterns: someone has already.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Computer Systems & Architecture Lesson Software Product Lines.
Introduction To System Analysis and design
Starting Chapter 4 Starting. 1 Course Outline* Covered in first half until Dr. Li takes over. JAVA and OO: Review what is Object Oriented Programming.
Object Oriented Software Development
Software Engineering Muhammad Fahad Khan
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 18 Slide 1 Software Reuse.
Object-oriented Software Engineering with Reuse Contracts Koen De Hondt, Carine Lucas, Kim Mens, Tom Mens, Patrick Steyaert, Roel Wuyts Programming Technology.
Introduction to Object-oriented programming and software development Lecture 1.
Objects and Components. The adaptive organization The competitive environment of businesses continuously changing, and the pace of that change is increasing.
An Object-Oriented Approach to Programming Logic and Design
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 11 : Frameworks SWE 316: Software Design and Architecture  To understand.
Creational Patterns (1) CS350, SE310, Fall, 2010.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Introduction To System Analysis and Design
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
Chapter 38 Persistence Framework with Patterns 1CS6359 Fall 2011 John Cole.
Frameworks CompSci 230 S Software Construction.
Define an interface for creating an object, but let subclasses decide which class to instantiate Factory Method Pattern.
Define an interface for creating an object, but let subclasses decide which class to instantiate.
The HotCiv GUI Instantiating the MiniDraw Framework.
Object-Oriented Programming. Objectives Distinguish between object-oriented and procedure-oriented design. Define the terms class and object. Distinguish.
Test Stubs... getting the world under control. TDD of State Pattern To implement GammaTown requirements I CS, AUHenrik Bærbak Christensen2.
Testing OO software. State Based Testing State machine: implementation-independent specification (model) of the dynamic behaviour of the system State:
The Template Method Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
Deriving State…...and an example of combining behaviour.
 2001 Lodewijk Bergmans University of Twente Pattern Languages.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
Session 7 Introduction to Inheritance. Accumulator Example a simple calculator app classes needed: –AdderApp - contains main –AddingFrame - GUI –CloseableFrame.
Basic Concepts and Definitions
Multi Dimensional Variance: How to make ultra flexible software!
Applying the Principles Two Examples. Example 1 New Requirement It would be nice with a simple GUI “to see something” instead of just xUnit tests...
Refactoring and Integration Testing or Strategy, introduced reliably by TDD The power of automated tests.
MiniDraw Introducing a Framework... and a few patterns.
CS, AUHenrik Bærbak Christensen1 Compositional Design Principles The “GoF” principles Or Principles of Flexible Design.
Strategy in 15 minutes... derived from the principles.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Instantiating the MiniDraw Framework
Introducing a Framework ... and a few patterns
Design Patterns: MORE Examples
Low Budget Productions, LLC
Behavioral Design Patterns
Software Design and Architecture
Mastering UML with Rational Rose 2002
Compositional Design Principles
Object-Oriented Programming
CMPE 135 Object-Oriented Analysis and Design March 21 Class Meeting
On the notion of Variability in Software Product Lines
Informatics 122 Software Design II
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Presentation transcript:

Henrik Bærbak Christensen1 Frameworks / Product Lines The frame for reuse

Henrik Bærbak Christensen2 Motivation I have presented some design principles –3-1-2 process: encapsulate variation, program to an interface and compose behaviour using delegation –Compositional design it is better to reuse code by delegation than inheritance let someone else do the dirty job –Iterative and Incremental search for variability supported by TDD supported by refactoring... and on the way we discovered some patterns 2

Henrik Bærbak Christensen3 Abstracting What I have actually done is to show you the pieces that together form the puzzle called frameworks: Framework: –A framework is a set of cooperating classes that make up a reusable design for a specific class of software. Exercise: –Is the pay station a framework given this definition? –Argue why MiniDraw is a framework. 3 [GoF]

Henrik Bærbak Christensen4 Framework Characteristics A framework is characterized by –reuse of both design as well as executable code –reuse within a well defined domain Swing is for GUI’s, not for banking… –high reuse percentage (70-90%) –must be customized for customer’s particular need Example: –HP printer software –Eclipse IDE plug-in architecture –CelciusTech C&C for ships –Java Swing 4

Henrik Bærbak Christensen5DAIMIHenrik Bærbak Christensen5 Other Definitions

Henrik Bærbak Christensen6DAIMIHenrik Bærbak Christensen6 Common aspects of the definitions Skeleton / design / high-level language –… provide behaviour on high level of abstraction: a design/skeleton/architecture Application/class of software –… has a well defined domain where it provides behaviour Cooperating / collaborating classes –… define and limit interaction patterns (protocol) between well defined roles Customize/abstract classes/reusable/specialize –… can be tailored to a concrete context Classes/implementation/skeleton –... is reuse of code as well as reuse of design

Variability points = Hotspots Henrik Bærbak Christensen7

Applications made from frameworks A framework based application is composed of three portions of code –The framework code (external, third party) –The framework customization code (our own code) –Non-framework related code (own code) Example: HotCiv project –MiniDraw framework (basic GUI control) –Customization code (adapt MiniDraw til Civ graphics) –HotCiv domain code (attacking, units, city production, …) Henrik Bærbak Christensen8

Which leads to... Traditionally one distinguish between –Developers:Developing the software for end users –End users:Using the software Frameworks require one additional role –Framework developers:Develops the framework –Application developers:Adapt the FW for users –End users:Using the software I.e.: The end users of a framework are themselves software developers! Henrik Bærbak Christensen9

10 HotSpots… ”Separate code that changes from the code that doesn’t” Hot spots are also known as: –Hooks / hook methods –Variability points (our favourite term) 10

Henrik Bærbak Christensen11 Example The pay station system has hotspots regarding –receipt type –rate policy –display output –weekend determination but frozen spots, fixed behaviour, concerning –coin types (payment options), numerical only display, only buy and cancel buttons, etc. Domain: Pay stations –no reuse in the electronic warfare domain 11

Frozen spots Frozen is important : keep the code in the fridge! Code modifications means unthawing and freezing again    Henrik Bærbak Christensen12

Why... I have realized that this point is so natural to me that I have more or less forgotten to emphasize it. Why –Consider Java Swing If you had to rewrite code in 8 different places in the Swing library to add a new special purpose visual component –Then you had to Understand the Swing code in deep detail (costs!) Reintroduce special purpose code everytime Sun/Oracle releases a new version of Swing (costs!!!) Henrik Bærbak Christensen13

Morale You adapt a framework to your particular needs by –Change by addition, not by modification!!! –Open for extension, closed for modification You –Implement interfaces or extend existing classes Concrete implementations, real behaviour filling out the responsibilities defined by the framework –Tell the framework to use your implementations... Henrik Bærbak Christensen14

Which again leads to... If the framework has to use my concrete implementations then... It cannot itself create these objects –If MiniDraw itself had Drawing = new StandardDrawing(); –Then it was an application (fixed behaviour), not a framework (adaptable behaviour). Then... How can it create objects? Henrik Bærbak Christensen15

Dependency Injection Typically an (OO) framework would use factory techniques like abstract factory –Or prototype or factory method patterns... –Or reading configuration files, or using conventions Ruby on Rails, Grails, Maven, use particular named files in specific directory paths to configure the frameworks Henrik Bærbak Christensen16

Henrik Bærbak Christensen Customization Techniques

Techniques to define hotspots We have object oriented composition to define hotspots. We have also looked at other techniques –Parameterization, overriding superclass methods Henrik Bærbak Christensen18

Henrik Bærbak Christensen19 HotSpots Exercise: List techniques to make the hotspots –Hint: Consider techniques used in MiniDraw Swing Java RMI Collection classes Eclipse C library sorting algorithms Intel 486 interrupt vector handling Functional languages Amiga libraries Does a Framework require object-orientation? 19

A good framework Must give ”return on investment” –Investment: ”I have to learn how to use it” –Return: ”I get reliable software that does a lot” Swing/MiniDraw/... –Consider writing Swing yourself! Henrik Bærbak Christensen20

In the old times... Henrik Bærbak Christensen21

Henrik Bærbak Christensen22

Framework Protocol

Henrik Bærbak Christensen24 Design and Code Reuse “Cooperating / collaborating classes –… define and limit interaction patterns (protocol) between well defined roles” Frameworks require users (=developers) to understand the interaction patterns between objects in the FW and their own customization objects. That is, understand the protocol. –Ex: Understand the editor↔tool protocol in MiniDraw –One TA tried to invoke activate on a tool (and ended with an infinite loop) activate is a method called by MiniDraw when a tool is activated!

Henrik Bærbak Christensen25 Where is the protocol? So: The framework dictates the protocol! The question is: How?

Henrik Bærbak Christensen26 Protocol The protocol arise because objects in the framework invokes methods on objects that are defined by you. These methods/functions/procedures that are predefined by the framework to be ‘overridable’ or customizable are the hotspots. A framework contains frozen code with embedded hotspots where your (unfrozen) code may be called.

Inversion of Control This property of frameworks is called Inversion of Control (”Hollywood principle: do not call us, we will call you.) The framework dictates the prototocol – the customization code just has to obey it! Henrik Bærbak Christensen27

Compare ‘traditional’ reuse Another type of reuse of code (more than design) is libraries I have never written my own cosine function – have you? There are lot of libraries of usable behavior out there that does not invert control. Henrik Bærbak Christensen28

Inversion of Control Note: inversion of control is not a ’required’ characteristics of a framework in some author’s view –RMI is an example. The control inversion is difficult to spot... –(but why is it not just a library then???) Henrik Bærbak Christensen29

Henrik Bærbak Christensen30 Template Method The central OO pattern to separate frozen and hot code The core of the inverted control

Henrik Bærbak Christensen31 Template Method Intent (Original GoF statement) –Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure. Restatement –Some steps in the algorithm are fixed but some steps I would like to keep open for future modifications to the behaviour 31

Henrik Bærbak Christensen32 GoF Structure The structure in GoF is that of subclassing 32

The Multi-Dimensional Variability Subclassing handles multi-dimensional variability very badly... Consider –Three variants of step1() required –Four variants of step2() –Any combination feasible How many subclasses? Henrik Bærbak Christensen33

Henrik Bærbak Christensen34 Conclusion Conclusion: Favour object composition over class inheritance 34

Henrik Bærbak Christensen35 Exercise Rewrite the GoF structure to its compositional equivalent that is behavioural equivalent but follows the three principles of flexible design. 35

Find the error in the Book The book’s code is not wrong but it misses the point in supporting multi- dimensional variability  Improved version: Henrik Bærbak Christensen36

Template Method Terminology These two variants have a name: –Original: subclassing+override hook methods –New: interface implementation + delegate to hooks Henrik Bærbak Christensen37

Henrik Bærbak Christensen38 Exercise Identify template method in the pay station: 38 public void addPayment( int coinValue ) { switch ( coinValue ) { case 5: case 10: case 25: break; default: throw new IllegalCoinException("Invalid coin: "+coinValue+" cent."); } insertedSoFar += coinValue; _timeBought = rateStrategy.calculateTime(insertedSoFar); }

Exercise How does template method relate to the inversion of control property of frameworks? Henrik Bærbak Christensen39

Henrik Bærbak Christensen40 Not wrong, but misses the point

Improved structure Henrik Bærbak Christensen41

Henrik Bærbak Christensen42 Another Case for Composition

Henrik Bærbak Christensen43 Mixing Two Frameworks Based upon the inheritance based template method 43

Henrik Bærbak Christensen44 Mixing Two Frameworks But it does work using compositional template method 44 Example: MiniDraw and Swing combination

Henrik Bærbak Christensen45 Software Reuse and Product Line Architectures

Reuse of software Software reuse –High quality (= reliable) software If mature and well supported –Lower cost One line of reliable implementation is expensive!!! Easier to buy than to develop –Faster development Building apps is faster and cheaper Henrik Bærbak Christensen46

Reuse types There are many different types of reuse: –Math.cos(double x)code reuse –Strategy Patterndesign reuse –Knuth’s binary search alg.design reuse Frameworks are pretty special: Henrik Bærbak Christensen47

Henrik Bærbak Christensen48 Software Engineering Institute SEI in Pittsburgh –(associated with Carnegie Mellon University) 48

Henrik Bærbak Christensen49 Analysis Characteristics –software intensive system –common, managed, set of features –needs of particular market segment –developed from a common set of core assets –prescribed way Exercise: Compare PayStation 49

Henrik Bærbak Christensen50 Framework/Product Line In my view the technical aspects of a product line is covered by the framework concept –A framework is a set of cooperating classes that make up a reusable design for a specific class of software. 50

Henrik Bærbak Christensen51 Organisation Aspect The organisation aspect, however, is important: –managed set of features –developed in a prescribed way –market segment A lot of experience from industry point to the fact that software reuse and product line reuse is primarily a organisational challenge! –Who pays for making the code flexible? Not my project – I want to save my own a… Reuse is actually quite expensive in practice  51