software reuse main text: ian sommerville, software engineering, 8 th edition, chapter 18 additional...

59
Software Reuse Main text: Ian Sommerville, Software Engineering, 8 th edition, chapter 18 Additional readings: Prieto Diaz, "Status Report: Software Reusability," IEEE Software, 10(3):61-66, May, 1993. Bruce H. Barnes, Terry B. Bollinger, "Making Reuse Cost-Effective", IEEE Software, vol. 8, no. 1, pp. 13-24, January/February, 1991

Upload: isabel-park

Post on 26-Dec-2015

222 views

Category:

Documents


1 download

TRANSCRIPT

Software Reuse

Main text:

• Ian Sommerville, Software Engineering, 8th edition, chapter 18

Additional readings:

• Prieto Diaz, "Status Report: Software Reusability," IEEE Software, 10(3):61-66, May, 1993.

• Bruce H. Barnes, Terry B. Bollinger, "Making Reuse Cost-Effective", IEEE Software, vol. 8, no. 1, pp. 13-24, January/February, 1991

Software reuse

• In most engineering disciplines, systems are designed by composing existing components that have been used in other systems.

• Software engineering has been more focused on original development but it is now recognised that to achieve better software, more quickly and at lower cost, we need to adopt a design process that is based on systematic software reuse.

• Systematic software reuse vs ad-hoc reuse:– Human nature is inherently lazy => developers are happy to find

ready-made solutions

– Problem: ad-hoc (or copy-paste) reuse may be harmful !

Reuse Taxonomy – what, how, where to reuse ?

From [Prieto-Diaz91]

Reuse – by substance

• Classification of reuse according to the essence of items to be reused:– Ideas, concepts:

• Reuse of abstract concepts – sharing “wisedom”

• General solutions to a class of problems: algorithms

– Artifacts, components• Reuse of software parts

– Processes, procedures, skills• Reusable processes – needs more formalization of software

development procedures

• Procedure reuse – means also the informal reuse of skills

Reuse – by scope

• Classification of reuse according to the form and extent of reuse:– Vertical: reuse within the same domain or application

area• Goal: to build generic models for families of systems that can

be used as templates for building new system in that domain• Needs: effort in domain analysis and domain modelling

– Horizontal: reuse of generic parts in different applications

• Example: scientific subrutines • Needs: packaging and presentation of parts; cataloging and

classification standards for parts;

Reuse – by technique

• Classification of reuse according to the the approach used to implement reuse:

– Compositional• Uses existing components as building blocks for new

systems

– Generative• Reuse at the specification level by means of application or

code generators

Reuse – by product

• Classification of reuse according to the work products that are reused:

– Source code

– Design

– Specifications

– Objects

– Text

– Architectures

What to reuse

• Today’s agenda: (mainly based on chap. 18 from [Sommerville])– Software building blocks– Concept reuse

Reusing software building blocks

• What size are the reused blocks?– Application system reuse

