© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 1
Chapter 18
Software ReuseIan Sommerville
Lutz Prechelt
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 2
Objectives
To explain the benefits of software reuse and some reuse problemsTo discuss several different ways to implement software reuseTo explain how reusable concepts can be represented as patterns or embedded in program generatorsTo discuss COTS reuseTo describe the development of software product lines
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 3
Topics covered
The reuse landscapeDesign patternsGenerator based reuseApplication frameworksApplication system reuse
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 4
Software reuse
In most engineering disciplines, systems are designed by composing existing components that have been used in other systems.
Software engineering has long been more focused on original development
but it is now recognised that to reduce cost and to improve quality and time-to-market, we need to adopt a design process that is based on systematic reuse.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 5
Reuse-based software engineering
Application system reuseThe whole of an application system may be reused either by incorporating it without change into other systems or by developing application families.
Component reuseComponents of an application from sub-systems to single objects may be reused. Covered in Chapter 19.
Object and function reuseSoftware components that implement a single well-defined object or function may be reused.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 6
Reuse benefits (1)
Increased dependabilityPreviously used SW tends to have fewer defects.
Reduced process riskBuilding a component can fail more easily than reusing an existing one.Particularly true for large, complex components (sub-systems).
•Sometimes not true, if the adaptability of the reusable component is unclear.
Effective use of specialistsRare knowledge is encapsulated in a component and is then more readily and widely available.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 7
Reuse benefits (2)
Standards complianceReusing components can promote the adherence to standards (e.g. user interface look-and-feel).This improves usability of a component (for programmersand/or for end-users).
Accelerated developmentOften more important than anything else.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 8
Reuse problems (1)
Increased maintenance costExternal changes to a reused (COTS) component mayforce changes to the reusing software.Required changes to a reused component may be moredifficult to have than for a custom component.
Lack of tool supportThere is little support for maintaining a catalog of reusable components and for finding components.Development tools do not support development with all kinds of reusable components well.
Not-invented-here syndromeMany software engineers tend to prefer rewriting a component over reusing it.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 9
Reuse problems (2)
The reuse barrier:1. A software developer will only search for a reusable
component if s/he expects to find an appropriate one.2. S/he will only find it if it is described in a way s/he can
recognize as providing a solution.3. S/he will only use it if s/he can understand it.4. Use will only be successful if the component can be
adapted to the problem at hand.The whole process will start only if the developerexpects all steps to be successful in the beginning.
Reuse works well for many general-purposecomponents, but is difficult for highly domain-specific ones.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 10
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 granularity levels
• from simple functions to complete application systemsat a range of abstraction levels
• from requirements to code etc.at a range of scales
•from one-time-reuse to mass-marketing
The reuse landscape covers the range of possible reuse techniques.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 11
The reuse landscape
Designpatterns
Component-baseddevelopment
Componentframeworks
Service-orientedsystems
COTSintegration
Applicationproduct lines
Legacy systemwrapping
Programlibraries
Programgenerators
Aspect-orientedsoftware development
Configurable verticalapplications
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 12
Reuse approaches (1)
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.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 13
Reuse approaches (2)
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.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 14
Reuse planning factors
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.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 15
Concept reuse
When you reuse program or design components, you have to follow the design decisions made by the original developer of the component.
This may limit the opportunities for reuse.
However, a more abstract form of reuse is concept reuse:
A particular approach is described in an implementation-independent way.At reuse time, an implementation is then developed.
The two main approaches to concept reuse are:Design patterns;Generative programming.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 16
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.
Many patterns aim at flexibility and rely on object characteristics such as inheritance and polymorphism.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 17
Pattern elements
NameA meaningful pattern identifier.
Problem descriptionContext, requirements, constraints
Solution descriptionNot a concrete design but a template for a design solution that can be instantiated in different ways.
ConsequencesThe results, variants and trade-offs when applying the pattern.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 18
Multiple displays
A: 40B: 25C: 15D: 20
Observer 1
A
B
C
D
Observer 2
Subject
0
50
25
A B C D
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 19
The Observer pattern
NameObserver.
DescriptionSeparates the display of object state from the object itself.
Problem descriptionUsed when multiple displays of state are needed and must be added and removed at run-time.
Solution descriptionSee slide with UML description.
ConsequencesOptimisations to enhance display performance must be designed for all observers in advance.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 20
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 observerso -> Update ()
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 21
Generator-based reuse
Program generators involve the reuse of standard patterns and algorithms.
These are embedded in the generator and parameterised by user commands.
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.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 22
Types of program generator
Types of program generatorApplication generators for business data processing;Parser and lexical analyser generators for language processing (e.g. compilers);Code generators in CASE tools.
Generator-based reuse is very cost-effective but its applicability is limited to some application domains.
It is easier for end-users to develop programs using generators compared to other component-based approaches to reuse.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 23
Aspect-oriented development
Aspect-oriented development (AOD) 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.
In AOD, cross-cutting concerns are implemented separately (as 'aspects') and are dynamically woven into a program.
The concern code is reused and the new system is generated by the aspect weaver.Requires extensions to existing programming languages.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 24
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>
Any join point may be filled by more than one aspect
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 25
Application frameworks
A framework is a conceptually complete design plus an incomplete implementation.
Typically object-oriented: a collection of abstract and concrete classes and the interfaces between them.Describes a sub-system or complete system.
Implementation is completed by adding components to fill in the missing parts.Miniature example:
java.util.collections.Collection: static void sort(List list)Requires that all elements of the list implement interface Comparable: int compareTo(Object o)Reusable 'sort' will call user-defined function 'compareTo'.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 26
Types of framework
System infrastructure frameworksSupport the development of system infrastructures such as communications, user interfaces and compilers.
Middleware integration frameworksStandards and classes that support resource management and component communication.
Enterprise application frameworksSupport the development of specific types of application such as telecommunications or financial systems.
A problem with frameworks is their complexity.It takes long to learn using them effectively.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 27
Model-View-Controller (MVC)
System infrastructure framework for GUI design.
Allows for multiple presentations of an object and separate interactions with each.
Using an MVC framework involves the instantiation of a number of design patterns.
E.g. Observer pattern, Strategy pattern, maybe Composite pattern.Parts of the implementations of these patterns have to be provided by the framework user.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 28
Model-View-Controller
Model methods
Controller methods View methods
Userinputs
view modificationmessages
Model edits
Model queriesand updates
Controller state View state
Model state
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 29
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.
Two approaches covered here:COTS product integration;Product line development.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 30
COTS product reuse
COTS = Commercial Off-The-Shelf software.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.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 31
COTS design choices
Which COTS products offer the most appropriate functionality?
There may be several similar products that may be used.
Can I later switch my system over to a different COTS product if I have to?
If the COTS is decomissioned or does not support future requirements.
How will data be exchanged?Individual products use their own data structures and formats.
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.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 32
E-procurement system
Client
Web browser E-mail system
Server
E-commercesystem
Ordering andinvoicing system
E-mail system
Adaptor
Adaptor
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 33
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.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 34
COTS system integration problems
Lack of control over functionality and performanceCOTS systems may be less effective than they appear.
Problems with COTS system inter-operabilityDifferent COTS systems may make conflicting assumptions so that integration can be difficult.
No control over system evolutionCOTS vendors, not system users control evolution.
Finite support from COTS vendorsCOTS vendors may not offer support over the lifetime of the product.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 35
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.
Adaptation 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.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 36
COTS product specialisation
Platform specialisationDifferent versions of the application are developed for different platforms.
Environment specialisationDifferent versions of the application are created to handle different operating environments e.g. different types of communication equipment.
Functional specialisationDifferent versions of the application are created for customers with different requirements.Or for different marketing needs (e.g. "light" versions).
Process specialisationDifferent versions of the application are created to support different business processes.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 37
COTS configuration
Deployment-time configurationA generic system is configured by embedding knowledge of the customer’s requirements and business processes. The software itself is not changed.
Design-time configurationA common generic code is adapted and changed according to the requirements of particular customers.Creates a specific version of the software.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 38
Deployment-time configuration:ERP systems
An Enterprise Resource Planning (ERP) system is a generic system that supports common business processes
such as ordering and invoicing, production planning, etc.
These are very widely used in large companiesand represent probably the most common form of huge-scale software reuse.
The generic core is adapted at deployment timeby including modules and by incorporating knowledge of specific business processes and rules.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 39
ERP system organisation
Configurationdatabase
System database
Generic ERP system
Configurationplanning tool
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 40
Design time configuration: Product lines
Software product lines that are configured at design time are instantiations of generic application architectures
as discussed in Chapter 13.Generic products usually emerge after experience with specific products.
Architectures must be structured in such a way to separate different sub-systems and to allow them to be modified
e.g. by separating entities strongly in the architecture:The higher levels in the system access entities through descriptions rather than directly.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 41
Generic resource management system
User inter face
Resourcemanagement
Resource policycontrol
Resourceallocation
Userauthentication
Querymanagement
Resource database
Resourcedelivery
Transaction management
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 42
Vehicle despatching
A specialised resource management system where the aim is to allocate resources (vehicles) to handle incidents.
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.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 43
A vehicle 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 systeminter face
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 44
Product instance development
Elicitstakeholder
requirements
Chooseclosest-fit
family memberDeliver new
family member
Renegotiaterequirements
Adapt existingsystem
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 45
Product instance development
Elicit stakeholder requirementsUse existing family member as a prototype.
Choose closest-fit family memberFind the family member that best meets the requirements.
Re-negotiate requirementsAdapt requirements as necessary to capabilities of the software.
Adapt existing systemDevelop new modules and make changes for family member.
Deliver new family memberDocument key features for further member development.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 46
Key points
Advantages of reuse are lower costs, faster software development and lower risks.
Successful reuse requires overcoming a number of barriers: Creation/availability, discovery, understanding, fitness, trust, adaptation, evolution.
Design patterns are high-level abstractions that describe and discuss problem/solution pairs.Reusable concepts may be embedded in a program generator system.Application frameworks are collections of concrete and abstract objects
that are designed for reuse through specialisation.
© Ian Sommerville 2004, Software Engineering, 7th edition, [email protected] 47
Key points (2)
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.
ERP systems are created by configuring a generic system with information about a customer’s business.Software product lines are related applications developed around a common core of shared functionality.