TM354-Unit10 Lecture Slides
TM354-Unit10 Lecture Slides
1
In this unit, you will continue exploring how reuse can
contribute to more productive software development.
Note that: All SAQs and Exercises in this unit are required.
2
Section 1: Introduction
3
Section 1: Introduction
This raises the question of what principles software architects can follow
to ensure that various types of quality requirement are met.
◦ For each type of attribute we can describe a set of tactics: reusable
solutions to the problem of achieving particular qualities.
4
Section 2 : Components and interfaces
5
Section 2 : Components and interfaces
6
Section 2 : Components and interfaces
2.2 Interfaces
7
Section 2 : Components and interfaces
8
Section 2 : Components and interfaces
9
Section 2 : Components and interfaces
10
Section 2 : Components and interfaces
Example 1
Figure 5 shows a catalogue component offering a number of services, including some support
for browsing the catalogue and searching for particular products.
Assuming a client can browse alphabetically or by category of product, and search by entering
a keyword, we could specify the provided interfaces of the component as shown in Figure 6.
11
Section 2 : Components and interfaces
12
Section 2 : Components and interfaces
13
Section 2 : Components and interfaces
Exercise 1
What would the assume–guarantee contract for a component include and how
do the assume and guarantee relate to the component’s provided and required
interfaces?
Solution
The contract for a component would be:
1. the pre- and post condition of all the operations in the provided interface of the
component
2. the invariants that apply to any publicly visible properties of the component
3. the required interface of the component and all the assumptions of the required
interface
4. any other assumptions about the environment in which the component will
operate.
The assume would be the preconditions of the operations, and items 3 and 4 of the
contract above.
The guarantee would be the post condition of the operations and item 2 of the
contract above.
14
Section 2 : Components and interfaces
Exercise 2
Suppose component X is replaced by component Y, which has different
assumptions and guarantees from X. Drawing on your knowledge of design by
contract (DbC) suggest what restrictions must apply to the assume and
guarantee if Y is to be an acceptable replacement for X. Illustrate your answer
with an example.
Solution
The assumptions made by Y must be the same as those made by X, or weaker. The
guarantee Y makes must be the same as the one X makes, or stronger. In other
words Y must not demand more, or deliver less, than X.
For example X might accept up to a million items and promise to process them with
99 per cent accuracy. If Y restricts the maximum to half a million items it is
demanding more. If it promises only 90 per cent accuracy it is delivering less.
15
Section 2 : Components and interfaces
Interacting components
16
Section 2 : Components and interfaces
For example we might want to reuse items of legacy software rather than
go to the expense of replacing them.
In these cases it is possible to write an adapter that gives the software a
provided and required interface.
17
Section 2 : Components and interfaces
18
Section 3 : Service-oriented architecture
3.1 Services
19
Section 3 : Service-oriented architecture
Similarities
• have well defined interfaces which specify how other software can
interact with them
• aim to be loosely coupled, by not exposing details of their
implementation, thus allowing it to be changed without disturbing other
parts of the system
• can be composed – services can be combined to build up more
complex functionality
• aim to be reusable, so that the same service can be used as part of
many different applications.
20
Section 3 : Service-oriented architecture
• Services are discoverable. Clients can access a repository to find details of available
services.
• Components run on computers controlled by the organization using them and if many
organizations use a component it executes in multiple locations. A service in contrast
resides on a provider server, typically owned by a different organization, and executes at a
single end-point that all clients communicate with.
21
Section 3 : Service-oriented architecture
22
Section 3 : Service-oriented architecture
23
Section 3 : Service-oriented architecture
The consumer.
The service. Each service has a service description that specifies how the
client can interact with it in addition to the signature of the service.
The provider, which is the platform on which the service is implemented. It
accepts and executes requests from clients.
The registry (or locator) which allows clients to find services.
The service description for each service is published in the registry by the
service provider.
A consumer queries the registry, to find the details of a particular service or
to discover a service that meets given criteria.
The registry provides the consumer with the service description and
information that allows it to bind to the service and invoke its operations.
24
Section 3 : Service-oriented architecture
Kinds of service
The discussion in this subsection and the following one are based on
Sommerville (2011).
25
Section 3 : Service-oriented architecture
26
Section 3 : Service-oriented architecture
Composing an application
27
Section 3 : Service-oriented architecture
28
Section 3 : Service-oriented architecture
Advantages of SOA
Service-oriented architecture offers a number of potential advantages
including the following:
• Agile and flexible response. SOA supports a flexible business model that can
respond quickly to changes in customers’ requirements, new business
opportunities or competitive threats. Developers can quickly assemble new
applications by combining existing services.
• Less duplication. If several parts of a business require the same function, it can
be packaged as a service and made available for reuse.
• Integration of legacy applications. Legacy software can be wrapped as a
service and made to interoperate with other applications.
• Use of third-party services. Systems can easily incorporate functions, for
example credit card validation or online payment, provided as services by external
suppliers.
• Language independence. Services written in different languages can
interoperate using standard protocols.
29
Section 3 : Service-oriented architecture
You next learnt about the ‘find, bind and invoke’ cycle.
You saw that services can be classified into three types: utility services,
business services and coordination services, and further classified as task
orientated or entity-orientated.
30
Section 4: Architecture, quality attributes and tactics
31
Section 4: Architecture, quality attributes and tactics
The source is a human actor, another system, or anything else that can
generate a stimulus.
The stimulus is any kind of event or request.
The artefact is what will respond to the stimulus. It might be a running
component or service if we are considering performance for example, but
it could be code or documentation if we are interested in maintainability.
The environment specifies the conditions which the artefact will be
operating under. For instance if we are concerned with performance the
environment might be either ‘normal operation’ or ‘overloaded’.
The response is what happens as a result of the artefact receiving the
stimulus.
The response measure is an objective yardstick by which we can test if
the requirement has been met.
32
Section 4: Architecture, quality attributes and tactics
For a given attribute we can list what types of value can occur for each of the six
parts. Table 2 shows the possibilities, including sample metrics, that Bass et al.
give for performance.
33
Section 4: Architecture, quality attributes and tactics
34
Section 4: Architecture, quality attributes and tactics
Periodic
◦ Anything that occurs regularly, for example information sent at the same
time each day from a weather station, or status information sent every
minute from a spacecraft.
Sporadic
◦ Messages sent to an address for reporting problems, or signals from a
device monitoring earth tremors.
Bursty
◦ Search queries about a suddenly popular topic, or signals from a device
reporting lightning strikes in a particular area.
35
Section 4: Architecture, quality attributes and tactics
36
Section 4: Architecture, quality attributes and tactics
Bass et al. (2003, 2012) have led the way in introducing tactics as a form
of reuse and describing tactics for a representative range of quality
attributes, although tactics can be described for any attribute.
Here we have space to consider only two examples. The ones we chose
are performance and flexibility.
37
Section 4: Architecture, quality attributes and tactics
38
Section 4: Architecture, quality attributes and tactics
39
Section 4: Architecture, quality attributes and tactics
◦ If deadline is the measure then each task must have a priority and the
scheduler must ensure that higher-priority tasks are dealt with first.
40
Section 4: Architecture, quality attributes and tactics
41
Section 4: Architecture, quality attributes and tactics
42
Section 4: Architecture, quality attributes and tactics
43
Section 4: Architecture, quality attributes and tactics
44
Section 4: Architecture, quality attributes and tactics
◦ The longer we can delay any binding, the more flexible the system will be, because a
different choice remains available. Examples:
◦ Object-oriented programming languages typically allow the class of the object to which a
variable is bound to be decided at run-time, making it possible to vary behavior by
replacing an object of one class by one belonging to a different class.
◦ Instead of the code of a user interface binding it to a particular look and feel, the look and
feel can be decided at run-time from a configuration file, which can be changed as
required.
45
Section 4: Architecture, quality attributes and tactics
In this section you learnt about the six-part model for quality attribute scenarios.
You saw that for a given quality attribute we can make a list of the general
possibilities for each part of the model and then, to express a particular
nonfunctional requirement, we choose an appropriate value for each part of the
scenario.
Tactics for quality attributes are reusable solutions to the problem of achieving
particular qualities.
You saw detailed examples of tactics for two example attributes – performance
and flexibility.
You learnt that the main tactics for performance are managing demand, managing
system capacity, and matching resources to demand.
The main tactics for flexibility are minimizing coupling, maximising cohesion,
keeping modules small, and delaying binding for as long as possible.
46
Section 5: Putting it all together – enterprise architecture
Finally we explore one possible architecture for the hotel system, showing
how a single enterprise application created within Java EE can contain
examples of many of the reusable styles and patterns
47
Section 5: Putting it all together – enterprise architecture
48
Section 5: Putting it all together – enterprise architecture
J2SE (Java 2 Platform, Standard Edition): The standard Java language, which
Java EE is built on top of.
EJB (Enterprise JavaBeans): A technology for reusable server-side business
components, called enterprise beans.
The range of services Java EE provides for EJBs includes persistence,
distribution, security and transaction processing.
Servlets, JSF (JavaServer Faces) and JSP (JavaServer Pages): Technologies
for constructing web pages and serving them to clients on demand.
JPA (Java Persistence API): A technology for accessing relational databases.
JMS (Java Message Service). A technology enabling software components to
communicate asynchronously with low coupling.
JAX-WS (Java API for XML Web Services) and JAX-RS (Java API for RESTful
Web Services: Technologies for providing services that can be accessed over the
internet.
JavaMail: A technology for sending email messages.
49
Section 5: Putting it all together – enterprise architecture
50
Section 5: Putting it all together – enterprise architecture
51
Section 5: Putting it all together – enterprise architecture
The web container and the EJB container are normally part of the platform
supplied by an enterprise server, such as Oracle's GlassFish Server.
◦ A browser just means one of the common web browsers, such as Firefox or Chrome, that
can send requests to a web server and display the response.
52
Section 5: Putting it all together – enterprise architecture
The code in this section and the next is just so that you can get a feeling
for how components and services might be implemented in practice. You
are not expected to remember the details.
53
Section 5: Putting it all together – enterprise architecture
These are the standard HTTP (hypertext transfer protocol) methods, used
by web browsers to communicate with web servers.
54
Section 5: Putting it all together – enterprise architecture
The browser, unlike the EJB client, is not aware of the Java technology used at
the server end. It simply sends a request and receives a response, using standard
protocols.
55
Section 5: Putting it all together – enterprise architecture
Example:
Read the following information about the hotel system and then sketch on
paper a possible way of building it as a Java EE application, showing
what components would be involved, what containers they would run in
and what the communication is.
◦ The hotel system will require three types of client: web clients connecting via the internet,
desktop applications installed in hotels, and mobile clients using tablet and phone apps
that connect to RESTful web services. Part of the system must deal with the core
business processes, such as reservations, room lettings, billing and so on. The system
will need to maintain persistent data about customers and hotels.
56
Section 5: Putting it all together – enterprise architecture
Solution
57
Section 5: Putting it all together – enterprise architecture
You learnt about the details of a small example of EJB to convert between
two different measures of land area.
You also learnt that Java EE provides support for developing service
providers and saw how the same conversion example that you met in
component form can easily be reprogrammed as a RESTful web service.
58
Unit Summary
59