• The whole of an application system may be reused:– by incorporating it without change into other systems. (COTS reuse - Detailed in

[Sommerville 18.5.1]– by reusing a common architecture used for developing applications from the same

family, tailored for specific customers. (Software product lines - Detailed in [Sommerville 18.5.2]

– Component reuse• Components of an application from sub-systems to single objects may be

reused. Detailed in [Sommerville Chapter 19]

– Object and function reuse• Software components that implement a single well-defined object or function

may be reused.

• Who reuses ?– Third party reuse: COTS– Intra-organizational: Software product lines

Concept reuse

• Concepts are abstract, the reuse process includes an instantiation activity

– Design patterns. Detailed in [Sommerville 18.2]

– Program generators. Detailed in [Sommerville 18.3]

Reuse benefits Increased dependability

Reused software, that has been tried and tested in working systems, should be more dependable than new software. The initial use of the software reveals any design and implementation faults. These are then fixed, thus reducing the number of failures when the software is reused.

Reduced process risk If software exists, there is less uncertainty in the costs of reusing that software than in the costs of development. This is an important factor for project management as it reduces the margin of error in project cost estimation. This is particularly true when relatively large software components such as sub-systems are reused.

Effective use of specialists

Instead of application specialists doing the same work on different projects, these specialists can develop reusable software that encapsulate their knowledge.

Fig 18.1. [Sommerville]

Reuse benefits (cont.)

Standards compliance

Some standards, such as user interface standards, can be implemented as a set of standard reusable components. For example, if menus in a user interfaces are implemented using reusable components, all applications present the same menu formats to users. The use of standard user interfaces improves dependability as users are less likely to make mistakes when presented with a familiar interface.

Accelerated development

Bringing a system to market as early as possible is often more important than overall development costs. Reusing software can speed up system production because both development and validation time should be reduced.

Fig.18.1 [Sommerville]

Reuse problems Increased maintenance costs

If the source code of a reused software system or component is not available then maintenance costs may be increased as the reused elements of the system may become increasingly incompatible with system changes.

Lack of tool support

CASE toolsets may not support development with reuse. It may be difficult or impossible to integrate these tools with a component library system. The software process assumed by these tools may not take reuse into account.

Not-invented-here syndrome

Some software engineers sometimes prefer to re-write components as they believe that they can improve on the reusable component. This is partly to do with trust and partly to do with the fact that writing original software is seen as more challenging than reusing other people’s software.

Fig. 18.2 from [Sommerville]

Reuse problems (cont.)

Creating and maintaining a component library

Populating a reusable component library and ensuring the software developers can use this library can be expensive. Our current techniques for classifying, cataloguing and retrieving software components are immature.

Finding, understanding and adapting reusable components

Software components have to be discovered in a library, understood and, sometimes, adapted to work in a new environment. Engineers must be reasonably confident of finding a component in the library before they will make routinely include a component search as part of their normal development process.

Fig. 18.2 [Sommerville]

The reuse landscape

• Although reuse is often simply thought of as the reuse of system components, there are many different approaches to reuse that may be used.

• Reuse is possible at a range of levels from simple functions to complete application systems.

• The reuse landscape covers the range of possible reuse techniques.

The reuse landscape

Fig. 18.3 from [Sommerville]

Designpatterns

Component-baseddevelopment

Componentframeworks

Service-orientedsystems

COTSintegration

Applicationproduct lines

Legacy systemwrapping

Programlibraries

Programgenerators

Aspect-orientedsoftware development

Configurable verticalapplications

Reuse approaches Design patterns Generic abstractions that occur across applications

are represented as design patterns that show abstract and concrete objects and interactions.

Component-based development

Systems are developed by integrating components (collections of objects) that conform to component-model standards. This is covered in Chapter 19.

Application frameworks

Collections of abstract and concrete classes that can be adapted and extended to create application systems.

Legacy system wrapping

Legacy systems (see Chapter 2) that can be ‘wrapped’ by defining a set of interfaces and providing access to these legacy systems through these interfaces.

Service-oriented systems

Systems are developed by linking shared services that may be externally provided.

Fig. 18.4 from [Sommerville]

Reuse approaches (cont)

Application product lines

An application type is generalised around a common architecture so that it can be adapted in different ways for different customers.

COTS integration Systems are developed by integrating existing application systems.

Configurable vertical applications

A generic system is designed so that it can be configured to the needs of specific system customers.

Program libraries Class and function libraries implementing commonly-used abstractions are available for reuse.

Program generators

A generator system embeds knowledge of a particular types of application and can generate systems or system fragments in that domain.

Aspect-oriented software development

Shared components are woven into an application at different places when the program is compiled. (See chapter 32)

Reuse planning factors

• Key question: given this array of techniques for reuse, which one (if any) to choose ?

• The key factors to be considered when planning reuse:– The development schedule for the software.– The expected software lifetime.– The background, skills and experience of the development team.– The criticality of the software and its non-functional

requirements.– The application domain.– The execution platform for the software.

• Conclusion: whether reuse is achieved or not is often a managerial rather than technical issue

Reuse Investment Cost

Estimated cost w/o reuse

Cost w/ reuse

Estimated cost w/o reuse

Cost w/ reuse

. . .

$ Savings $ Savings

Reuse investments

Net profit Net loss

Reuse producer activities Reuse consumer activities

From [Barnes&Bollinger91]

Reusing parts - Size of reuse units

• Possible reuse units:– Objects: often too fine-grained and too specialised for a

particular application

– Application frameworks: larger-grain abstractions

• Application frameworks:– Frameworks are a sub-system design made up of a

collection of abstract and concrete classes and the interfaces between them.

– The sub-system is implemented by adding components to fill in parts of the design and by instantiating the abstract classes in the framework.

– Frameworks are moderately large entities that can be reused.

Framework classes

• System infrastructure frameworks– Support the development of system infrastructures such as

communications, user interfaces and compilers.

• Middleware integration frameworks– Standards and classes that support component communication

and information exchange.

• Enterprise application frameworks– Support the development of specific types of application such as

telecommunications or financial systems.

Extending frameworks

• Frameworks are generic and are extended to create a more specific application or sub-system.

• Extending the framework involves

– Adding concrete classes that inherit operations from abstract classes in the framework;

– Adding methods that are called in response to events that are recognised by the framework.

• Problem with frameworks is their complexity which means that it takes a long time to use them effectively.

Example: Model-view controller

• System infrastructure framework for GUI design.

• Allows for multiple presentations of an object and separate interactions with these presentations.

• MVC framework involves the instantiation of a number of patterns (as discussed earlier under concept reuse).

Example: Model-view-controller

Model methods

Controller methods View methods

Userinputs

view modificationmessages

Model edits

Model queriesand updates

Controller state View state

Model state

Fig. 18.10 from [Sommerville]

Application system reuse

• Involves the reuse of entire application systems either by configuring a system for an environment or by integrating two or more systems to create a new application.

• Reuses large-grain assets

• Two approaches covered here:– COTS product integration;– Product line development.

COTS product reuse

• COTS - Commercial Off-The-Shelf systems – a software system that can be used without change by its buyer

• Examples of COTS: database management systems, web browser, e-mailer

• COTS systems are usually complete application systems that offer an API (Application Programming Interface).

• Building large systems by integrating COTS systems is now a viable development strategy for some types of system such as E-commerce systems.

• The key benefit is faster application development and,

usually, lower development costs.

COTS design choices

• Which COTS products offer the most appropriate functionality?– There may be several similar products that may be used.

• How will data be exchanged?– Individual products use their own data structures and formats.– Writing adapters that convert from one representation to another

• What features of the product will actually be used?– Most products have more functionality than is needed. You

should try to deny access to unused functionality.

COTS Example: E-procurement system

Fig. 18.11 from [Sommerville]

Client

Web browser E-mail system

Server

E-commercesystem

Ordering andinvoicing system

E-mail system

Adaptor

Adaptor

Convert formats of

orders

Convert notifications into emails

COTS products reused

• On the client, standard e-mail and web browsing programs are used.

• On the server, an e-commerce platform has to be integrated with an existing ordering system.

• This involves writing an adaptor so that they can exchange data.

• An e-mail system is also integrated to generate e-mail for clients. This also requires an adaptor to receive data from the ordering and invoicing system.

COTS system integration problems

• Lack of control over functionality and performance– COTS systems may be less effective than they appear

• Problems with COTS system inter-operability– Different COTS systems may make different assumptions that

means integration is difficult

• No control over system evolution– COTS vendors not system users control evolution

• Support from COTS vendors– COTS vendors may not offer support over the lifetime of the

product

Software product lines

• Software product lines or application families are applications with generic functionality that can be adapted and configured for use in a specific context.

• All members of the family share a common core:– The application-specific architecture

– A set of core components

• Adaptation (creation of individual family members) may involve:– Component and system configuration;

– Adding new components to the system;

– Selecting from a library of existing components;

– Modifying components to meet new requirements.

Specialisation in a product line

• Platform specialisation– Different versions of the application are developed for different

platforms.

• Environment specialisation– Different versions of the application are created to handle

different operating environments e.g. different types of communication equipment.

• Functional specialisation– Different versions of the application are created for customers

with different requirements.

• Process specialisation– Different versions of the application are created to support

different business processes.

Product line configuration

• Software product lines are designed to be reconfigured.

• Reconfiguration:– Adding or removing components

– Defining parameters and constraints for components

– Including knowledge of business processes

• Software product lines can be configured at 2 points in the development process:– Deployment time configuration

• A generic system is configured by embedding knowledge of the customer’s requirements and business processes. The software itself is not changed.

– Design time configuration• A common generic code is adapted and changed according to the

requirements of particular customers.

Example of deployment-time configuration:

Configuration of an ERP system

Configurationdatabase

System database

Generic ERP system

Configurationplanning tool

Fig. 18.12 from [Sommerville]

Example: ERP systems

• An Enterprise Resource Planning (ERP) system is a generic system that supports common business processes such as ordering and invoicing, manufacturing, etc.

• These are very widely used in large companies - they represent probably the most common form of software reuse.

• The generic core is adapted by including modules and by incorporating knowledge of business processes and rules.

Design time configuration

• Software product lines that are configured at design time are instantiations of generic application architectures (see Chapter 13).

• Involves changing and extending the source code of the core system

• Offers greater flexibility than deployment-time configuration

• Generic products usually emerge after experience with specific products.

Product line architectures

• The decision to design a generic product line becomes explicit at a point, otherwise changes may corrupt the application structure

• Architectures must be structured in such a way to separate different sub-systems and to allow them to be modified.

• The architecture should also separate entities and their descriptions and the higher levels in the system access entities through descriptions rather than directly.

Product line: Vehicle despatching

• A specialised resource management system where the aim is to allocate resources (vehicles) to handle incidents.

• Versions for: police, fire service, ambulance service• Adaptations include:

– At the UI level, there are components for operator display and communications;

– At the I/O management level, there are components that handle authentication, reporting and route planning;

– At the resource management level, there are components for vehicle location and despatch, managing vehicle status and incident logging;

– The database includes equipment, vehicle and map databases.

A despatching system

User interface

Vehicle statusmanager

Incidentlogger

Operatorauthentication

Querymanager

Equipmentdatabase

Map and routeplanner

Transaction management

Vehicle database

Incident log

Map database

Vehicledespatcher

Equipmentmanager

Vehiclelocator

Reportgenerator

Comms systeminterface

Fig. 18.14 from [Sommerville]

Product instance development

Elicitstakeholder

requirements

Chooseclosest-fit

family memberDeliver new

family member

Renegotiaterequirements

Adapt existingsystem

Fig. 18.15 from [Sommerville]

Product instance development

• Elicit stakeholder requirements– Use existing family member as a prototype

• Choose closest-fit family member– Find the family member that best meets the requirements

• Re-negotiate requirements– Adapt requirements as necessary to capabilities of the software

• Adapt existing system– Develop new modules and make changes for family member

• Deliver new family member– Document key features for further member development

Concept reuse• When you reuse program or design components, you have to

follow the detailed design decisions made by the original developer of the component.

– This may limit the opportunities for reuse.• One way around is to reuse abstract designs (concepts) that

do not include implementation details

– You must implement the abstract design for your application

– Examples of reusable concepts: algorithms, abstract data types, design patterns

• Main approaches to concept reuse are:– Design patterns– Generative programming

Design patterns

• A design pattern is a way of reusing abstract knowledge about a problem and its solution.

• A pattern is a description of the problem and the essence of its solution.

• It should be sufficiently abstract to be reused in different settings.

• Patterns often rely on object characteristics such as inheritance and polymorphism.

Pattern elements

• Identification of a pattern [GoF]:– Name - A meaningful pattern identifier.

– Problem description – when the pattern can be applied

– Solution description - Not a concrete design but a template for a design solution that can be instantiated in different ways.

– Consequences - The results and trade-offs of applying the pattern.

Example: The Observer pattern

NameObserver.

DescriptionSeparates the display of object state from the object itself.

Problem descriptionUsed when multiple displays of state are needed.

Solution descriptionSee slide with UML description.

ConsequencesOptimisations to enhance display performance are impractical.

Example: Multiple displays

A: 40B: 25C: 15D: 20

Observer 1

A

B

C

D

Observer 2

Subject

0

50

25

A B C D

Fig. 18.6 from [Sommerville]

Example: The Observer pattern

Subject Observer

Attach (Observer)Detach (Observer)Notify ()

Update ()

ConcreteSubject

GetState ()

subjectState

ConcreteObserver

Update ()

observerState

observerState = subject -> GetState ()return subjectState

for all o in observers o -> Update ()

Fig. 18.7 from [Sommerville]

Reuse through patterns - conclusion

• The use of patterns is an effective form of reuse

• Disadvantage: only experienced software engineers who have a deep knowledge of patterns can use them effectively

– Experience needed to recognise generic situations where a pattern can be applied

Generator-based reuse• Concept reuse through patterns:

– relies on describing the concept in an abstract way and leaving it up to the software developer to create an implementation

• Generator-based reuse:

– Program generators involve the reuse of standard patterns and algorithms.

– These are embedded in the generator and parameterised by user commands. A program is then automatically generated.

– Generator-based reuse is possible when domain abstractions and their mapping to executable code can be identified.

– A domain specific language is used to compose and control these abstractions.

Reuse through program generation

Program generator Generated programApplicationdescription

Application domainknowledge

Database

Fig. 18.8 from [Sommerville]

Types of program generators• Generator-based reuse takes advantage of the fact that applications in the

same domain have common architectures and carry out similar functions

• Areas of use for program generator

– Application generators for business data processing• Systems follow an input-process-output model

• Usually include operations as data verification and report generation – generic components

– Parser and lexical analyser generators for language processing (examples: lex, yacc);

• input=the grammar

• output=the parser program

– Code generators in CASE tools; • input=design diagrams

• output=program implementing the design

Generator-based reuse

• Disadvantages:

– Generator-based reuse has a high initial cost in defining and implementing the domain concepts and language

– its applicability is limited to a relatively small number of application domains.

• Advantages:

– It is easier for end-users to develop programs using generators compared to other component-based approaches to reuse.

• Future:– Generative programming

• K. Czarnecki. Overview of Generative Software Development. In J.-P. Banâtre et al. (Eds.): Unconventional Programming Paradigms (UPP), LNCS 3566, pp. 313–328, 2005. http://www.swen.uwaterloo.ca/~kczarnec/gsdoverview.pdf

• Czarnecki and Eisenecker, Components and generative programming. ESEC/FSE 1999. http://www.prakinf.tu-ilmenau.de/~czarn/esec99/esec99.pdf

– Aspect-oriented software development• Kiczales et al, An Overview of AspectJ, ECOOP 2001

http://people.cs.ubc.ca/~gregor/papers/kiczales-ECOOP2001-AspectJ.pdf• [Sommerville], chap. 32

Generative programming

• Combines program generation with component-based development

• Applicable for System-family engineering (also known as software product-line engineering)

• exploits the commonalities among systems from a given problem domain while managing the variabilities among them in a systematic way

• Generative software development is a system-family approach, which focuses on automating the creation of system-family members: a given system can be automatically generated from a specification written in one or more textual or graphical domain-specific languages

Spectrum of generative approaches

from [Czarnecki]

Aspect-oriented development

• Aspect-oriented development addresses a major software engineering problem - the separation of concerns.

• Concerns are often not simply associated with application functionality but are cross-cutting - e.g. all components may monitor their own operation, all components may have to maintain security, etc.

• Cross-cutting concerns are implemented as aspects and are dynamically woven into a program. The concern code is reuse and the new system is generated by the aspect weaver.

Aspect-oriented development

Generated code

Aspect 1 Aspect 2

AspectWeaver

<statements 1>Aspect 1

<statements 2>Aspect 2

<statements 3>

Input source code

<statements 1>join point 1

<statements 2>join point 2

<statements 3>

Fig. 18.9 from [Sommerville]

A simple AspectJ example

Example 2-1. A simple business logic Java class

package com.oreilly.aspectjcookbook;

public class MyClass{public void foo(int number, String name){System.out.println("Inside foo (int, String)");}public static void main(String[] args){// Create an instance of MyClassMyClass myObject = new MyClass( );// Make the call to foomyObject.foo(1, "Russ Miles");}}

Example 2-2. A simple HelloWorld aspect in AspectJ

package com.oreilly.aspectjcookbook;

public aspect HelloWorld{pointcut callPointcut( ) :call(void com.oreilly.aspectjcookbook.MyClass.foo( int, String));

before() : callPointcut( ){System.out.println("Hello World");System.out.println("In the advice attached to the call pointcut");}}

HelloWorld defines an aspect that will be applied to the class MyClass.The aspect captures all calls to the void foo(int, String) method in the MyClass class.The ajc compiler will produce two .class files; MyClass.class and HelloWorld.class.

• Advantages of reuse are lower costs, faster software development and lower risks.

• Design patterns are high-level abstractions that document successful design solutions.

• Program generators are also concerned with software reuse - the reusable concepts are embedded in a generator system.

• Application frameworks are collections of concrete and abstract objects that are designed for reuse through specialisation.

• COTS product reuse is concerned with the reuse of large, off-the-shelf systems.

• Problems with COTS reuse include lack of control over functionality, performance, and evolution and problems with inter-operation.

• Software product lines are related applications developed around a common core of shared functionality.

Key points