Architecture Patterns: Software Architecture in Practice Chapter 13
Architecture Patterns: Software Architecture in Practice Chapter 13
Architecture
Patterns
S O F T WA R E A R C H I T E C T U R E I N P R A C T I C E C H A P T E R 1 3
Topics
What is a Pattern?
Pattern Catalog
◦ Module patterns
◦ Component and Connector Patterns
◦ Allocation Patterns
Architectural Styles (Patterns)
Patterns – a Review
Work on software patterns stemmed from work on patterns for building
architecture carried out by Christopher Alexander (
A Pattern Language: Towns, Buildings, Construction (1977))
How do you think about software design? Essentially the same cognitive
process for architecture design …
◦ Requirements driven, separation of concerns, top-down, apply patterns
Describing a Pattern Solution
A pattern solution is determined and described by:
◦ A set of element types (for example, data repositories, processes, and
objects)
◦ A set of interaction mechanisms or connectors (for example, method calls,
events, or message bus)
◦ A topological layout of the components
◦ A set of semantic constraints covering topology, element behavior, and
interaction mechanisms
◦ I.e., views
Team 1 – Broker
Team 2 – Event Driven
Team 3 – Publish-Subscribe
Team 4 – Pipe-and-Filter
Team 5 – Map-Reduce
Team 6 – Microservices
Layer Pattern
Context: Complex systems need to develop and evolve portions of the
system independently. Developers need well-documented separation
of concerns, so system modules may be independently developed and
maintained.
Problem: The software needs to be segmented in such a way that the
modules can be developed and evolved separately with little
interaction among the parts, supporting portability, modifiability, and
reuse.
Solution: To achieve this separation of concerns, the layered pattern
divides the software into units called layers. Each layer is a grouping of
modules that offers a cohesive set of services. The usage must be
unidirectional. Layers completely partition a set of software, and each
partition is exposed through a public interface.
Layer Pattern Example
UML Package Notation for
Layer Diagrams
A
structures.
<<uses>>
C
Business IT Example
Change notification
State query
Receives model data Encapsulates application
Requests model data functions and data
Presents view Invocations
Events
MVC Solution - 1
Overview: The MVC pattern breaks system functionality into three
components: a model, a view, and a controller that mediates
between the model and the view.
Elements:
◦ The model is a representation of the application data or state, and it
contains (or provides an interface to) application logic.
◦ The view is a user interface component that either produces a
representation of the model for the user or allows for some form of user
input, or both.
◦ The controller manages the interaction between the model and the view,
translating user actions into changes to the model or changes to the view.
MVC Solution - 2
Relations: The notifies relation connects instances of model,
view, and controller, notifying elements of relevant state
changes.
Constraints:
◦ There must be at least one instance each of model, view, and controller.
◦ The model component should not interact directly with the controller.
Weaknesses:
◦ The complexity may not be worth it for simple user interfaces.
◦ The model, view, and controller abstractions may not be good fits for
some user interface toolkits.
Pipe and Filter Pattern
Context: Many systems are required to transform streams of discrete data
items, from input to output. Many types of transformations occur repeatedly in
practice, and so it is desirable to create these as independent, reusable parts.
Problem: Such systems need to be divided into reusable, loosely coupled
components with simple, generic interaction mechanisms. In this way they can
be flexibly combined with each other. The components, being generic and
loosely coupled, are easily reused. The components, being independent, can
execute in parallel.
Solution: The pattern of interaction in the pipe-and-filter pattern is
characterized by successive transformations of streams of data. Data arrives at
a filter’s input port(s), is transformed, and then is passed via its output port(s)
through a pipe to the next filter. A single filter can consume data from, or
produce data to, one or more ports.
Pipe and Filter Example
Pipe and Filter Example
Pipe and Filter Solution
Overview: Data is transformed from a system’s external inputs to its external outputs through a
series of transformations performed by its filters connected by pipes.
Elements:
◦ Filter, which is a component that transforms data read on its input port(s) to data written
on its output port(s).
◦ Pipe, which is a connector that conveys data from a filter’s output port(s) to another filter’s
input port(s). A pipe has a single source for its input and a single target for its output. A
pipe preserves the sequence of data items, and it does not alter the data passing through.
Relations: The attachment relation associates the output of filters with the input of pipes and
vice versa.
Constraints:
◦ Pipes connect filter output ports to filter input ports.
◦ Connected filters must agree on the type of data being passed along the connecting pipe.
Client-Server Pattern
Context: There are shared resources and services that large numbers
of distributed clients wish to access, and for which we wish to control
access or quality of service.
Problem: By managing a set of shared resources and services, we can
promote modifiability and reuse, by factoring out common services
and having to modify these in a single location, or a small number of
locations. We want to improve scalability and availability by
centralizing the control of these resources and services, while
distributing the resources themselves across multiple physical servers.
Solution: Clients interact by requesting services of servers, which
provide a set of services. Some components may act as both clients and
servers. There may be one central server or multiple distributed ones.
Client-Server Example
ATM Banking System
Client-Server Solution - 1
Overview: Clients initiate interactions with servers, invoking services
as needed from those servers and waiting for the results of those
requests.
Elements:
◦ Client, a component that invokes services of a server component. Clients have
ports that describe the services they require.
◦ Server: a component that provides services to clients. Servers have ports that
describe the services they provide.
Request/reply connector: a data connector employing a request/reply
protocol, used by a client to invoke services on a server. Important
characteristics include whether the calls are local or remote, and
whether data is encrypted.
Client-Server Solution- 2
Relations: The attachment relation associates clients with servers.
Constraints:
◦ Clients are connected to servers through request/reply connectors.
◦ Server components can be clients to other servers.
Weaknesses:
◦ Server can be a performance bottleneck.
◦ Server can be a single point of failure.
◦ Decisions about where to locate functionality (in the client or in the server)
are often complex and costly to change after a system has been built.
Peer-to-Peer Pattern
Context: Distributed computational entities—each of which is
considered equally important in terms of initiating an interaction and
each of which provides its own resources—need to cooperate and
collaborate to provide a service to a distributed community of users.
Problem: How can a set of “equal” distributed computational entities
be connected to each other via a common protocol so that they can
organize and share their services with high availability and scalability?
Solution: In the peer-to-peer (P2P) pattern, components directly interact
as peers. All peers are “equal” and no peer or group of peers can be
critical for the health of the system. Peer-to-peer communication is
typically a request/reply interaction without the asymmetry found in the
client-server pattern.
Peer-to-Peer Example
Gnutella Network
Peer-to-Peer Solution - 1
Overview: Computation is achieved by cooperating peers that request
service from and provide services to one another across a network.
Elements:
◦ Peer, which is an independent component running on a network node. Special
peer components can provide routing, indexing, and peer search capability.
◦ Request/reply connector, which is used to connect to the peer network,
search for other peers, and invoke services from other peers. In some cases,
the need for a reply is done away with.
Relations: The relation associates peers with their connectors.
Attachments may change at runtime.
Peer-to-Peer Solution - 2
Constraints: Restrictions may be placed on the following:
◦ The number of allowable attachments to any given peer
◦ The number of hops used for searching for a peer
◦ Which peers know about which other peers
◦ Some P2P networks are organized with star topologies, in which peers only connect to supernodes.
Weaknesses:
◦ Managing security, data consistency, data/service availability,
backup, and recovery are all more complex.
◦ Small peer-to-peer systems may not be able to consistently
achieve quality goals such as performance and availability.
Service Oriented Architecture
Pattern
• Context: A number of services are offered (and
described) by service providers and consumed by service
consumers. Service consumers need to be able to
understand and use these services without any detailed
knowledge of their implementation.
Problem: How can we support interoperability of
distributed components running on different platforms and
written in different implementation languages, provided by
different organizations, and distributed across the Internet?
Solution: The service-oriented architecture (SOA) pattern
describes a collection of distributed components that
provide and/or consume services.
Service Oriented Architecture Example
“Adventure Builder”
http://www.enterpriseintegrationpatterns.com/patterns/messaging/PublishSubscribeChannel.html
Publish-Subscribe Solution –
1
Overview: Components publish and subscribe to events. When an
event is announced by a component, the connector infrastructure
dispatches the event to all registered subscribers.
Elements:
◦ Any C&C component with at least one publish or subscribe port.
◦ The publish-subscribe connector, which will have announce and listen roles
for components that wish to publish and subscribe to events.
Relations: The attachment relation associates components with the
publish-subscribe connector by prescribing which components
announce events and which components are registered to receive
events.
Publish-Subscribe Solution - 2
Constraints: All components are connected to an event distributor that
may be viewed as either a bus—connector—or a component. Publish
ports are attached to announce roles and subscribe ports are attached
to listen roles.
Weaknesses:
◦ Typically increases latency and has a negative effect on scalability and
predictability of message delivery time.
◦ Less control over ordering of messages, and delivery of messages is not
guaranteed.
Shared-Data Pattern
Context: Various computational components need to share
and manipulate large amounts of data. This data does not
belong solely to any one of those components.
Problem: How can systems store and manipulate persistent
data that is accessed by multiple independent components?
Solution: In the shared-data pattern, interaction is
dominated by the exchange of persistent data between
multiple data accessors and at least one shared-data store.
Exchange may be initiated by the accessors or the data store.
The connector type is data reading and writing.
Shared Data Example
Shared Data Example
Enterprise Access Management System
Data Warehouse Example
Relations:
◦ Is part of, to group components into tiers.
◦ Communicates with, to show how tiers and the components they contain interact
with each other.
◦ Allocated to, in the case that tiers map to computing platforms.