Software Design Software Design Techniques Techniques: Prof. Luca Dan Serbanati
Software Design Software Design Techniques Techniques: Prof. Luca Dan Serbanati
SOFTWARE DESIGN
TECHNIQUES
2009
Luca Dan Serbanati - Software Design Techniques 2
REVIEW
The scope: to establish The scope: to discover The scope: to identify The scope:
a problem definition the resources required an architecture where 1 Define the internal
1.Define
that will guide the rest by the problem domain. user expectations implementation of each
of the project. For each resource, (security, number of problem domain
define its purpose and users, data and resource.
the interface it supports.
supports processing distribution
distribution, 2.
2 Add the classes that
shared resources, enable the software
response time) could be to support the use of
placed. the resources.
3 Iterate through the
3.
model to enhance and
refine it.
DocumentList
add( )
docid : int
sortByName( )
numField : int
read( )
Openning
FileList
sortFileList( )
fLi t
fList
create( )
fillDocument( )
add( ) close file
delete( )
1
rep
Deployment
File
Repository
diagram
name : char * = 0
read( )
readDoc( )
open( )
readFile( )
create( )
fillFile( )
Collaboration diagram
9: sortByName ( )
Repository DocumentList
Windows9
mainWnd : MainWnd 5
FileManager
1: Doc view request ( )
2: fetchDoc( )
8: fillFile ( )
N
T
3: create ( ) GraphicFile
UNI
ÀÀ¿ë¼-¹ö.EX X
6: fillDocument ( )
E
File FileList
IBM
7: readFile ( ) Mainframe
5: readDoc ( )
document : Document
repository : Repository
µ¥ÀÌŸº£À̽º¼-¹
ö
Component
user
mainWnd fileMgr :
FileMgr
document :
Document
gFile repository
diagram
Target
g
System
2: fetchDoc(
)
3: create (
)
5: readDoc (
)
º¸¿©ÁØ´Ù
.
9: sortByName (
)
Engineering
Sequence
diagram
Luca Dan Serbanati - Software Design Techniques 5
UP: Design
Model
Domain Model
Captured-on Register Catalog
Sale
R l ti
Relations
... 1 1 ... ...
UP: Deriving
the Design
g
Model
Luca Dan Serbanati - Software Design Techniques 8
Design
g Class Diagram
g
Package
g Diagram
g
• UML package diagrams are often used to illustrate the logical architecture of
a system, the layers, subsystems, Java packages, etc.
• A layer can be modeled as a UML package
package.
• A UML package diagram provides a way to group elements: classes, other
packages, use cases, anything. Nesting packages is very common.
Package Dependency Generalization
XX
<<subsystem>>
y
(from XX) (from XX)
global
10
Luca Dan Serbanati – Software Development Methods
Orders Clients
Oracle Interface
<<abstract>>
Database
Interface SQL Server
Interface
A UML package
k represents
t a namespace
11
Nested
ested Package
ac age Diagram
ag a
Order Capturing UI AWT E-mail List UI
E-mail
Application
Order Capturing
Application
Domain
Orders Clients
(from Domain) (from Domain)
<<global>>
l b l
Oracle Interface
<<abstract>>
abstract
Database
Interface SQL Server
Interface
Luca Dan Serbanati - Analisi e progettazione dei sistemi in UML 12
Luca Dan Serbanati - Software Design Techniques 13
Types of Architecture
In the IT industry, the term architecture is used to refer to several things.
From the enterprise point of view, there are four types of architecture:
– Business
B siness architecture.
architect re
– Information technology (IT) architecture.
– Information architecture.
– Application (software) architecture.
Collectively, these architectures are referred to as enterprise architecture.
Luca Dan Serbanati - Software Design Techniques 16
Business Architecture
• Business architecture defines the business strategy, governance,
organization, and key business processes within an enterprise. The field of
business process reengineering (BPR) focuses on the analysis and design
of business processes, not necessarily represented in an IT system. The
business architecture is mapped to the IT architecture
architecture.
Luca Dan Serbanati - Software Design Techniques 17
Information Architecture
• Information architecture includes logical and physical data assets and
data management resources. Information is becoming one of the most
important assets a company has in achieving its objectives, and the IT
architecture must support it.
Luca Dan Serbanati - Software Design Techniques 19
Application
pp Architecture
• Application (software) architecture serves as the blueprint for individual
applications systems, their interactions, and their relationships to the
business processes of the organization. The application architecture is
commonly built on top of and utilizes the services of the IT architecture.
• Application architecting is more than the specification of the internal physical
structure of the software. It involves creating models of the problem in order
to simplify and understand the problem and creating implementation-
independent models of the solution that address those problems
problems, for
example, creating business process workflows and reviewing these with the
end users. It also involves user interface and interaction design.
Luca Dan Serbanati - Software Design Techniques
Software Architecture
Software Architecture = the set of significant decisions about the organization
of a software system, the selection of the structural elements and their
interfaces by which the system is composed, together with their behaviour
as specified
ifi d in
i the
th collaborations
ll b ti among th
those elements,
l t th
the composition
iti off
these structural and behavioural elements into progressively larger
subsystems, and the architectural style that guides this organization these
elements and their interfaces, their collaborations, and their composition
Software architecture presents a view of a software system as components and
connectors.
– Components encapsulate some coherent set of functionality.
– Connectors realize the runtime interaction between components.
The system design achieves certain qualities based on its composition from
components and connectors.
An architecture style defines a family of systems in terms of a pattern of
structural organization
organization. It should contain:
– a vocabulary of components and connector types
– a set of constraints on how they can be combined
– one or more semantic models that specify how a system’s
system s overall
properties can be determined from the properties of its parts.
20
Luca Dan Serbanati - Software Design Techniques 21
Architectural Views
Characteristics
Ch t i ti off a good d architecture:
hit t
– Flexible
– Simple
– Approachable
– Clear separation of concerns
– Balanced distribution of responsibilities
p
– Balances economic and technology constraints.
An architectural view is
a simplified description
(an abstraction) of a Logical View Implementation View
system from a particular
perspective
p p or vantage
g End-user
Programmers
point, covering particular Functionality Software management
concerns, and omitting Use Case
entities that are not View
relevant
l t tto this
thi
perspective. Process View Deployment View
System integrators System engineering
Performance System topology
Scalability Delivery installation
Delivery,
Throughput Communication
Conceptual Physical
Luca Dan Serbanati - Software Design Techniques
Logical
g Architecture
Logical architecture = the large-scale organization of the software classes into
packages (or namespaces), subsystems, and layers (“logical” because
there's
there s no decision about how these elements are deployed across different
operating system processes or across physical computers in a network.
These latter decisions are part of the deployment architecture).
L
Layer = a very coarse-grained
i d grouping
i off classes,
l packages,
k or subsystems
b t
that has cohesive responsibility for a major aspect of the system. Also,
layers are organized such that "higher" layers (such as the UI layer) call
upon services of "lower" layers, but not normally vice versa.
Typically layers in an OO system include:
– User Interface.
Interface
– Application Logic and Domain Objects software objects representing
domain concepts that fulfill application requirements.
– Technical Services general purpose objects and subsystems that provide
supporting technical services, such as interfacing with a database or
error logging.
logging These services are usually application-independent
application independent and
reusable across several systems.
22
A logical architecture doesn't have to be organized in layers.
Luca Dan Serbanati - Software Design Techniques 23
This view captures how the This view captures how This view represents the
management views the software
ft engineers
i view
i software
ft development
d l t lif
life cycle
l
development life cycle (it is the development life cycle. from the perspective of
seen outside of engineering) architecting concerns, activities,
and artifacts.
Luca Dan Serbanati - Software Design Techniques 24
Representing
p g Design
g Elements ((I))
• Design Elements Representation = A baseline
decomposition that splits the system based on
functional requirements is initially (during the
predesign phase) established.
• The decomposition can be modeled using a design
structure matrix (DSM),
(DSM) which represents the
dependencies between design elements without
prescribing the granularity of the elements.
• The architecture of a software application is often
represented as a set of interconnected modules or
subsystems, often called components. These
modules are organizational constructs that
structure source code, but often are not directly
visible in the source code.
• Source code is an abstraction of machine
instructions and data patterns structured in terms
of a programming language's grammar.
• This physical view of a software application can be
viewed from an even higher-level set of
components called software modules.
Luca Dan Serbanati - Software Design Techniques 26
Representing
p g Design
g Elements ((II))
• Modules are discrete units of software (binary and source). They have high
internal cohesion and low external coupling.
• Components and connectors describe the physical instantiation of a system
and are run-time instantiations of modules.
• A module may contain several component definitions. The client module
may contain many class definitions for various user interface components
components.
UML Packages Design Structure Matrix (DSM)
Luca Dan Serbanati - Software Design Techniques 27
Evaluating
g the Architecture
• The Architectural Design Evaluation = Determine if the system satisfies the
architectural requirements. The design is evaluated in order to gather
qualitative measures or quantitative data
data, both of which are metrics.
metrics Each
metric is then compared to the quality attribute requirements.
• It is not enough to say "the system must be fast" or "the system must be
easy to modify or adapt to customer needs." These statements may be
acceptable in an initial requirements list, but they are not specific enough to
evaluate the designg against.
g Such requirements must first be articulated as
specific quality attributes and their acceptable values.
• A performance quality attribute will usually be stated as some numeric range
or set of ideal numbers
numbers, but most quality attributes are not quantitative in
nature so their values may not be numeric. For instance, a modifiability
requirement may be reified as a scenario called a change case.
Luca Dan Serbanati - Software Design Techniques 29
Architectural Views
• Models may be classified by or organized into viewsviews.
• An Architectural View is a representation of a system from the perspective
of a related set of concerns (e.g. a concern in a distributed system is how
the software components are allocated to network nodes)nodes). This
representation is comprised of a set of system elements and the
relationships associated with them.
• Views are aspects or dimensions of an architectural model. A view can
contain either problem domain models or solution domain models.
• The types of the elements and the relationships as well as other meta-
information on the views are described by y the Viewpoint
p in order to
document and communicate views unambiguously.
• Views are instances of viewpoints because the elements and relationships
contained in the View are instances of the corresponding types of elements
and relationships contained in the Viewpoint.
An Architectural Pattern defines types of
elements and relationships that work together in
order to solve a particular problem from some
perspective. It is a specialization of a viewpoint
since it provides specialized semantics to the
types of elements and relationships, as well as
constraints upon them.
Luca Dan Serbanati - Software Design Techniques 32
Architectural Views
– Objectives/purpose describes what is needed.
– Behavior/function describes what the system does to satisfy the
objectives (it is compulsory for information systems).
– Information/data describes the information created by and retained in
the system (it is compulsory for information systems).
– Form/structure describes the physical structure of the software (for
example, modules and components).
– Performance describes how effectively the system performs its
functions.
• Other views can be added for more recent systems:
– Deployment view,
– User and external systems interaction view
view,
– Technological view, how commercial or standard technologies are used
• The architect must determine which views are most critical to the software
system's success.
Luca Dan Serbanati - Software Design Techniques 33
Behavioral/Functional Models
• Functional or behavioral models specify what the system does. These
models are a response to the functional objectives in the objectives models.
• In modern software development, we usually only start with a partially
specified behavior model because we usually do not have a complete set of
fully
y defined requirements
q and objectives
j before design
g begins.
g
• This is why we promote iterative refinement of requirements and system
design. We create models of the target system, and we test or measure
these models against the desired quality attributes
attributes.
• There are several kinds of behavioral models:
– User interface prototypes
p yp
– Scenarios and threads
– State transition diagrams
– Process models .
Luca Dan Serbanati - Software Design Techniques 35
ARCHITECTURAL STYLES
AND PATTERNS
Luca Dan Serbanati - Software Design Techniques 36
Architectural
c tectu a p
Architectural
process
ocess = A seque
sequence
ce o
of act
Design
activities
t es tthat
at lead
ead to tthe
epproduction
oduct o oof
architectural artifacts: a software architecture description and an architectural
prototype. In order to carry out this process:
Identify, select, and validate “architecturally significant” elements. Not
everything is architecture, but the followings are architecture:
• Main “business” classes
• Important
p mechanisms
• Processors and processes
• Layers and subsystems
• Interfaces.
Interfaces
Architectural Design Workflow
1. Select scenarios: criticality and risk Use case view
2 Identify main classes and their responsibility
2.
Logical view
3. Distribute behavior on classes
4. Structure in subsystems, layers, define interfaces Implementation view
5 Define distribution and concurrency
5.
6. Implement architectural prototype Deployment view
7. Derive tests from use cases Process view
8 Evaluate
8. E l t architecture
hit t
Iterate
Result: A Software Architecture Document
Luca Dan Serbanati - Software Design Techniques 37
Ports (Interfaces)
Connector
Component Component
Attributes
Attributes Attributes
Configuration
Luca Dan Serbanati - Software Design Techniques 38
Components
Components are the basic building blocks and the active computational entities
in a system.
Such a component:
1) encapsulates a subset of the system’s functionality and/or data,
2)) restricts access to that subset via an explicitly
p y defined interface, and
3) has explicitly defined dependencies on its required execution context.
• A Component communicates with its environment (which includes other
components)
t ) through
th h one or more ports
t or interfaces.
i t f
– A port may be: (1) a user interface, (2) a shared variable, (3) a procedure
name that can be called by y another component,
p , ((4)) a set of events that
can be emitted, or (6) some other mechanism.
• Attributes (or properties) of the component specify information for analysis
and development of the software,
software such as protocols
protocols, real
real-time
time constraints,
constraints
and behavioral constraints.
• y aspect
The key p is that any
y component
p can be “seen” by y its users, whether
human or software, from the outside only via the interface it has chosen to
make public.
Luca Dan Serbanati - Software Design Techniques 39
Connectors
Connectors define the interaction between components and describe the
rules that govern those interactions.
• A Connector links the ports of two or more components.
• A Connector has a Role attached to it as an attribute that defines the
behavior of the attached components
components. ee.g.,
g in a unidirectional
communication scheme, one component would be the source, while the
other component would be the receiver.
• A Connector can have other attributes. e.g., rates, capacities, and
latencies.
Luca Dan Serbanati - Software Design Techniques 40
Configuration
g ((Topology)
p gy)
• A configuration (topology) is a connected graph (a set of specific
associations) of components and connectors that describes the architectural
structure.
structure
• The configuration must:
– Adhere to the rules for proper connectivity.
– Satisfy concurrent and distributed properties
properties.
• Adhere to constraints such as design heuristics (e.g. end-to-end connectivity
may be no longer than five components.) and style rules.
• C fi
Configuration
ti can bbe analyzed
l d ffor: system
t properties
ti such h as performance,
f
bottlenecks, concurrency, system reliability, security, etc.
• A system can have several configurations.
• Example:
Luca Dan Serbanati - Software Design Techniques 41
Architectural Styles
y and Patterns
An architecture style is a named collection of architectural design decisions that
1) are applicable in a given development context,
context 2) constrain architectural
design decisions that are specific to a particular system within that context,
3) elicit beneficial qualities in each resulting system .
A architectural
An hit t l style
t l iis a ttype off metamodel
t d l th
thatt prescribes
ib a sett off elements
l t
and their relationships that characterize a system based on the style. These
elements are commonly expressed as components and connectors and their
relationships are the constraints on how components and connectors may
be combined.
An architectural pattern is a named collection of architectural design decisions
that are applicable to a recurring design problem, parameterized to account
for different software development contexts in which that problem appears.
Examples:
– Three tiers
– Model-View-Controller
– Sensor-Controller-Actuator
– etc.
Luca Dan Serbanati - Software Design Techniques 42
Classification
C ass ca o o of
architectural
styles
(M. Shaw,
DG l )
D.Garlan)
Luca Dan Serbanati - Software Design Techniques 43
Layered View
In the Layered View the system is viewed as a complex heterogeneous entity
that can be decomposed into interacting parts of distinct, related
responsibilities, with a clean, cohesive separation of concerns with each other
The design concerns addressed by this view are:
• What are the parts that make up the whole system?
• How do these parts interact with each other?
• How do the parts perform their functionality and still remain decoupled from
each other?
• How are the quality attributes of modifiability, scalability, and integrability
supported?
Luca Dan Serbanati - Software Design Techniques 46
Users
Characteristics:
• A hierarchically layered system consists of a large software application that
is partitioned into layers that is components that are decoupled as much as
possible from one another.
• Each layer acts as a virtual machine for the layers above it, providing
services to those layers
layers. In turn
turn, it acts as a client to the layers below itit.
• Communication between layers occurs through connectors that include
appropriate well-defined APIs interfaces, states, and interaction protocols.
Luca Dan Serbanati - Software Design Techniques 48
Layered
Architecture (III)
Layered
y Patern
Layer
Package
Characteristics
The system structure is partitioned system into discrete layers of distinct,
related responsibilities of use-cases or classes and interface , with a clean,
cohesive separation of concerns such that the "lower" layers are low-level
and general services, and the higher layers are more application specific.
The lower layer has an interface with hardware components or with the
operating
p g system
y and the highest
g layer
y contains the application
pp objects
j .
The architecture is very portable. The lower layers are reusable with various
higher layers for the same platform. The
49 higher layers are reusable for
various platforms.
Luca Dan Serbanati - Software Design Techniques
50
Luca Dan Serbanati - Software Design Techniques
Benefits in Using
g Layers
y
• In general, there is a separation of concerns, a separation of high from low-
level services
services, and of application-specific
application specific from general services
services. This
reduces coupling and dependencies, improves cohesion, increases reuse
potential, and increases clarity.
• Related
R l t d complexityl it is
i encapsulated
l t d and
d decomposable.
d bl
• Some layers can be replaced with new implementations. This is generally
not ppossible for lower-level Technical Service or Foundation layers y (e.g.,
( g
java.util), but may be possible for UI, Application, and Domain layers.
• Lower layers contain reusable functions.
• Some
S layers
l ((primarily
i il th
the D
Domain i and
dT Technical
h i lSServices)
i ) can b
be
distributed.
• Development
p by
y teams is aided because of the logical
g segmentation.
g
Note. The domain layer is part of the software and the domain model is part
of the conceptual-perspective analysis they aren't the same thing. But by
creating a domain layer with inspiration from the domain model model, we achieve
a lower representational gap, between the real-world domain, and our
51
software design.
Luca Dan Serbanati - Software Design Techniques
Domain Layer
y vs. Domain Model
52
Luca Dan Serbanati - Software Design Techniques
Layers
y and Partitions
• The original notion of a tier in architecture was a logical layer, not a physical
node, but the word has become widely used to mean a physical processing
node (or cluster of nodes)
nodes), such as the "client
client tier"
tier (the client computer)
computer).
• The layers of an architecture are said to represent the vertical slices, while
partitions represent a horizontal division of relatively parallel subsystems of
a layer.
Example 1 Example 2
Partitions
Application package
Wi d
Window
Graphics
Layers
53
Luca Dan Serbanati - Software Design Techniques
Mixing
g views of the architecture
54
Luca Dan Serbanati - Software Design Techniques 55
Motivation
Indirection Layer
A sub-system should be accessed by one or more components, but direct
access to the subsystem is problematic. For instance, the components
should not get hard
hard-wired
wired into the subsystem,
subsystem instead the accessors for the
sub-system should be reused. Or the access should be defined in a way that
it can be flexibly adapted to changes. The same problem appears at different
levels of scale: it can happen between two ordinary components in one
environment, components in two different languages, components in two
different systems (e.g. if a legacy system is accessed).
Solution
An INDIRECTION LAYER is a LAYER between the accessing component
and the “instructions” of the sub-system that needs to be accessed. The
general term “instructions”
instructions can refer to a whole programming language
language, or
an application programming interface (API) or the public interface(s) of a
component or sub-system, or other conventions that accessing components
must follow.
follow The INDIRECTION LAYER wraps all accesses to the relevant
sub-system and should not be bypassed.
The INDIRECTION LAYER can perform additional tasks while deviating
i
invocations
ti tto th
the subsystem,
b t such
h as converting
ti or ttracing
i ththe iinvocations.
ti
The INDIRECTION LAYER pattern is a foundation for the architectures of
INTERPRETER, VIRTUAL MACHINE, and RULE-BASED SYSTEM.
Luca Dan Serbanati - Software Design Techniques 56
Indirection Layer
y Example
p
Dataflow Systems
• Dataflow systems are characterized by how data moves through the system system.
Dataflow architectures have two or more data processing components that
each transform input data into output data.
Pi li architectural
Pipeline hit t l style
t l : it is
i limited
li it d tto a lilinear sequence off filt
filters. V
Version:
i
Bounded pipes, Typed pipes
Connector Connector
Component Component Component
Types
yp of Data Flow Systems
y
• Transform flow: incoming input data is transformed within the system
into an internal form. While the information is in the system, it may be
subject to further transformations of its internal form. Finally, outgoing
data is transformed within the system from an internal form to its
external form.
• Transaction flow: a single input item triggers data flow along several
action paths. Many interactive systems and query/response systems
fit this model
model. Each element along the data flow path usually has
multiple outputs. Some elements are incorporated solely as junctions
to recombine separate paths.
Transaction
Entering flow Exiting flow
Transactional
External centre
representation
on
Informatio
Flow in
transformation Action path
Internal
representation
Time
Luca Dan Serbanati - Software Design Techniques 61
Batch Sequential
q Systems
y
• A batch sequential system is a collection of programs that are arranged and
executed sequentially.
• Each
E h program runs tto completion.
l ti D
Data
t iis ttransmitted
itt d between
b t the
th programs
via files stored on external storage. A program reads data from one or more
files, processes it, and writes one or more files before exiting. Then the next
program, if there is one, is initiated.
1. UNIX pipe command:
cat foo
foo.txt
txt | grep “bar”
bar | sort > baz
baz.txt
txt
Properties
2. Master file processing system:
•Low memoryy requirement
q
Data
Data Set Data Data • High latency for I/O
Set Set
Set
Edit Sort Update Report • Limited opportunity for concurrency
• Limited opportunity for synchronization
Data • Unable to support interactive systems
Set -> e.g., cannot interrupt the Unix pipe
Luca Dan Serbanati - Software Design Techniques 62
Batch Sequential
q Style
y
Summary: Separate programs are executed in order; data is passed as an
aggregate from one program to the next
Components: Independent programs
Connectors: the human hand carrying tapes between the programs
Data elements: Explicit, aggregate elements passed from one component to the
next upon completion of the producing program’s
program s execution
Topology: Linear
Additional constraints imposed: One program runs at a time, to completion
Qualities yielded: Severable execution; simplicity
Typical uses: Transaction processing in financial systems
Cautions: when interaction between the components is required; when
concurrency between components is possible or required
Relations to programming languages or environments: none.
When can we use it?
Consider a complex task that can be sub-divided into a number of smaller
tasks, which can be defined as a series of independent computations. This
should not be realized by one monolithic component because this
component would be overly complex, and it would hinder modifiability and
reusability.
Luca Dan Serbanati - Software Design Techniques 63
input
output
A pipe and filter architecture is
one in which one or more data
pipe sets are processed in discrete,
filter
output separable stages. Each stage is
filter pipe filter
filter represented by a component
component.
Pipes and filters
• A component
p operates
p on the entire data set and p
passes its results along
g to
the next stage: local transformation of input stream/incremental computation
(-> Filter)
• Connectors between components serve as link (-> ( > Pipe)
Properties:
• Pure data-driven interaction
• Each component has a set of inputs and a set of outputs
• Data transmitted as a whole between Filters
• Filters are independent programs
• Each
E h ttransformation
f ti step
t runs to
t completion
l ti before
b f nextt step
t starts
t t
• Filters ignore identity of upstream/downstream filters
• Correctness of output depends on the order of filters.
Luca Dan Serbanati - Software Design Techniques 64
Pipe
p and Filter Systems
y ((II))
Pipelines – the filters are in linear sequence.
Bounded pipes – the data quantity in a pipe is bounded
Typed pipes – the pipes are typed (the data are of certain types only)
Characteristics:
Ch i i
• Filter
– Incrementally transform some amount of the data at inputs to data at
outputs
• Stream-to-stream transformations
– Use little local context in p
processing
g stream
– Preserve no state between instantiations
• Pipe
– Move data from a filter output to a filter input
– Pipes form data transmission graphs
• Overall Computation
– Run pipes and filters (non
(non-deterministically)
deterministically) until no more computations
are possible.
Luca Dan Serbanati - Software Design Techniques 65
Disadvantages
• Order of filters matters: should be
decided by the designer
• Difficult to maintain correspondences between two separate but related
streams
• Multiple I/O problem: difference in arrival data rates can impose a
performance bottleneck in the system.
Luca Dan Serbanati - Software Design Techniques 66
Pipe-and-filter
p
Summary: Separate programs are executed, potentially concurrently; data is
passed as a stream from one program to the next
Components: Independent programs, known as filters
Connectors: Explicit routers of data streams; service provided by operating
system
Data elements: Not explicit; must be (linear) data streams. In the typical
Unix/Linux/DOS implementation the streams must be text text.
Topology: Pipeline, though T fittings are possible.
Qualities yielded: Filters are mutually independent. Simple structure of incoming
and outgoing data streams facilitates novel combinations of filters for new,
composed applications.
Typical uses: Ubiquitous in operating system application programming
programming.
Cautions: When complex data structures must be exchanged between filters;
when interactivity between the program is required.
Relations to programming languages or environments: Prevalent in Unix shell.
Luca Dan Serbanati - Software Design Techniques 67
C
Consider
id the
h case where
h
Applicability
pp
a complex
l task
k can b
y
be sub-divided
b di id d iinto a number
b off
smaller tasks, which can be defined as a series of independent
computations. Additionally the application processes streams of data, i.e. it
t
transforms
f input
i t data
d t streams
t into
i t output
t t data
d t streams.
t This
Thi functionality
f ti lit
should not be realized by one monolithic component because this
component would be overly complex, and it would hinder modifiability and
reusability Furthermore
reusability. Furthermore, different clients require different variations of the
computations, for instance, the results should be presented in different ways
or different kinds of input data should be provided. To reach this goal, it must
be possible to flexibly compose individual sub sub-tasks
tasks according to the client
client’s
s
demands.
In a PIPES AND FILTERS architecture a complex task is divided into several
sequential subtasks.
subtasks Each of these sub-tasks
sub tasks is implemented by a separate
separate,
independent component, a filter, which handles only this task. Filters have a
number of inputs and a number of outputs and they are connected flexibly
using pipes but they are never aware of the identity of adjacent filters.
Each pipe realizes a stream of data between two components. Each filter
consumes and delivers data incrementally, which maximizes the throughput
of each individual filter,, since filters can potentially
p y work in parallel.
p Pipes
p act
as data buffers between adjacent filters. The use of PIPES AND FILTERS is
advisable when little contextual information needs to be maintained between
the filter components and filters retain no state between invocations.
Luca Dan Serbanati - Software Design Techniques 68
Data-centered
View
Vi
In the Data-centered View the system is viewed as a persistent, shared data
store that is accessed and modified by a number of elements. The concerns
addressed by this view are:
• How is the shared data store created, accessed, and updated?
• How is data distributed?
• Is the data store passive or active, i.e. does it notify its accessors or are the
accessors responsible of finding data of interest to them?
• How does the data store communicate with the elements that access it?
• Do the accessor elements communicate indirectly through the shared data
or also directly with each other?
• How are the quality attributes of scalability, modifiability, reusability, and
integrability supported?
Luca Dan Serbanati - Software Design Techniques 69
Data
ata Ce
Centered
te ed Syste
Systems
s
trans1 trans2
computation
ks1 ks3
Bl kb d
Blackboard
memoriy
trans3
Database direct
computation access
Blackboard
access
transaction to data trans4
database ks2
transaction
ks: knowledge source ks4
Shraed-repository
Shared Repository
p y
• When transforming a conceptual domain into a technical software
architecture we must sometimes provide a design for applications whose
parts operate on, and coordinate their cooperation via, a set of shared data.
• Some applications are inherently data-driven: interactions between
components do not follow a specific business process, but depend on the
data on which they operate
operate.
Solution:
• Maintain all data in a central repository shared by all functional components
of the data-driven application and let the availability, quality, and state of that
data trigger and coordinate the control flow of the application logic.
Luca Dan Serbanati - Software Design Techniques 71
Active Repository
A system needs to have a SHARED REPOSITORY, but it should not just be
passively accessed by accessor components
components. Clients need to be
immediately informed of specific events in the shared repository, such as
changes of data or access of data. “Polling” (i.e. querying in frequent
intervals) the SHARED REPOSITORY for such events does not work work, for
instance, because this does not deliver timely information or inflicts
overhead on the system performance.
An ACTIVE REPOSITORY is a SHARED REPOSITORY that is “active” in the
sense that it informs number of subscribers of specific events that happen
in the shared repository.
p y The ACTIVE REPOSITORY maintains a registry g y
of clients and informs them through appropriate notification mechanisms.
• The notification mechanism can be realized using ordinary EXPLICIT
INVOCATIONS but in most cases IMPLICIT INVOCATIONS,
INVOCATIONS, INVOCATIONS such as
PUBLISH-SUBSCRIBE, are more appropriate.
Luca Dan Serbanati - Software Design Techniques 72
•
Blackboard System
Consider the case where a SHARED REPOSITORY is needed for the
shared data of a computation, but no deterministic solution strategies are
known. Examples are image recognition or speech recognition applications.
• In a BLACKBOARD architecture the complex p task is divided into smaller
sub-tasks for which deterministic solutions are known.
• The BLACKBOARD is a SHARED REPOSITORY that uses the results of its
clients for heuristic computation and step-wise improvement of the solution.
• Each
E h participant
ti i t agentt h
has expertise
ti iin itits own fi
field,
ld anddhhas a ki
kind
d off
problem solving knowledge (knowledge source) that is applicable to a part of
the problem, i.e., the problem cannot be solved by an individual agent only.
• Agents communicate strictly through a common blackboard whose contents
is visible to all agents. When a partial problem is to be solved, candidate
agents that can possibly handle it are listed up.
Components
p
• The knowledge source: separate, independent parcels of application-
dependent knowledge. Interaction among knowledge sources takes place
solely through the blackboard.
• The
Th blackboard
bl kb d data d t structure:
t t problem
bl solving
l i state
t t ddata,
t organized
i d iinto
t an
application-dependent hierarchy. Knowledge sources make changes to the
blackboard that lead incrementally to a solution to the problem.
• Control: driven entirely by the state of the blackboard
blackboard. Knowledge sources
respond opportunistically when changes in the blackboard make them
applicable. The control unit is responsible for selecting among the candidate
agents to assign the task to one of them.
Luca Dan Serbanati - Software Design Techniques 73
Blackboard: Advantages/Disadvantages
Advantages:
• Suitable when there are diverse
sources of input data
• Suitable for physically distributed
environments
• Suitable for scheduling and
postponement
t t off tasks
t k andd
decisions
• Suitable for team problem-
solving
l i approaches h as it can bbe
Drawbacks: used for posting problem
• Expensiveness subcomponents and partial
• Difficult to determine
results
lt
partitioning of knowledge
• Control unit can be very
complex
p
Luca Dan Serbanati - Software Design Techniques 74
Blackboards
Summary: Independent programs access and communicate exclusively through
a global data repository, known as a blackboard.
Components: Independent programs, sometimes referred to as “knowledge
sources”,, blackboard.
sources
Connectors: Access to the blackboard may be by direct memory reference, or
can be through a procedure call or a database query.
Data elements: data stored in the blackboard.
Topology: star topology, with the blackboard at the center.
Variants: in one version of the style, programs poll the blackboard to determine
if any values of interest have changed; in another version, a blackboard
manager notifies interested components of an update to the blackboard.
Qualities yielded: Complete solution strategies to complex problems do not
have to be preplanned. Evolving views of the data/problem determine the
strategies
i that
h are adapted.
d d
Typical uses: Heuristic problem solving in artificial intelligence applications.
Cautions: When a well-structured solution strategy is available; when
i t
interactions
ti b
between
t the
th independent
i d d t programs require i complex
l regulation;
l ti
when representation of the data on the blackboard is subject to frequent
change (requiring propagating changes to all the participating components)
Relations to programming languages or environments: Versions of the
blackboard style that allow concurrency between the constituent programs
require concurrency primitives for managing the shared blackboard.
Luca Dan Serbanati – Software Design Techniques 75
Interpreter
p
Motivation
A language syntax and grammar needs to be parsed and interpreted within
an application. The language needs to be interpreted at runtime (i.e. using
a compiler is not feasible).
feasible)
Solution
An INTERPRETER for the language g g is p provided,, which p
provides both
parsing facilities and an execution environment. The program that needs to
be interpreted is provided in form of scripts which are interpreted at
runtime. These scripts are portable to each platform realization of the
INTERPRETER. For instance, the INTERPRETER can define a class per
grammar rule of the language. The parser of the interpreter parses
language instructions according to these rules and invokes the
interpretation classes. Many more complex INTERPRETER architectures
exist.
Luca Dan Serbanati – Software Design Techniques 78
Interpreter
p
Interpreter
memory
Program
memory (pseudocode))
(p
Data access
inputs (fetch/store) being
Activation interpreted
records
(program
state)
memory
Computation
Data access
(state (fetch/store)
machine)
Control state
selected instruction of the
outputs
t t Interpretation interpretation
engine engine
selected data
Characteristics:
A interpreter
An i t t hash 4 components. t
• In an interpreter style the software implements a virtual machine .
• An interpreter includes the pseudoprogram being interpreted and the
interpretation engine itself.
• The pseudoprogram includes the program itself and the interpreter’s analog
off its
it execution
ti state
t t (activation
( ti ti records).
d )
• The interpretation engine includes both the definition of the interpreter and
the current state of its execution.
Luca Dan Serbanati - Software Architectures 79
Interpreter
Summary: Interpreter parses and executes input commands, updating the state
maintained by the interpreter.
Components: Command interpreter, program/interpreter state, user interface.
Connectors: Typically the command interpreter, user interface, and state are
very closely bound with direct procedure calls and shared state.
Data elements: Commands.
C
Topology: Tightly coupled three-tier; state can be separated from the
interpreters.
p
Qualities yielded: Highly dynamic behavior is possible, where the set of
commands is dynamically modified. System architecture may remain
constant while new capabilities are created based upon existing primitives
primitives.
Typical uses: Superb for end-user programmability; support dynamically
changing set of capabilities.
Cautions: When fast processing is needed; memory management may be an
issue, especially when multiple interpreters are invoked simultaneously.
Relations to programming languages or environments: Lisp and Scheme are
interpretive languages, and sometimes used when building other
interpreters; Word/Excel macros.
Luca Dan Serbanati - Software Design Techniques 80
Virtual Machine
Applicability
An efficient execution environment for a programming language is needed.
Th architecture
The hit t should
h ld facilitate
f ilit t portability,
t bilit coded optimizations,
ti i ti and
d native
ti
machine code generation. Runtime interpretation of the language is not
necessarily required.
Solution
A VIRTUAL MACHINE defines a simple machine architecture on which not
machine code but an intermediate form called the byte-code
y can be
executed. The language is compiled into that byte-code. The VIRTUAL
MACHINE can be realized on different platforms, so that the byte-code can
be portable between these platforms.
platforms The VIRTUAL MACHINE redirects
invocations from a byte-code layer into an implementation layer for the
commands of the byte-code. A virtual machine (VM) is an emulator that
executes on top of a hardware or software platform
platform.
• Such a machine provides the familiar functions and services expected by
computer programs but does so using software rather than hardware.
• It iis a variant
i t off th
the INDIRECTION LAYER pattern. tt
Luca Dan Serbanati - Software Design Techniques 81
Virtual Machine
Summary: Consists of an ordered sequence of layers; each layer or virtual
machine, offers a set of services that may be accessed by programs
(subcomponents) residing within the layer above it.
Components: layers offering a set of services to other layers, typically
comprising several programs (subcomponents)
Connectors: Typically procedure calls
Data elements: Parameters p passed between layers
y
Topology: Linear, for strict virtual machines; a directed acyclic graph in looser
interpretations
Q liti yielded:
Qualities i ld d ClClear ddependency
d structure;
t t software
ft att upper llevels
l iimmune
to change of implementation within lower levels as long as the service
specifications are invariant. Software at lower levels fully independent of
upper levels
Typical uses: Operating system design; network protocol stacks
Cautions: Strict virtual machines with many levels can be relatively inefficient
inefficient.
Luca Dan Serbanati - Software Design Techniques 82
Using
g the Virtual Machine Pattern
Advantages
1. Virtual machine concept provides complete protection of system resources
since each virtual machine is isolated from all other virtual machines
machines. This
isolation, however, permits no direct sharing of resources.
2. A virtual machine is an ideal platform for research and development of new
software concepts because it insulates the R&D environment from the
operational environment and does not disrupt normal operation.
Disadvantages:
The virtual machine concept is difficult to implement due to the effort
required to provide an exact duplicate of the underlying machine.
The
M i i
Motivation
e Rule-Based
u e ased Syste
System Pattern
atte
Logical problems are hard to express elegantly in imperative languages that are
typically used in INTERPRETERS and VIRTUAL MACHINES. Consider for
i t
instance an expertt system
t that
th t provides
id the
th knowledge
k l d off an expertt or a sett
of constraints. In imperative languages these are expressed by nested if-
statements or similar constructs which are rather hard to understand.
Solution
A RULE-BASED SYSTEM offers an alternative for expressing such problems in
a system. It consists mainly of three things: facts, rules, and an engine that
acts on them
them. Rules represent knowledge in form of a condition and
associated actions. Facts represent data. A RULE-BASED SYSTEM applies
its rules to the known facts. The actions of a rule might assert new facts,
which in turn
which, turn, trigger other rules
rules.
Rule-based Systems:
– Provide a means of codifying the problem-solving skills of human experts
– Experts tend to capture problem-solving
problem solving techniques as sets of situation-
situation
action rules
– Typically, execution / activation of rules is sequenced in response to the
conditions of the p problem-solvingg computations
p rather than by
ya
predetermined scheme
– Because situation-action rules are not directly executable by computers,
systems for interpreting such rules must be provided (es. PROLOG)
Luca Dan Serbanati - Software Design Techniques 84
Rule-Based Systems
S
Rule-Based/Expert
Summary: IInference
f engine
p
i parses user input
i t and
dd
System
y
determines
t i whether
h th it iis a
fact/rule or a query. If it is a fact/rule, it adds this entry to the knowledge
base. Otherwise, it queries the knowledge base for applicable rules and
attempts
tt t tot resolve
l the
th query.
Components: User interface, inference engine, knowledge base.
Connectors: Components are tightly interconnected, with direct procedure calls
and/or shared data access.
access
Data elements: facts and queries.
Topology: tightly coupled three-tier (direct connection of user interface,
inference engine
engine, and knowledge base)
base).
Qualities yielded: Behavior of the application can be easily modified through
dynamic addition or deletion of rules from the knowledge base. Small
systems can be quickly prototyped
prototyped. Thus useful for iteratively exploring
problems whose general solution approach is unclear.
Typical uses: When the problem can be understood as matter of repeatedly
resolving a set of predicates.
Cautions: When a large number of rules are involved, understanding the
interactions between multiple rules affected by the same facts can become
very y difficult. Understanding g the logical
g basis for a computed
p result can be
as important as the result itself.
Relations to programming languages or environments: Prolog is a common
language for building rule-based systems.
Luca Dan Serbanati - Software Design Techniques 86
C
Component
t IInteraction
t ti View
Vi
IIn the
th Component
C t Interaction
I t ti View
Vi the
th system
t is
i viewed
i d as a numberb off
independent components that interact with each other in the context of a
system. The concerns addressed by this view are:
• How do the independent components interact with each other?
• How are the individual components decoupled from each other?
• How are the quality attributes of modifiability and integrability
supported?
The components retain their independence, since they merely exchange
data but do not directly control each other.
The components interact with each other through connectors that pass
data from one to another. This interaction can be performed
synchronously or asynchronously and can be message-based or through
direct
d ect ca
calls.
s
The two major patterns in this view differentiate whether the components
interact through explicit or implicit invocations.
Luca Dan Serbanati - Software Design Techniques 87
response message
PSM
Service
– O
Onlyy the
t e requestor
equesto “knows”
o s tthe
epprovider,
o de , 1. S
Server
Service
provider
Service
provider
2. “Fire-and-Forget”
Fire and Forget
Multi cast
Unidirectional transmission from Service
provider
requestor
Service
provider
Service
fire-and-forget provider
message
Service
3. Server
requestor provider
Service
PSM provider
Luca Dan Serbanati – Software Design Techniques 89
Complex
p MEP
Complex MEP = Aggregation of primitive and complex MEP.
Example: Event-based Communication, Publish/Subscribe
subscription
p
Step 1:
request message
PSM request-response
subscription
response message
Subscriber Publisher
Step 2:
notification
tifi ti messages PSM fire-and-forget
Explicit Invocation
Luca Dan Serbanati - Software Design Techniques 91
Explicit, Synchronous
Invocation
• A synchronous
h software
ft architecture
hit t in
i which
hi h the
th client
li t ceases
execution while the service provider performs the service. Upon
completing the service, the service provider may return a value to the
client.
• Call & Return style is used when the order of computation is fixed.
Client
Service Provider
1
2
4
5
Main Program/Subroutine
• The main program and subroutines architecture consists of a main program
that acts as a controller (or executive) and one or more subroutines that
perform specific functions when called by the main program
program.
• This architecture is based on the definition–use relationship, which imposes
a single thread of control.
• The correct operation of the main program and any subroutine is directly
dependent on the correct operation of the subroutines it calls.
main
R0
C1
C2 C3
P1 P2 P3 ... Pn
Main Program R1 R2
Subroutine C21 R2
Return
Call P21
Main
Program/Subroutine C211 R21
Subroutine P211
Luca Dan Serbanati - Software Design Techniques 95
Main Program/Subroutine
g Style
y
Characteristics
• Hierarchical decomposition based on definition-use relationship
• Single
Si l th thread
d off control
t l supported
t d di
directly
tl bby programming
i llanguages
• Subsystem structure implicit: subroutines typically aggregated into
modules
• Hierarchical reasoning: correctness of a subroutine depends on the
correctness of the subroutines it calls.
Ad
Advantages:
t
• Simple to visualize and easy to learn.
• A single thread of control works its way through the various subroutines.
Disadvantages:
• Correctness of any job depends on all subroutines called.
• Tendency to devolve into spaghetti code: several subroutines may do
similar job due to similar requirements added at different times in the
application’s
application s lifetime.
• Scalability & configuration control: one can lose visibility of the flow of
control over several subroutines.
Luca Dan Serbanati - Software Design Techniques 96
Main Program
g and Subroutines
Summary: Decomposition based upon separation of functional processing
steps.
steps
Components: Main programs and subroutines
Connectors: Function/procedure calls
Data elements: Values passed in/out of subroutines
Topology: Static organization of components is hierarchical, full structure is a
directed graph
Qualities yielded: Modularity: Subroutines may be replaced with different
implementations as long as interface are unaffected
Typical uses: Small programs; pedagogical purposes
Cautions: Typically fails to scale to large applications; inadequate attention to
data structures
structures. Un predictable effort required to accommodate new
requirements
Relations to programming languages or environments:
Luca Dan Serbanati - Software Design Techniques 97
Object op
Object
op is an invocation or
procedure call
Characteristics:
• The data are encapsulated as the abstract data types demand in
objects together with primitive operations; the object internal
representation
p is hidden for other objects’
j access. The objects
j interact
by means of a message-passing or procedure call mechanism (call-
and-return style) .
• Object systems also support inheritance and/or delegation
mechanisms not necessarily available in program/subroutines
architecture.
Luca Dan Serbanati - Software Design Techniques 98
Object-Orientation
Summary: St
S State
t strongly
t l encapsulated
l t d with
ith ffunctions
ti th
thatt operate
t on that
th t state
t t
as objects
Components: Objects (instance of a class)
Connectors: Method invocation (procedure calls to manipulate state)
Data elements: Arguments to methods
Topology:
p gy Can vary y arbitrarily
y components
p may y share data and interface
functions through inheritance hierarchies
Additional constraints imposed: Commonly shared memory (to support use of
pointers) single threaded
pointers),
Qualities yielded: Integrity of data operations: data manipulated only by
appropriate functions. Abstraction implementation details hidden
Typical uses: Applications where the designers wants a close correlation
between entities in the physical world and entities in the program;
applications involving complex, dynamic data structures
C ti
Cautions: U
Use iin di
distributed
t ib t d applications
li ti requires
i extensive
t i middleware
iddl tto
provide access to remote objects. Relatively inefficient for high-performance
applications with large, regular numeric data structures, such as scientific
computing. Lack of additionla structuring principles can result in highly
complex applications
Relations to programming languages or environments: Java, C++
Luca Dan Serbanati - Software Design Techniques 100
Client-Server Architecture
Luca Dan Serbanati - Software Design Techniques 101
Motivation
Client-Server Pattern
Two components need to communicate, and they are independent of each
other, even running in different processes or being distributed in different
machines The two components are not equal peers communicating with
machines.
each other, but one of them is initiating the communication, asking for a
service that the other provides. Furthermore, multiple components might
q
request the same service p provided by
y a single
g component.
p Thus,, the
component providing a service must be able to cope with numerous
requests at any time(the component must scale well). On the other hand, the
q
requesting g components
p using
g one and the same service mightg deal
differently with the results. This asymmetry between the components should
be reflected in the architecture for the optimization of quality attributes such
as performance, shared use of resources, and memory consumption.
Solution
The CLIENT-SERVER pattern distinguishes two kinds of components:
clients and servers. The client requests information or services from a
server. To
T dod so it needsd tto know
k how
h to
t access the
th server: it requires
i an ID
or an address of the server and of course the server’s interface.
The server responds to the requests of the client, and processes each client
request on its own
own. It does not know about the ID or address of the client
before the interaction takes place. Clients are optimized for their application
task, whereas servers are optimized for serving multiple clients.
Luca Dan Serbanati - Software Design Techniques 102
Type of Connection
Client-Server Issues (I)
• Connectionless communication: e.g. via UDP (User Datagram Protocol),
implements unreliable delivery of messages. Clients should use
connectionless communication when the application service handles errors
andd participates
ti i t iin b broadcast
d t or multicast
lti t service,
i or performance
f
requirements cannot tolerate virtual circuit overhead delays.
• Connection-oriented communication: e.g. via TCP/IP (Transfer Control
P t
Protocol/Internet
l/I t t Protocol),
P t l) implements
i l t reliable
li bl d delivery
li off messages.
Connection oriented communication makes programming easier because
the protocol includes mechanisms for detecting and handling errors and an
acknowledgment mechanism between client and service. service
Stateless vs. Stateful Servers
• State information: Information a server maintains about its clients. A server
may or may not retain this information
information.
• State information may be required if the information exchange between the
client and the application consists of multiple messages. State information
can become useless if messages are lost lost, duplicated
duplicated, or delivered out-of-
out of
order, or if the server crashes and must be rebooted.
• Stateless servers rely on the application protocol to assume the
espo s b y for
responsibility o reliability
e ab y o of de
delivery
eya andd se
service.
ce Thus,
us, the e app
application
ca o
gives the same response no matter how many times a request arrives.
• Stateful designs can lead to complex application protocols and error
handling mechanisms
Luca Dan Serbanati - Software Design Techniques 103
• It iis also
l possible
ibl tto combine
bi ththe CLIENT
CLIENT-SERVER
SERVER pattern
tt with
ith LAYERS iin
order to design a system where the client and the server components
individually are layered.
• SHARED REPOSITORIES or BLACKBOARDS can be perceived as
CLIENT-SERVER, where the data store is the server and the data
accessors are the clients.
Luca Dan Serbanati - Software Design Techniques 105
Client/Server Styles
Client-Server
Summary: Clients send service requests to the server, which performs the
required functions and replies as needed with the requested information.
Communication is initiated by the clients
clients.
Components: Clients and server
Connectors: Remote p procedure calls, network pprotocols
Data elements: Parameters and return values as sent by the connectors
Topology: Two-level, with multiple clients making requests to the server
Additional constraints imposed: Client-to-client communications prohibited
Qualities yielded: Centralization of computation and data at the server, with the
information made available to remote clients. A single powerful server can
service many clients
Typical uses: Applications where centralization of data is required, or where
processing and data storage benefit from a high
high-capacity
capacit machine
machine, and
where clients primarily perform simple user interface tasks, such as many
business applications
Cautions: when the network bandwidth is limited and there are a large number
of client requests
Luca Dan Serbanati - Software Design Techniques 107
Peer-To-Peer Architecture
Luca Dan Serbanati - Software Design Techniques 108
Workstation Server
Data
Presentation Business Logic Database
Distributed
access Distributed Distributed applications Distributed
dialog data/databases
Peer-to-Peer:
– Any process or node in the system may be both client and server.
peer-to-peer
Process 1 Process2
Process 3 Process4
Process5
Luca Dan Serbanati - Software Architectures 110
Peer-To-Peer
Peer To Peer Style
Peer-to-peer systems tend to be complex, and there is a greater need
to be aware of issues such as deadlock,, starvation between processes,
p ,
and fault handling.
Luca Dan Serbanati - Architetture e tecnologie di servizi 112
Output
Service B Pipe
Service A Service C
Input
Output Pipe Input
Pipe Pipe
PeerID PeerID
PeerID
PeerID
PeerID PeerID
PeerID
Peer
Peer Peer Peer
TCP/IP Peer
Peer Peer
Peer NAT
Firewall
HTTP
5
Luca Dan Serbanati - Software Architectures 113
Peer-to-Peer
Summary: State and beshavior are distributed among peers that can act as
either clients or servers.
C
Components: t PPeers-independent
i d d t components, t having
h i th their
i own state
t t andd
control thread.
Connectors: Network p protocols,, often custom.
Data elements: network messages.
Topology: Network (may have redundant connections between peers); can vary
arbitrarily
bit il and d dynamically.
d i ll
Qualities yielded: decentralized computing with flow of control and resources
distributed among gppeers. Highly
g y robust in face of failure of any
yggiven node.
Scalable in terms of access to resources and computing power.
Typical uses: where sources of information and operations are distributed and
network is ad hoc
hoc.
Cautions: when information retrieval is time critical and cannot afford the
latency imposed by the protocol. Security-P2P networks must make
prevision for detecting malicious peers and managing trust in an open
environment.
Luca Dan Serbanati – Software Design Techniques 114
Implicit Invocation
•Event-driven
Event driven means that processing only occurs when the
event happens.
• The event may be a data point changing, an alarm going off,
a timer timing out or a user clicking on an icon or a graphic
object.
• There is no flow of control.
• Calls are invoked indirectly an implicitly as a response to a
notification or an event.
Luca Dan Serbanati - Software Design Techniques 115
Asynchronous
y Communication
Two modells:
– pub/sub (publish/subscribe) - like TV. Consumer are listeners
subscribe for a event
event-type
type channel or topic
topic.
– PTP (point-to-point) – like vocal mail. A consumer consumes
messages from a message queue.
provider 1
consumer 1 consumer 1
provider1
provider 2 topic queue
provider 2
consumer 2 consumer 2
provider 2
pub/sub PTP
Message
essage Source Message
Publiser Subscriber D i i
Destination
channel Queue
Message Message
Luca Dan Serbanati - Software Design Techniques 117
Publish-Subscribe
Architecture
Luca Dan Serbanati - Software Design Techniques 118
Publish-Subscribe Pattern
Motivation
A component should be accessed or informed of a specific runtime event.
Events are of different nature than direct interactions as in CLIENT-SERVER
or PEER-TO-PEER. Sometimes a number of components should be actively
informed (an announcement or broadcast), in other cases only one specific
component
co po e t iss interested
te ested in the
t eeevent.
e t In co
contrast
t ast to EXPLICIT C
INVOCATIONS, event producers and consumers need to be decoupled for a
number of reasons: to support locality of changes; to locate them in different
processes or machines; to allow for an arbitrary time period between the
announcement of interest in an event, and the actual triggering of the event.
Still, there must be a way to inform the interested components?
S l ti
Solution
PUBLISH-SUBSCRIBE allows event consumers (subscribers) to register for
specific
p events,, and event producers
p to p
publish ((raise)) specific
p events that
reach a specified number of consumers. The PUBLISH-SUBSCRIBE
mechanism is triggered by the event producers and automatically executes a
callback-operation
callback operation to the event consumers
consumers. The mechanism thus takes care
of decoupling producers and consumers by transmitting events between
them.
Luca Dan Serbanati - Software Architectures 119
Publish--Subscribe Style
Publish y
• Publish/subscribe is a style of messaging
Publish-Subscribe
application in which the providers of
Publisher
Architecture i f
information
ti ((publishers)
bli h ) are ddecoupled
l d
Subscriber
from the consumers of that information
Publisher
Publisher
(subscribers) using a broker.
Subscriber
Event
Remote Procedure Call
Publish-Subscribe
Summary: Subscribers register/deregister to receive specific messages or
specific content. Publisher maintain a subscription list and broadcast
messages to subscribers either synchronously or asynchronously.
p
Components: Publishers,, subscribers,, proxies
p for managing
g g distribution.
Connectors: Procedure calls may be used within programs, more typically a
network protocol is required. Content-based subscription requires
sophisticated connectors.
Data elements: Subscriptions, notifications, published information.
Topology: Subscribers connect to publishers either directly or may receive
notifications via a network protocol from intermediaries.
V i t Specific
Variants: S ifi uses off the
th style
t l may require i particular
ti l steps
t ffor subscribing
b ibi
and unsubscribing. Support for complex matching of subscription interests
are available information may be provided and be performed by
intermediaries.
intermediaries
Qualities yielded: Highly efficient one-way dissemination of information with
very low coupling of components.
Typical uses: News dissemination – whether in the real world or online events
events.
Graphical user interface programming. Multiplayer-network – based games.
Cautions: When the number of subscribers for a single data item is very large a
p
specialized broadcast pprotocol will likely
y be necessary.
y
Relations to programming languages or environments: In large-scale systems
support for publish-subscribe is provided by commercial middleware
technology.
Luca Dan Serbanati - Analisi e progettazione orientate agli oggetti 121
Event-Based Architecture
Event
Event-based Implicit Invocation
Architecture
Source
Event
• Instead of invoking a procedure
Procedure g
Manager
E
Event
t Handler
H dl
directly, a component (event source)
can “notify” events to other components
Procedure
Event Handler • There are components (event
Event handlers)) that manifest an interest in an
Remote Procedure Call
event by associating a procedure with it
• When the event is announced, the
Procedure Procedure
system (event manager) invokes all
procedures that have been registered
with it.
• Components: procedures (or methods)
– Interface defines a set of incoming procedure calls
– Interface also defines a set of outgoing events
• Connections: event
event-procedure
procedure bindings
– Procedures are registered with events
– Components communicate by announcing events at “appropriate” times
– When
Wh an eventt is i announced d th
the associated
i t d procedures
d are iinvoked
k d
(implicit invocation)
– Order of invocation is non-deterministic.
Luca Dan Serbanati – Software Design Techniques 122
Characteristics:
• The source event component does not know the event listeners.
• The components can not know the order in the event processing.
Luca Dan Serbanati – Software Design Techniques 123
Event Systems:
y Drawbacks
Components have no control over the computations performed by the system:
– When a component announces an event, it cannot assume other
components t will
ill respond
d tto itit. M
Moreover, even it kknows what
h t other
th
components are interested in the events it announces, it cannot rely on
the order in which they are invoked.
Exchange of data:
– Sometimes data can be passed with an event, but in other situations
event systems must rely on a shared repository for interaction
interaction.
– In these cases global performance and resource management can
become critical issues.
Reasoning about correctness can become problematic:
– The meaning of a procedure (method) that announces events will
d
depend
d on th
the context
t t off bindings
bi di iin which
hi h it iis iinvoked
k d ((->overloading,
> l di
polymorphism).
– This is in contrast to traditional reasoning
g about p
procedure calls,, which
need only consider a procedure’s pre- and post-conditions when
reasoning about the functional behavior of its invocation.
Luca Dan Serbanati - Software Architectures 126
Event-Based
Summary: Independent components asynchronously emit and receive events
communicated over event buses.
Components: Independent,
Independent concurrent event generators and/or consumers
consumers.
Connectors: Event bus. In variants, more than one may be used.
Data elements: Events – data sent as a first-class entity over the event bus.
Topology: Components communicate with the event-bases, not directly to each
other.
Variants: Component communication with the event
event-bus
bus may either be push or
pull based.
Qualities yielded: Highly scalable, easy to evolve, effective for highly
distributed, heterogeneous applications.
Typical uses: User interface software, wide-area applications involving
independent parties (such as financial markets,
markets logistics,
logistics sensor networks)
networks).
Cautions: No guarantee if or when a particular event will be processed.
Relations to programming languages or environments: Commercial message-
oriented middleware technologies support event-based architectures.
Luca Dan Serbanati - Software Design Techniques 127
Subject
setState(SubjectState)
notify( )
update( )
getState(
tSt t ( )
update( )
getState( )
128
Luca Dan Serbanati - Software Design Techniques
131
Luca Dan Serbanati - Software Design Techniques
MVC
Observer Observer
Update()
Model-View-
Model
View
Controller
Controller (III)
Model The pattern separates responsibilities
CurrentTime
Controller of the system in three categories of
Subscribe() 1..1
Detach()
1..1
1..1
objects.
AcceptTick()
p ()
1..1
- Controller is the object which
View
0..*
0..*
receives, process and responds to
all events generated by views and
aModel : Model aView : View aController :
Controller
users
users.
Subscribe - View is an object that presents data
Subscribe
to be shown to yhe user. It is
automatically updated when data
Inc(3)
change or periodically. A View
Adjust()
object creates the controller
because the last one should be
Update
customized according to the view.
Update - Model is the object that gathers
domain data. It updates the views e
controllers, if necessary, each time
when a data change occurs.
132
Luca Dan Serbanati - Software Design Techniques
133
Luca Dan Serbanati - Software Design Techniques 134
PAC
• On a more macroscopic level, the PRESENTATION-ABSTRACTION-
CONTROL patterns is structured according to LAYERS: The top layer
contains the chief agent that controls the entire application; the middle layer
contains agents with coarse-grained functionality; the lower layer is
comprised of fine-grained agents that handle specific services, which users
interact with.
• The various agents usually need to propagate changes to the rest of the
agent hierarchy, and this can be achieved again through the PUBLISH-
PUBLISH
SUBSCRIBE pattern. Usually higher-level agents subscribe to the
notifications of lower-level agents.
C2-Components and Connectors
136
Luca Dan Serbanati - Software Design Techniques 137
Motivation
The C2 Pattern
An interactive system is comprised of multiple components such as GUI
widgets, conceptual models of those widgets at various levels, data
structures,
t t renderers,
d and
d off course application
li ti llogic.
i Th
The system
t may need
d
to support several requirements such as:
– different implementation language of components,
– different GUI frameworks reused
reused,
– distribution in a heterogeneous network,
– concurrent interaction of components without shared address spaces,
– run-time
run time reconfiguration
reconfiguration,
– multi-user interaction.
Yet the system needs to be designed to achieve separation of concerns and
satisfy its performance constraints
constraints.
Solution
The system is decomposed into a top-to-bottom hierarchy of concurrent
components that interact asynchronously by sending messages through
explicit connectors. Components submit request messages upwards in the
hierarchy, knowing the components above, but they send notification
messagesg downwards in the hierarchy, y, without knowingg the components
p
lying beneath. Components are only connected with connectors, but
connectors may be connected to both components and other connectors.
The purposes of connectors is to broadcast, route, and filter messages.
Luca Dan Serbanati - Software Design Techniques 138
C2 Example
A example
An l off a C2 architecture
hit t with
ith ffour components
t iin th
three llayers, and
d ttwo
connectors that delimit the layers.
The C2 top
top-to-bottom
to bottom hierarchy resembles the form of a LAYERS architecture
in an upside-down order. A C2 component that belongs to a given layer,
uses the services of the layers above it by invoking services on them and
provides services to the layers below it by sending notifications to them.
Since the C2 pattern provides substrate independence, isolating a component
from the components underneath it, the layer where a component is placed
is in essence an INDIRECTION LAYER.
The interaction between the C2 components takes place through asynchronous
message exchange, thus utilizing an IMPLICIT INVOCATION mechanism,
and specifically callbacks, e.g. PUBLISH-SUBSCRIBE.
Luca Dan Serbanati - Software Architectures 139
C2 ((Components
p and Connectors)) ((I))
Summary: An indirect invocation style in which independent components
communicate exclusively through message routing connectors. Strict rules
on connectors between components
p and connectors induce layering.
y g
Components: Independent, potentially concurrent message generators and/or
components.
Connectors: Message routers that may filter, translate, and broadcast
messages of two kinds – notifications and requests.
Data elements: Messages – data sent as first-class entities over the
connectors Notification messages announce changes of state
connectors. state. Request
messages request performance of an action.
Topology: layers of components and connectors , with a defined top and
bottom wherein notifications flow downward and requests upward
bottom, upward.
Additional constraints imposed:
• All components and connectors have a defined top and bottom. The top of a
component may be attached to the bottom of a single connector and the
bottom of a component may be attached to the top of a single connector. No
direct component-to-component links are allowed; there is however no
bound on the number of components or connectors that may attached to a
single connector. When two connectors are attached to each other, it must
be from the bottom of one to the top of the other.
Luca Dan Serbanati - Software Architectures 140
Distribution View
In the Distribution View the system is viewed as a number of components
that are distributed among network nodes (or different processes). The
concerns addressed by this view are:
• How do the distributed components interact with each other?
• How are the distributed components
p decoupled
p from each other?
• How are the quality attributes of interoperability, location-transparency,
performance, and modifiability supported?
Th components
The t are physically
h i ll located
l t d in
i different
diff t network
t k nodes
d or
processes. They interact with each other through connectors that pass
invocations or data from one to another. The details of these
interactions can be better explained in the Component Interaction
View. 142
Luca Dan Serbanati - Software Design Techniques 143
Remote-Procedure Call
Luca Dan Serbanati - Software Design Techniques 144
Distributed Objects
• Objects
Obj t are iinstantiated
t ti t d on diff
differentt hosts,
h t each h off which
hi h exposes a public
bli
interface. Objects can be anythings from data structures to legacy systems.
• The interfaces are special in that all parameters and return values must be
serializable so they can go over the network.
• The default mode of interaction between objects is synchronous procedure
call,, although
g asynchronous
y extensions are found in some p particular version
of distributed objects as CORBA.
• Basic idea: an application is broken up into objects which are effectively
software components that expose one or more interfaces.
interfaces In CORBA these
provided interfaces are specified in terms of Interface Definition Language
(IDL). It resembles the way class interfaces are specified in an OO
programming language
language. IDL is a strongly typed language
language.
interface salestax {
float calculate_tax ( in float taxable_amount );
}
module HelloApp {
interface Hello {
string sayHello();
oneway void shutdown();
};
};
Luca Dan Serbanati – Corba 3 146
Rete
Luca Dan Serbanati – Software Design Techniques 147
Middleware
Application Data Application Data
Middleware Layers
Middleware Middleware Middleware
Applications
Piattaforma Hw/Sw
Common
Middleware Services
Distribution
Examples Presentation Middleware
Host Infrastructure
Middle tier Middleware
Application Application
Database Hardware
Operating System Database
Luca Dan Serbanati – Corba 3 148
Network
Memory
Management
Scheduling
Luca Dan Serbanati - Design Patterns 149
CORBA
Client Code target object
ProxyObject
Codice Skeleton
Stub Code
Computer Computer
Luca Dan Serbanati - Software Architectures 150
? Target
Client ? CORBA
C d
Code Obj t
Object
client_invoke() send_message() target_invoke() (Servant)
receive_message()
Reply
Server
Client Process
Process
Computer Computer
Luca Dan Serbanati - Design Patterns 152
CORBA Objects
j
• In CORBA you compile your IDL into client stubs and object skeletons, and
write your object (shown on the right) and a client for it (on the left). Stubs
and skeletons serve as proxies for clients and servers,
respectively. Because IDL defines interfaces so strictly, the stub on the
client side has no trouble meshing perfectly with the skeleton on the server
side, even if the two are compiled into different programming languages, or
even running on different ORBs from different vendors.
• I CORBA,
In CORBA every objectbj t iinstance
t h
has itits own unique
i object
bj t reference,
f an
identifying electronic token. Clients use the object references to direct their
invocations, identifying to the ORB the exact instance they want to invoke
Luca Dan Serbanati - Software Design Techniques 154
Broker Architecture
Luca Dan Serbanati - Software Design Techniques 155
Motivation
The Broker Pattern
Distributed software system developers face many challenges that do not
arise in single-process software. One is the communication across
unreliable networks. Others are the integration of heterogeneous
components into coherent applications, as well as the efficient use of
networking g resources. If developers
p of distributed systems
y must overcome
all these challenges within their application code, they may lose their primary
focus: to develop applications that efficiently tackle their domain-specific
problems.
problems
Solution
A BROKER separates the communication functionality of a distributed
system from its application functionality. The BROKER hides and mediates
all communication between the objects or components of a system. A
BROKER consists of a client-side REQUESTOR to construct and forward
invocations, as well as a server-side INVOKER that is responsible for
invoking the operations of the target remote object. A MARSHALLER on
each side of the communication path handles the transformation of requests
and replies from programminglanguage native data types into a byte array
that can be sent over the transmission medium.
Broker
Broker
Broker Broker
object
1..1 1..1
Cliente Server
Client Proxy Server Proxy
0..* Server
0..*
Client
o y
Proxy Server
Proxy
1..1
1..1
0..* 0..*
Cli t
Client Server
Client
Characteristics
The Broker pattern put forward decoupling the server and its clients.
A Broker object is an object which knows where the system objects are located.
This knowledge is learned at compile-time
compile-time, at run-time based on a dynamic
discovery or using a mixed policy .
Luca Dan Serbanati - Software Development Methods 156
Broker (II)
Two indirection levels.
aClient : aProxy : Client anObject : otherProxy : aServer :
Client Proxy Broker Object Server Proxy Server The first level is composed
Register b proxies
by i which
hi h iisolate
l t th
the
Register clients from the servers.
The second level is
Subscribe represented by the broker
Subscribe
Subscribe object which isolates the
proxies from servers.
Notify(aS) First of all other activities a
Notify(aS)
Notifiy(aS) server has to register itself
Notify(uS) Notif(aS) at the broker.
Detach
Notify(aS) This way the broker can
Detach answer forf allll requests
t with
ith
Detach the server as target.
Notify(aS) Notify(aS)
When the client registers
itself at the local proxy
proxy, the
proxy asks it to register at
the server proxy.
This requests is exclusively
managed by the broker that
Luca Dan Serbanati - Software Development Methods 157 knows where the server is
located.
Luca Dan Serbanati - Software Design Techniques 158
Broker Example
Luca Dan Serbanati – Software Architecture 160
ORB Architecture
Object
Implementation
Client
Client requests
• The ORB is responsible for all of the mechanisms required to find the object
implementation for the request, to prepare the object implementation to
receive the request, and to communicate the data making up the request.
The interface the client sees is completely independent of where the object
is located, what programming language it is implemented in, or any other
aspect that is not reflected in the object’sinterface.
• ORB iis universal
i l -> interoperability
i t bilit off implementations.
i l t ti
• IIOP - Inter-ORB (IIOP) - TCP/IP for CORBA .
• ORBs must implement IIOP.
Luca Dan Serbanati - Software Architectures 161
•
CORBA
ORB Interface
O
Architecture
te ace – Itt provides
Components
p o des access to every
e e y ORB
O service
se ce e except
cept c
(I)
client
e t
invocations (which go through the stubs or the DII), and object activations
and calls (which come through the object adapter, typically a POA). Access
to initial services such as the Naming Service, Trader Service, Root
POA access to the
POA, h IFR
IFR, and
d construction
i off DII iinvocations,
i object
bj
reference operations, etc.
• Interface Repository – It is the component of the ORB that provides
persistent storage of interface definitions
definitions—it it manages and provides access
to a collection of object definitions specified in OMG IDL. An ORB provides
distributed access to a collection of objects using the objects’ publicly
defined interfaces specified in OMG IDL. The Interface Repository provides
for the storage, distribution, and management of a collection of related
objects’ interface definitions.
• Dynamic Invocation Interface - The DII describes the client’s side of the
interface that allows dynamic creation and invocation of request to objects.
DII-based invocations differ from stub-based invocations in the same way
that scripts differ from programs: they're interpreted at run time, and not
compiled in a previous step
step. Using the DII
DII, a client can invoke an operation
on a new type of object that it's just discovered (for example, using the
Trader Service). The invocation itself is a CORBA object with its own object
reference.
reference
• Stub - The stubs are produced by the IDL compiler, each one marshaling the
arguments called for in its definition. There is a separate stub for each
operation of each interface.
Luca Dan Serbanati - Software Architectures 162
Exemples
CORBA Object
Obj t Services,
S i CORBA Component
C t
Services, Sun’s J2EE, Microsoft’s .NET
Luca Dan Serbanati – Corba 3 164
Persis Concur
Naming tence Life Cycle Properties rency Collection Security Trading
1 Creare le
C++ definizioni IDL 2
C
Compilation
il ti
Carica Interface
x.idl Repository
3 Precompilare
xx.h
h Adattatore
xx_skel.h
skel h di oggetti
tti
x.cpp x_skel.cpp
7
Stub IDL Skeleton 6
del client
Implementation
p
utilizza 4 Repository
8 instance
Implementare
Implementare
il client
il server Java
srv.cpp Count.idl
x cpp
x.cpp module Counter
5 Count
9 Compilare { interface Count
Compilare sum : long { attribute long sum;
long increment ();
increment() };
Classe server };
Classe client eseguibile
eseguibile RPC
idl
Summary:
Distributed
y Application
pp functionality
Objects
y broken up
p into objects
j ((coarse- or fine-
grained) that can run on heterogeneous hosts and can be written in
heterogeneous programming languages . Objects provide services to other
objects through well-defined provided interfaces. Objects invoke methods
across host
host, process
process, and language boundaries via remote procedure call
(RPCs), generally facilitated by middleware.
Components: Objects (software components exposing services through well-
defined provided interfaces).
Connectors: Remote procedure calls (RMIs).
Data elements: Arguments to methods, return values, and exceptions.
Topology: General graph of objects from callers to callees; in general, required
services
i are nott explicitly
li itl represented.
t d
Additional constraints imposed: Data passed in remote procedure calls must
be serializable. Callers must deal with exceptions that can arise due to
network or process faults
faults.
Qualities yielded: Strict separation of interfaces from implementations as wellas
other qualities of OO systems in general, plus mostly-transparent
interoperability across location, platform, and language boundaries.
Typical uses: Creation of distributed software systems composed of
components running on different hosts. Integration of software components
written in different programming languages or for different platforms.
Cautions: Interactions tend to be mostly synchronous and do not take
advantage of the concurrency present in distributed systems. Difficulty
dealing with streams and high-volume data flows.
Relations to programming languages or environments: Any language .
Luca Dan Serbanati - Software Design Techniques 167
Message Queuing
Luca Dan Serbanati - Software Design Techniques 168
Message Queuing
Motivation
Consider a situation similar to that of REMOTE PROCEDURE CALLS, but it
is necessary to decouple the sender from the receiver to realize queuing of
invocations Queuing is necessary
invocations. necessary, for instance
instance, when temporal outages of
the receiver should be tolerated or when heterogeneous systems should be
integrated. For instance, when a legacy system using BATCH SEQUENTIAL
should be integrated into a distributed system
system, only one invocation can be
handled at a time by that system. Somewhere additional messages must be
queued until the system is ready to process the next message.
Solution
Messages are not passed from client to server application directly, but
through intermediate message queues that store and forward the messages.
q
This has a number of consequences: senders and receivers of messages
g
are decoupled, so they do not need to know each other’s location (perhaps
not even the identity). A sender just puts messages into a particular queue
and does not necessarily know who consumes the messages. For example,
a message might be consumed by more than one receiver. Receivers
consume messages by monitoring queues.
Luca Dan Serbanati - Software Design Techniques 169
Message
g Queuing
g Example
p
• MESSAGE QUEUING realizes CLIENT-SERVER interactions and
implements IMPLICIT INVOCATION as the primary invocation pattern.
Luca Dan Serbanati - Software Design Techniques 170
Bibliography
1. D. Garlan, M. Shaw, "An Introduction to Software Architecture", Advances in
Software Engineering and Knowledge Engineering"
Engineering , Volume II, World Scientific
Scientific, 1993
2. P. Avgeriou, U. Zdun, “Architectural Patterns Revisited – A Pattern Language”, in:
Proceedings of 10th European Conference on Pattern Languages of Programs
(EuroPlop 2005),
2005) Irsee,
Irsee Germany,
Germany July,
July 2005
3. Neil B. Harrison, Paris Avgeriou, Uwe Zdun, "Using Patterns to Capture Architectural
Decisions," IEEE Software, vol. 24, no. 4, pp. 38-45, July/Aug. 2007