You are on page 1of 47

Chapter 18

Software Reuse
Ian Sommerville
Lutz Prechelt

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 1


Objectives
z To explain the benefits of software reuse and
some reuse problems
z To discuss several different ways to implement
software reuse
z To explain how reusable concepts can be
represented as patterns or embedded in program
generators
z To discuss COTS reuse
z To describe the development of software product
lines

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 2


Topics covered
z The reuse landscape
z Design patterns
z Generator based reuse
z Application frameworks
z Application system reuse

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 3


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

z 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, prechelt@inf.fu-berlin.de 4


Reuse-based software engineering
z Application system reuse
ƒ The whole of an application system may be reused either
by incorporating it without change into other systems or
by developing application families.

z Component reuse
ƒ Components of an application from sub-systems to single
objects may be reused. Covered in Chapter 19.

z Object and function reuse


ƒ Software components that implement a single well-
defined object or function may be reused.

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 5


Reuse benefits (1)
z Increased dependability
ƒ Previously used SW tends to have fewer defects.

z Reduced process risk


ƒ Building 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.

z Effective use of specialists


ƒ Rare knowledge is encapsulated in a component and is
then more readily and widely available.
© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 6
Reuse benefits (2)
z Standards compliance
ƒ Reusing components can promote the adherence to
standards (e.g. user interface look-and-feel).
ƒ This improves usability of a component (for programmers
and/or for end-users).

z Accelerated development
ƒ Often more important than anything else.

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 7


Reuse problems (1)
z Increased maintenance cost
ƒ External changes to a reused (COTS) component may
force changes to the reusing software.
ƒ Required changes to a reused component may be more
difficult to have than for a custom component.
z Lack of tool support
ƒ There 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.
z Not-invented-here syndrome
ƒ Many software engineers tend to prefer rewriting a
component over reusing it.

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 8


Reuse problems (2)
z 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 developer
expects all steps to be successful in the beginning.

z Reuse works well for many general-purpose


components, but is difficult for highly domain-
specific ones.
© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 9
The reuse landscape
z Although reuse is often simply thought of as the
reuse of system components, there are many
different approaches to reuse that may be used.

z Reuse is possible
ƒ at a range of granularity levels
• from simple functions to complete application systems
ƒ at a range of abstraction levels
• from requirements to code etc.
ƒ at a range of scales
• from one-time-reuse to mass-marketing
z The reuse landscape covers the range of possible
reuse techniques.
© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 10
The reuse landscape
Design
patterns

Component Application
frameworks product lines Aspect-oriented
software development

Component-based COTS Program


development integration generators
Legacy system
wrapping
Configurable vertical
applications
Service-oriented
systems
Program
libraries

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 11


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- Systems are developed by integrating components
based (collections of objects) that conform to component-
development model standards. This is covered in Chapter 19.
Application Collections of abstract and concrete classes that
frameworks can be adapted and extended to create application
systems.
Legacy system Legacy systems (see Chapter 2) that can be
wrapping 'wrapped' by defining a set of interfaces and
providing access to these legacy systems through
these interfaces.
Service-oriented Systems are developed by linking shared services
systems that may be externally provided.

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 12


Reuse approaches (2)
Application An application type is generalised around a common
product lines architecture so that it can be adapted in different
ways for different customers.
COTS integration Systems are developed by integrating existing
application systems.
Configurable A generic system is designed so that it can be
vertical configured to the needs of specific system
applications customers.
Program libraries Class and function libraries implementing commonly-
used abstractions are available for reuse.
Program A generator system embeds knowledge of a
generators particular types of application and can generate
systems or system fragments in that domain.
Aspect-oriented Shared components are woven into an application at
software different places when the program is compiled.
development

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 13


Reuse planning factors
z The development schedule for the software.
z The expected software lifetime.
z The background, skills and experience of the
development team.
z The criticality of the software and its non-
functional requirements.
z The application domain.
z The execution platform for the software.

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 14


