Professional Documents
Culture Documents
1
The unit explores the two main concepts of structure and
reuse.
Note that: All SAQs and Exercises in this unit are required.
2
Section 1: Introduction
3
Section 1: Introduction
4
Section 2 : Architecture
5
Section 2 : Architecture
7
Section 2 : Architecture
Figure 3 shows the very different architecture used by Skype, a well-known
internet telephony service.
8
Section 2 : Architecture
Figure 4 Filter
9
Section 2 : Architecture
The output from one filter can be ‘piped’ to another filter. The pipe is
visualized as a channel along which the data flows.
The two filters each perform an independent chunk of processing and are
not aware of one another.
The Windows command for a pipe is | and the following combination will
pipe the output from findstr/b to findstr/e.
findstr/b "P" elements.txt | findstr/e "um "
The result of the second filter can be piped to a third sort filter (Figure 5).
findstr/b "P" elements.txt | findstr/e "um" | sort
10
Section 2 : Architecture
A lot of attention has rightly been given to the question of whether there is a
conflict between architecture and agility.
◦ An architecturally focused approach will start to consider very early on
what the main elements of the system are and how they will interact.
◦ An agile approach will typically emphasize being adaptive and delaying
decisions for as long as possible.
12
Section 2 : Architecture
Architecture and agility are far from incompatible and in fact can benefit
one another.
By giving architecture equal emphasis with requirements, twin-peaks model
helps to answer the criticism often made that agile does not scale up to
larger projects.
The interweaving of requirements and architecture allows customers to
become involved in architectural decisions.
In a recent survey,Falessi et al. (2010) found that many agile practitioners
consider architecture to be important for complex projects and that agile
values and architecture are mutually supportive.
13
Section 2 : Architecture
There can be multiple architectures that meet the functional requirements but they
will not all be equal when it comes to non-functional requirements.
Not all non-functional requirements will be of equal importance when making
architectural decisions.
Figure 7 illustrates that meeting non-functional requirements is a stronger restriction
than meeting functional ones.
15
Section 2 : Architecture
16
Section 2 : Architecture
Architectural views
The logical (or functional) view describes the system’s main functional elements
and their interactions – broadly, the services the system must provide to users.
The process view describes the set of independently executing processes that will
exist at run-time and the communication between them.
The physical (or deployment) view describes how the system will be deployed to
an operating environment in terms of the physical computers and networks on
which the system will run.
The development view describes how the software will be split into subsystems
that can be allocated to teams of developers.
The ‘+1’ part of the model is the use of key scenarios – instances of use cases – to
help develop and validate the design.
17
Section 2 : Architecture
Bass et al. (2003) present a slightly different set, although they are
essentially equivalent to Kruchten’s.
The module view corresponds to the logical view in the 4+1 model. It
describes the main functional responsibilities of the system and how the
different parts depend on one another.
The component and connector view is similar to the process view in the
4 +1 model, with the independent processes being regarded as
components and the communications between them modelled by
connectors.
The allocation view describes all the mappings between the software and
the external environment in the widest sense and roughly corresponds to a
combination of the physical and development view in the 4+1 model.
18
Section 2 : Architecture
The logical view describes the main functional elements and how they interact,
and assumes that these correspond to subsystems that can be allocated to teams
of developers.
◦ This is effectively an amalgamation of Kruchten’s logical and development views. We made this choice
because we don’t plan to explore in any detail how work is allocated to teams so there is no need for a
separate view.
The process view describes the independent processes executing at runtime and
the communication between them, regarding the processes as components and the
communication as taking place via connectors.
◦ This is similar to the process view in the 4+1 model but using the component and connector terminology
borrowed from Bass et al. We made this choice because components and the communication between
them is an important part of the discussions in this unit and the next.
The deployment view describing how the system will be deployed to an operating
environment, the physical computers and networks on which the system will run.
◦ This is similar to the physical view in the 4+1 model. It is important to us because deployment decisions
will have a major impact on quality attributes.
19
Section 2 : Architecture
A system will have many groups of stakeholders and each stakeholder group
will have a particular set of concerns.
A concern is some aspect of the system that is of crucial importance from the
point of view of one or more groups of stakeholders.
Concerns can be to do with the system’s functionality or with qualities such as
correctness, performance, security and so on.
Because an architecture is too complex to be expressed in a single complete
description, we need a number of views, each of which addresses a particular
set of stakeholder concerns.
The views should be intelligible (clear) to stakeholders and should allow them
to see how the architecture deals with their concerns.
In software architecture the set of conventions and models appropriate to a
particular view is often referred to as a viewpoint. You can think of a
viewpoint as the language that is used to document a specific type of view.
20
Section 2 : Architecture
21
Section 2 : Architecture
Summary of section
In this section you first revisited the definition of a software architecture and then saw
several examples of different architectures.
Requirements and architecture go hand in hand and both must be considered in parallel
right from the start. Following an iterative twin-peaks model of development allows
architecture to be responsive to change and to provide support for agile development in
ways such as aiding communication, documenting assumptions and contributing to
subsequent iterations.
Non-functional requirements shape architecture, along with other considerations such
as the system’s core purpose and the environment it will run in. Collectively these
factors are known as architecturally significant requirements (ASRs).
An architectural view is a representation of the system that emphasises the concerns of
a particular set of stakeholder groups. The description of an architecture requires
several such views because no one view can capture the concerns of all the
stakeholders.
A range of view sets have been proposed. The version used in this module consists of
the logical, process and deployment views.
Each architectural view has a particular set of models and conventions that are used to
describe it. This is often called a viewpoint.
22
A major aspiration of software engineering is reuse – taking what you or
others have done or created in the past and using it either unchanged or
with relatively little adaptation.
23
Section 3: Reuse
24
Section 3: Reuse
Summary of section
This can take place on a range of levels, from architecture down to ways
of doing things in a particular language, and at different stages, from
requirements through to analysis and design.
25
Section 4: Reusing architecture
Architectural styles
At a very general level we can identify a number of basic plans used in software
architecture; these have come to be known as architectural styles.
Commonly architectural styles include:
◦ Client–server
◦ Call-return
◦ Layered
◦ Peer-to-peer
◦ Data flow
◦ Data-centred
◦ Independent components
◦ Service-oriented
◦ Notification
It is also important to note that there are relationships between these different
styles and some overlap with others.
26
Section 4: Reusing architecture
Client–server
Client–server style is probably the best known of all architectural styles.
Call-return
In a call-return style a component (the caller) makes a procedure call to another
component (often known as the callee) and waits for the call to return.
In traditional software a main program calls a subprogram and waits for a reply.
Layered
The essence of a layered style is that the system is structured as a series
of layers that are visualised as stacked on top of another.
Each layer uses services provided by the layers below (usually just by the
layer immediately below). It also supplies services to the layer above.
29
Section 4: Reusing architecture
The components in this style are the various services in each layer and
the connectors are the calls made on the services.
Normally a layer can only communicate with layers above and below.
There is no communication between components in the same layer.
The layered style is illustrated in Figure 11.
31
Section 4: Reusing architecture
Data flow (also known as pipes and filters)
The data-flow style components are objects or small independent subprograms
(filters) that process a stream of data and pass the results on to other components
for further processing.
Communication is unidirectional and uses fixed channels. Each filter has no
knowledge of other filters upstream or downstream, but simply accepts the data,
processes it and passes it on.
The connectors are services, provided by the operating environment, that ‘pipe’
data from one filter to another.
◦ This type of architecture is commonly used in the Unix operating system for combining
functions and is also seen in the Stream application programming interface (API)
introduced from Java 8 onwards.
The data-flow style is illustrated in Figure 13.
Data-centred
In the data-centred style there is a data provider that is a
centralized store of persistent data.
The structure of the data, the types of items and their relationships
are stable and change rarely or not at all.
There are many clients who are data consumers. Items can be
created, queried, updated and destroyed on request.
The central store may be duplicated, to provide backup in case of
failure or to deal with a greater volume of client requests.
The communication channels are normally fixed.
33
Section 4: Reusing architecture
34
Section 4: Reusing architecture
Independent components
In the independent components style (Figure 15), components execute
concurrently and are decoupled as far as possible, but can communicate
by messages that allow them to exchange data or coordinate their
operations.
The connectors are the message exchange protocols, which are normally
asynchronous (i.e. the sender can continue without waiting for an answer
from the other component).
Example: a set of components
controlling different parts of a
chemical processing plant,
independently regulating the
part each is responsible for, but
sharing data and coordinating
with one another by exchanging
messages.
Figure 15 Independent components architectural style
35
Section 4: Reusing architecture
Service-oriented
36
Section 4: Reusing architecture
37
Section 4: Reusing architecture
In the notification style the two kinds of components are observers and
subjects.
Observers can register themselves with a subject in order to be kept
notified whenever some particular event happens at the subject’s end.
At an architectural level this style is usually referred to as publish–
subscribe.
Subscribers register to receive updates (often messages) whenever a
publisher posts a new item.
◦ For example an RSS feed where anyone who signs up to the feed receives news updates
as they become available. Notification also appears at a more detailed design level.
◦ Another example of notification is an event-based model such as Java Swing, in which
components can register themselves with other components to receive information about
events such as user input and react to them by executing appropriate event-handling
code.
38
Section 4: Reusing architecture
Frameworks
It may be possible to reuse a large part of the architecture, along with any
code the systems have in common.
Frameworks: Segments of architecture and code that can be reused.
40
Section 4: Reusing architecture
Product lines
41
Section 4: Reusing architecture
The product-line process
A software product line is essentially a domain-specific framework. Building and
using a software product line follows a series of stages.
These four stages, which are typically very complex and difficult, establish
the product line from which products can be developed that are tailored to
the needs of individual customers.
42
Section 4: Reusing architecture
For each particular product a further four stages are needed.
5. Specific-requirements capture: specific requirements for the new
product are captured as specialisations and extensions of the domain
model developed in Stage 2.
43
Section 4: Reusing architecture
Summary of section
44
Section 5: Reusing design
45
Section 5: Reusing design
46
Section 5: Reusing design
The customer likes this so much that they ask you to add a facility for
rounded squares as well as ordinary ones (Figure 20).
Luckily another developer has already written a RoundedSquare class for
a different project, so you decide to reuse it. But the RoundedSquare class
has a different interface (Figure 21).
Where Square has the operation draw() the RoundedSquare class has
render().
Of course you could modify the client so it used both operations, but you’d
prefer not to have to do that.
47
Section 5: Reusing design
Figure 22 Adapter
48
Section 5: Reusing design
Note that:
50
Section 5: Reusing design
Interfaces
51
Section 5: Reusing design
The actual implementation of the operations is defined within classes that realize
the interface.
A class can realize multiple interfaces, in which case the class has to declare all
the operations found in all the interfaces, although it may also have additional
operations.
Codifying patterns
The most famous example is the catalogue of design pattern
published by the Gang of Four.
54
Section 5: Reusing design
We will use a template for documenting design patterns which has the
following entries:
◦ Name
◦ Purpose (also called intent)
◦ What problem does it aim to solve?
◦ How it works – a description of the solution
◦ When to use it
◦ Example of use.
55
Section 5: Reusing design
Adapter Pattern
Name. Adapter.
Purpose Allows a client to use a class that has a different interface from
the one the client is expecting.
How it works An Adapter class is introduced that provides the client with the interface it is
expecting but forwards client requests to an object of the class with the
incompatible interface (the Adaptee). The interface the client is expecting is
called the Target. Figure 26 shows the structure. The UML note explains
that the Adapter implements operation1() by forwarding the message
operation2() to an instance of the class being adapted, the Adaptee.
When to use it. When you want to use a class with a client that is expecting a different
interface from the one the class provides.
Example. Legacy software may need to be integrated with a newer system that uses
a different interface.
56
Section 5: Reusing design
57
Section 5: Reusing design
Model-view-controller pattern
Name. Model-view-controller (MVC)
Purpose Splits user interface interaction into three distinct roles: the model of the domain, the
view representing that domain, and the controller of changes to the domain.
How it works It identifies three roles.
• The first is the model, corresponding to an object with some information about the
domain. The model contains data and behaviour and is not directly accessible to the
user. If we consider MVC as a layered architecture the model resides in the application
domain (or business) layer.
• The view is the representation of the model in the user interface: it displays the output
from the system and is what the user perceives of the model’s state. Both the viewer and
the controller reside in the presentation layer, the layer responsible for user dialogue
aspects.
• The controller handles all user inputs that affect the model. The controller also resides in
the presentation layer.
• User inputs to the controller cause changes to the model’s state, which in turn are
reflected in the view (see Figure 29).
• Although the view and the controller are distinct roles, it is important to understand that
they are not always represented by different objects. For example, a tick box shows the
status of some setting, making it part of the view, but it also lets the user change the
setting, making it also part of the controller. ◦ This tight integration is typical of many
frameworks used for building user interfaces. In Java Swing, for example, visual
components are typically used for both input and output.
58
Section 5: Reusing design
Model-view-controller pattern
When to use it When you have a user interface that you want kept separate from the
model. The advantages of this include the following.
59
Section 5: Reusing design
In the design pattern the component that does the processing – corresponding to
the clockwork (the interlocking gearwheels and so on in a mechanical clock) – is
called the model.
The part the user sees is called the view.
A third component is the controller, which corresponds to the controls that are
used to set the clock to the correct time.
Put together, these three make up the Model-view-controller pattern.
60
Section 5: Reusing design
61
Section 5: Reusing design
62
Section 5: Reusing design
63
Section 5: Reusing design
Observer Pattern
Many online forums allow you to subscribe to them and receive an email
notification whenever a new forum post is made. This is an example of the
behavioural design pattern called Observer.
An observer registers to receive notifications whenever the state of an observable
(usually called the subject) changes (Figure 31).
You should be able to see that this pattern is closely related to the notification
architectural style.
64
Section 5: Reusing design
Observer pattern
Name. Observer (also sometimes known as publish–subscribe like the notification
architectural style which it resembles).
Purpose When partitioning a system into individual classes you want the coupling between
them to be loose so you have the flexibility to vary them independently. But a
mechanism is needed to ensure that when the state of an object changes related
objects are updated to keep them in step.
How it works One object has the role of the subject (or publisher) and one or more other objects the
role of observers (or subscribers). The observers register themselves with the subject
and if the state of the subject changes the observers are notified and can then update
themselves.
There are two variants of this pattern. In the push model the subject sends the
observers detailed information about the change that has occurred. In the pull model
the subject simply notifies the observers that there has been a change and it is the
responsibility of the observers to find out the details they need to update themselves.
The structure of the pattern is shown in Figure 32. The Subject and the Observer are
interfaces that are implemented by the corresponding concrete classes.
When the state of the subject changes the observer is sent an update() message. The
implementation of the update() operation in the ConcreteObserver is then responsible
for taking appropriate action to update the Observer.
65
Section 5: Reusing design
Observer pattern
When to use it When different parts of a system have to be kept in step
with one another without being too tightly coupled.
Example. As noted, the relationship between the view and the model in an MVC
design can be realised by applying the observer pattern. The view registers
with the model and is notified every time the model’s state changes,
allowing it to update itself to reflect the change.
Singleton pattern
The Singleton pattern is used where there should only be one instance of
a class.
◦ An example would be the strategy of implementing use cases by having all
messages from the user interface sent to a single object that is an instance of a
central class.
◦ Having more than one instance of this class at once might cause problems, for
example they might interfere with one another.
◦ It’s similar to the idea that a company should only have one chief executive.
67
Section 5: Reusing design
Singleton pattern
Name. Singleton.
Purpose In many cases only a single instance of a class is required and allowing
creation of more than one instance would compromise the design of the
system.
How it works • The Singleton class provides no public operation for creating instances.
Instead it defines a public operation getInstance() that lets clients
access the unique instance of the class.
• One way to implement this is shown in Figure 34. The «singleton»
stereotype denotes a Singleton class. Singleton is responsible for
creating its own unique instance and no other class should be able to
create an instance, so the create() operation is private.
Singleton pattern
When to use it. When there must be only one instance of a class. Often this is associated
with some global resource that other classes need access to.
Example. Figure 35 illustrates the application of the singleton pattern to the design of
a media manager in a multimedia application. There should be only one
instance of the manager, which is created by the MediaManager class
itself the first time a client accesses the manager. This strategy of creation
on demand is called lazy instantiation.
• Notice only the operation getManager() is public. The attribute manager
and the operation create() are declared as private, so other classes
have no direct access to them
Factory pattern
The name is taken from real-life factories, which are facilities dedicated to
manufacturing products required by their clients.
In the design pattern the object the factory produces is called the product.
Some quality requirements that the Factory pattern might help satisfy are
maintainability and portability (and flexibility if it is counted as distinct from
maintainability).
There are two types of factory patters: Simple factory pattern and Factory
method pattern.
70
Section 5: Reusing design
Factory pattern
Name. Factory.
Purpose If the creation and initialization of an object is complex and liable to
change, making clients responsible for the task introduces an
undesirable level of coupling. Encapsulating the creation in a
dedicated factory class hides the details from the client and reduces
the coupling.
How it works • The structure is shown in Figure 36. The client has a dependency, shown
by a dashed line, on the factory for the creation of the product, and the
factory depends on the Product class to create one of its instances. The
UML stereotype «create» indicates that the dependency between Factory
and Product is at object creation. This expresses the fact that the factory
must know what class to instantiate.
• The factory is often a singleton, as in Figure 36. Having a single instance
and making it available through a system-wide access point makes it
possible for all clients that require the product to use the same factory and
avoid duplicated code.
71
Section 5: Reusing design
Factory pattern
When to use Whenever object creation and initialization is complex or depends
it. on information that clients may not know or is likely to change.
Example. Many applications need to use a database management system
(DBMS) for storage. A DBMS is an independent program that
applications communicate with using a particular protocol. A
suitable object can handle the communications but needs to be
created and configured correctly for the DBMS concerned. A
connection factory can provide the required object without the client
application needing to know any details.
The Factory Method pattern develops the idea of a factory further and
reduces coupling to the minimum possible.
A client can use the factory and then the product via interfaces, without
knowing the actual classes of the objects involved.
73
Section 5: Reusing design
74
Section 5: Reusing design
75
Section 5: Reusing design
76
Section 5: Reusing design
Summary of Section
In this section you were introduced to design patterns, which are reusable solutions
to problems at a more detailed level.
You first met the Adapter pattern, which addresses the common problem of an
object having a different interface from the one expected by another object.
Many catalogues of different patterns have been produced, dealing with different
aspects of software development.
The most famous example is the catalogue of design pattern published by the
Gang of Four. This catalogued 23 design patterns in three categories: creational,
structural and behavioural.
You learned about a simplified form of the template the Gang of Four introduced for
describing design patterns and saw it applied to Adapter, which is a structural
pattern.
Other very common design patterns include the Model-view-controller (MVC)
pattern, the Observer pattern, which is behavioural, and the Singleton and Factory
patterns, which are creational.
You also learned of some relationships between different design patterns: for
instance in the Factory pattern the factory is often a singleton.
77
Unit Summary
78