TM354 Unit9 Lecture Slides
TM354 Unit9 Lecture Slides
TM354 Unit9 Lecture Slides
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
6
Section 2 : Architecture
Figure 3 shows the very different architecture used by Skype, a well-known
internet telephony service.
7
Section 2 : Architecture
8
Section 2 : Architecture
9
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 emphasise being adaptive and delaying
decisions for as long as possible.
10
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.
11
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.
13
Section 2 : Architecture
Architectural views
Architectural views proposed by Kruchten (Kruchten, 2004) Bass et al. (2003) present a slightly different set, although
- a ‘4+1 model’ they are essentially equivalent to Kruchten’s.
The logical (or functional) view describes the The module view corresponds to the logical view in
system’s main functional elements and their the 4+1 model.
interactions – broadly, the services the system must
provide to users.
The process view describes the set of independently The component and connector view is similar to the
executing processes that will exist at run-time and the process view in the 4 +1 model, with the independent
communication between them. processes being regarded as components and the
communications between them modelled by
connectors.
The physical (or deployment) view describes how the
system will be deployed to an operating environment in The allocation view describes all the mappings
terms of the physical computers and networks on which between the software and the external environment in
the system will run. the widest sense and roughly corresponds to a
combination of the physical and development view in
The development view describes how the software the 4+1 model.
will be split into subsystems that can be allocated to
teams of developers.
14
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
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
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.
15
Section 2 : Architecture
Views The views should be intelligible to stakeholders and should allow them to
see how the architecture deals with their concerns and how the architect
has balanced the claims of competing concerns by suitable
compromises.
16
16
Section 2 : Architecture
17
17
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.
18
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.
19
Section 3: Reuse
20
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.
21
Section 4: Reusing architecture
Architectural styles
22
Section 4: Reusing architecture
1. Client–server
23
Section 4: Reusing architecture
2. Call-return
24
Section 4: Reusing architecture
3. Layered Examples:
A compiled Java program, which
The essence of a layered style is executes in a Java virtual machine
that the system is structured as a that in turn makes calls to services
series of layers that are supplied by the operating system.
visualised as stacked on top of
another.
A client–server architecture, in
Each layer uses services provided
which there are just the two layers
by the layers below (usually just by and the connector takes the form of
the layer immediately below). It also a request and response, often over
supplies services to the layer a network.
above.
25
Section 4: Reusing architecture
26
Section 4: Reusing architecture
4. Peer-to-peer
Example
◦ Streaming music service, where listeners
generally get streamed tracks from the nearest
peer that can be located by sending a request that
hops from one peer to another until the desired
track is located.
The peer-to-peer style is illustrated in Figure 12 Peer-to-peer architectural style
Figure 12.
27
Section 4: Reusing architecture
5. 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.
There are two forms of the data-centred style (see Figures 14(a) and (b)):
◦ If communication is always initiated by clients and the store simply responds to requests it is called
database or repository. Typically the components are a database server and clients that access it. The
connectors are database queries made via a special database connection. A database holding
personnel records is an example of this form, with authorised users being able to log on and submit
queries.
◦ A variant in which the store is active and informs users of changes, so that communication may be
initiated from either end, is termed a blackboard.
29
Section 4: Reusing architecture
There are two forms of the data-centred style (see Figures 14(a) and (b)):
◦ If communication is always initiated by clients and the store simply responds to requests it
is called database or repository. Typically the components are a database server and
clients that access it. The connectors are database queries made via a special database
connection. A database holding personnel records is an example of this form, with
authorised users being able to log on and submit queries.
◦ A variant in which the store is active and informs users of changes, so that communication
may be initiated from either end, is termed a blackboard.
30
Section 4: Reusing architecture
7. Independent components
31
Section 4: Reusing architecture
8. Service-oriented
32
Section 4: Reusing architecture
33
Section 4: Reusing architecture
9. Notification
(also known as implicit invocation or publish– subscribe)
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.
◦ Examples:
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.
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.
34
Section 4: Reusing architecture
In publish–subscribe there
tend to be many subscribers
for each publisher.
The connectors are either
procedure calls or
messages transmitted via
intermediate software such
as a messaging system or a
run-time system like the
Java virtual machine. Figure 17 Publish–subscribe architectural style
35
Section 4: Reusing architecture
Reuse of Frameworks and Product Lines
36
Section 4: Reusing architecture
37
Section 4: Reusing architecture
Summary of section
38
Section 5: Reusing design
39
Section 5: Reusing design
Where Square has the operation draw() the RoundedSquare class has render()
The solution is to introduce an Adapter class, which extends Square but has a
RoundedSquare attribute, shown as rs : RoundedSquare in Figure 22.
Figure 22 Adapter
40
Section 5: Reusing design
41
Section 5: Reusing design
42
Section 5: Reusing design
Interfaces
43
Section 5: Reusing design
44
Section 5: Reusing design
45
Section 5: Reusing design
Codifying patterns
The most famous example is the catalogue of design pattern
published by the Gang of Four.
46
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.
47
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.
48
Section 5: Reusing design
49
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.
50
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.
51
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.
These are the working parts of a clock but without any clock face or hands. Clock builders
can then add their own clock dial, so a whole range of different clocks can be constructed
that all use an identical design for the clockwork (see Figure 28).
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.
53
Section 5: Reusing design
54
54
Section 5: Reusing design
◦ The same domain logic can be used with different user interfaces.
◦ The business logic can be tested separately from the interface logic.
55
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 (see Figure 31).
You should be able to see that this pattern is closely related to the notification
architectural style.
56
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 extreme 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.
57
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.
59
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
62
Section 5: Reusing design
Factory pattern
Name. Factory.
Purpose If the creation and initialisation 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.
63
Section 5: Reusing design
Factory pattern
When to use Whenever object creation and initialisation 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.
65
Section 5: Reusing design
66
Section 5: Reusing design
67
Section 5: Reusing design
68
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.
69
Unit Summary
70