Concept reuse
z 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.

z 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.

z The two main approaches to concept reuse are:


ƒ Design patterns;
ƒ Generative programming.
© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 15
Design patterns
z A design pattern is a way of reusing abstract
knowledge about a problem and its solution.

z A pattern is a description of the problem and the


essence of its solution.

z It should be sufficiently abstract to be reused in


different settings.

z Many patterns aim at flexibility and rely on object


characteristics such as inheritance and
polymorphism.

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 16


Pattern elements
z Name
ƒ A meaningful pattern identifier.

z Problem description
ƒ Context, requirements, constraints

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

z Consequences
ƒ The results, variants and trade-offs when applying the
pattern.

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 17


Multiple displays

50
D
A
C 25
A B C D
B 0

Subject

Observer 1 A: 40 Observer 2
B: 25
C: 15
D: 20

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 18


The Observer pattern
z Name
ƒ Observer.
z Description
ƒ Separates the display of object state from the object
itself.
z Problem description
ƒ Used when multiple displays of state are needed and must
be added and removed at run-time.
z Solution description
ƒ See slide with UML description.
z Consequences
ƒ Optimisations to enhance display performance must be
designed for all observers in advance.

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 19


The Observer pattern

Subject Observer

Attach (Observer) Update ()


Detach (Observer)
Notify () for all o in observers
o -> Update ()

ConcreteSubject ConcreteObserver

observerState =
GetState () return subjectState Update ()
subject ->
GetState ()
subjectState observerState

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 20


Generator-based reuse
z Program generators involve the reuse of
standard patterns and algorithms.
ƒ These are embedded in the generator and
parameterised by user commands.

z 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, prechelt@inf.fu-berlin.de 21


Types of program generator
z Types of program generator
ƒ Application generators for business data processing;
ƒ Parser and lexical analyser generators for language
processing (e.g. compilers);
ƒ Code generators in CASE tools.

z Generator-based reuse is very cost-effective but


its applicability is limited to some application
domains.

z 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, prechelt@inf.fu-berlin.de 22
Aspect-oriented development
z Aspect-oriented development (AOD) addresses a
major software engineering problem:
the separation of concerns.
z 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.
z 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, prechelt@inf.fu-berlin.de 23


Aspect-oriented development

Aspect 1 Aspect 2

Input source code Generated code


Aspect <statements 1>
<statements 1> Weaver
join point 1 Aspect 1
<statements 2> <statements 2>
join point 2 Aspect 2
<statements 3> <statements 3>

Any join point may be filled by more than one aspect

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 24


Application frameworks
z 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.
z Implementation is completed by adding
components to fill in the missing parts.
z 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, prechelt@inf.fu-berlin.de 25


Types of framework
z System infrastructure frameworks
ƒ Support the development of system infrastructures such
as communications, user interfaces and compilers.
z Middleware integration frameworks
ƒ Standards and classes that support resource management
and component communication.
z Enterprise application frameworks
ƒ Support the development of specific types of application
such as telecommunications or financial systems.

z A problem with frameworks is their complexity.


ƒ It takes long to learn using them effectively.

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 26


Model-View-Controller (MVC)
z System infrastructure framework for GUI design.

z Allows for multiple presentations of an object and


separate interactions with each.

z 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, prechelt@inf.fu-berlin.de 27


Model-View-Controller

User Controller state view modification View state


inputs messages

Controller methods View methods

Model queries
Model edits and updates
Model state

Model methods

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 28


Application system reuse
z 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.

z Two approaches covered here:


ƒ COTS product integration;
ƒ Product line development.

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 29


COTS product reuse
COTS = Commercial Off-The-Shelf software.
z COTS systems are usually complete application
systems that offer an API (Application
Programming Interface).
z Building large systems by integrating COTS
systems is now a viable development strategy for
some types of system
ƒ such as E-commerce systems.
z The key benefit is faster application development
and, usually, lower development costs.

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 30


COTS design choices
z Which COTS products offer the most appropriate
functionality?
ƒ There may be several similar products that may be used.
z 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.
z How will data be exchanged?
ƒ Individual products use their own data structures and
formats.
z 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, prechelt@inf.fu-berlin.de 31


E-procurement system
Client

Web browser E-mail system

Server

E-commerce Ordering and


Adaptor
system invoicing system

E-mail system Adaptor

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 32


COTS products reused
z On the client, standard e-mail and web browsing
programs are used.

z 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.

z 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, prechelt@inf.fu-berlin.de 33


COTS system integration problems
z Lack of control over functionality and performance
ƒ COTS systems may be less effective than they appear.
z Problems with COTS system inter-operability
ƒ Different COTS systems may make conflicting
assumptions so that integration can be difficult.
z No control over system evolution
ƒ COTS vendors, not system users control evolution.
z Finite support from COTS vendors
ƒ COTS vendors may not offer support over the lifetime of
the product.

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 34


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

z 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, prechelt@inf.fu-berlin.de 35


COTS product specialisation
z Platform specialisation
ƒ Different versions of the application are developed for
different platforms.
z Environment specialisation
ƒ Different versions of the application are created to handle
different operating environments e.g. different types of
communication equipment.
z Functional specialisation
ƒ Different versions of the application are created for
customers with different requirements.
ƒ Or for different marketing needs (e.g. "light" versions).
z Process specialisation
ƒ Different versions of the application are created to
support different business processes.
© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 36
COTS configuration
z 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.

z Design-time configuration
ƒ A 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, prechelt@inf.fu-berlin.de 37


Deployment-time configuration:
ERP systems
z An Enterprise Resource Planning (ERP) system is a
generic system that supports common business
processes
ƒ such as ordering and invoicing, production planning, etc.

z These are very widely used in large companies


ƒ and represent probably the most common form of huge-
scale software reuse.

z The generic core is adapted at deployment time


ƒ by including modules and
ƒ by incorporating knowledge of specific business processes
and rules.

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 38


ERP system organisation

Configuration
planning tool

Generic ERP system


Configuration
database

System database

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 39


Design time configuration: Product lines
z 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.
z 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, prechelt@inf.fu-berlin.de 40


Generic resource management system

User inter face

User Resource Query


authentication delivery management

Resource Resource policy Resource


management control allocation

Transaction management
Resource database

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 41


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

z 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, prechelt@inf.fu-berlin.de 42
A vehicle despatching system

User interface Comms system


inter face

Operator Map and route Report Query


authentication planner generator manager

Vehicle status Incident Vehicle Equipment Vehicle


manager logger despatcher manager locator

Transaction management Incident log


Equipment
database Vehicle database Map database

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 43


Product instance development

Renegotiate
requirements
Elicit Choose
stakeholder closest-fit
requirements family member
Adapt existing Deliver new
system family member

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 44


Product instance development
z Elicit stakeholder requirements
ƒ Use existing family member as a prototype.
z Choose closest-fit family member
ƒ Find the family member that best meets the requirements.
z Re-negotiate requirements
ƒ Adapt requirements as necessary to capabilities of the
software.
z Adapt existing system
ƒ Develop new modules and make changes for family
member.
z Deliver new family member
ƒ Document key features for further member development.

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 45


Key points
z 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.
z Design patterns are high-level abstractions that
describe and discuss problem/solution pairs.
z Reusable concepts may be embedded in a
program generator system.
z Application frameworks are collections of
concrete and abstract objects
ƒ that are designed for reuse through specialisation.

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 46


Key points (2)
z 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.
z ERP systems are created by configuring a generic
system with information about a customer’s
business.
z Software product lines are related applications
developed around a common core of shared
functionality.

© Ian Sommerville 2004, Software Engineering, 7th edition, prechelt@inf.fu-berlin.de 47

You might also like