arquitectura de sistemas de software -...
TRANSCRIPT
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 1
Arquitectura de Sistemas de Software Mestrado em Engenharia InformáticaLicenciatura em Engenharia Informática e Computação
Ademar AguiarUniversidade do Porto & INESC Portoademar.aguiar at fe.up.pt
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 2
Estilos de arquitectura
adaptado de http://www.ugrad.cs.ubc.ca/~cs410/lectures/slides/cs410-ArchitecturalStyle1.ppte http://www.ugrad.cs.ubc.ca/~cs410/lectures/slides/cs410-ArchitecturalStyle2.ppt
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 3
Architectural style (Buildings)
18th Century Georgian Architecture“Old Corner Bookstore”Boston MA
Early Gothic ArchitectureNotre Dame, Paris
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 4
Styles and patterns
Identifying styles (and patterns) can help codify and share knowledge/expertise• Architectural Styles [Shaw and Garlan, Software Architecture, Prentice Hall 96]
• Design Patterns [Gamma, Helm, Johnson, Vlissides, Design Patterns, Addison Wesley 95] [Buschmann et. Al, Pattern-oriented Software Architecture: A System of Patterns, John Wiley & Sons 96]
• Code Patterns [Coplien, Advanced C++ Programming Styles and Idioms, Addison-Wesley 91]
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 5
Architectural styles
A style consists of:• a set of component types (e.g., process, procedure) that perform some
function at runtime• a topological layout of the components showing their runtime relationships• a set of semantic constraints• a set of connectors (e.g., data streams, sockets) that mediate
communication among components
Styles provide guidance for architectural design based on the problem domain and the context of use
• Recurring (and proven) architectural design• Definition of common vocabulary
Each style has:• components, connectors, key characteristics, strengths and
weaknesses, variants and specializations.From Chapter 5, Software Architecture in Practice, p. 94
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 6
A catalog of architectural styles
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 7
Call-and-Return style
Goal: achieve modifiability and scalability
Substyles:• Main-program-and-subroutine
- Decompose program hierarchically. Each component gets control and data from its parent.
• Remote procedure call- Components are distributed across a network. Remote call is between two computers, but
otherwise looks like a procedure call.
• Object-oriented or abstract data type
• Layered
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 8
Object-oriented (ADT) substyle
Objects help achieve modifiability by encapsulating internal secrets from environment
Access to objects is only through methods (constrained forms of procedure calls)
Object-oriented paradigm is distinguished from ADT by inheritance and polymorphism
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 9
Example: cruise control system
A cruise-control system exists to maintain the speed of a car, even over varying terrain, when turned on by the driver.
When the brake is applied, the system must relinquish speed control until told to resume.
The system must also steadily increase or decrease speed to reach a new maintenance speed when directed to do so by the driver.Throttle
System on/off
Engine on/off
Pulses from Wheel
Accelerator
BrakeIncrease/Decrease
Speed
Resume Speed
Clock From Model Problems in Architecture, Shaw
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 10
Cruise control: Input/output
System on/off: If on, cruise-control should maintain the car speed.
Engine on/off: If on, denotes car engine is turned on; cruise-control is only active if the engine is on.
Pulses from wheel: A pulse is sent for every revolution of the wheel.
Accelerator: Indication of how far the accelerator has been pressed.
Brake: On when the brake is pressed; cruise-control temporarily reverts to manual control if the brake is pressed.
Increase/Decrease Speed: Increase or decrease the maintained speed; only applicable if the cruise-control system is on.
Resume: Resume the last maintained speed; only applicable if the cruise-control system is on.
Clock: Timing pulse every millisecond.
Throttle: Digital value for the engineer throttle setting.
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 11
Layered substyle
Goals: modifiability and portability
Optimally, each layer communicates only with its neighbors
Sometimes, must layer bridgefor performance: decreases benefits of style
Core
Basic Utility
Subsystem
Subsystem
User Interface
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 12
Layered substyle: Example
Outline of a design used on a mobile robot
Level 1 is robot control
Levels 2-3 deal with input from real world
Level 4 manages robot’s view of world
Level 5 manages robot navigation
Levels 6-7 schedule and plan robot’s activities
Top-level is UI and supervisory
Supervisor
Global Planning
Control
Navigation
Real-world Modelling
Sensor Integration
Sensor Interpretation
Robot Control
Environment
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 13
Data-Flow style
Data-flow
BatchSequential
Pipes andFilters
• components are independent programs• each step runs to completion
before the next starts• each batch of data is transmitted as
a whole between stepsClassic data-processing approach
Goals: achieve reuse and modifiability
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 14
Pipe-and-Filter substyle
Incremental transformation of data by successive components
• Filters transform data using little contextual information and retain no state between instantiations
• Pipes are stateless and are used to move streams of data betweenfilters
A pipe’s source end connects to a filter’s output port; sink end connects to filter’s input port
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 15
Pipe-and-Filter substyle...
Pipes and filters run non-deterministically until no more computations or transmissions are possible
+ Simple to reason about, eases maintenance, enhances reuse, can easily enhance performance by parallelizing or distributing
- Interactive apps are difficult, filters can’t cooperate to solve a problem, performance is often bad
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 16
Cruise control: Pipe-and-Filter style
Design a pipe-and-filter solution given the following filters:• System State: determines overall status. If engine on and cruise control on,
then On, else Off• Clock Pulses: Transforms pulses to numeric value
• Calculate Desired Speed (CDS): determine current desired speed based on system state, whether brake is applied, and cruise state
• Calculate Throttle
• Split: takes an input and creates two output streams
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 17
Heterogeneous Use
Systems are generally built from multiple styles
Three kinds of heterogeneity:• Locationally heterogeneous: run-time structures reveal different styles in
different areas
• Hierarchically heterogeneous: a component of one style, when decomposed is structured according to another style
• Simultaneously heterogeneous: different styles depending on point of view
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 18
Data-Centered styles
Two-substyles: Repository and Blackboard
When a system can be described as a centralized data store that communicates with a number of clients
Shared DataClient
Client Client
In a (passive) repository, such asshown on left, data might bestored in a file. In an activerepository, such as a blackboard,the blackboard notifies clients whendata of interest changes (so therewould be control from datato clients)
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 19
Blackboard: Example
Captain is the overall supervisor
Map navigator is a high-level path planner
Pilot is a low-level path planner and motor controller
Perception subsystem takes data from sensors and integrates it
Perception Subsystem
Blackboard
lookout
captain
mapnavigator
pilot
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 20
Independent components style
We’ll look at the implicit invocation (event) substyle
Goals: achieve modifiability by decoupling various parts of the computation
Approach: have independent processes or objects communicate through messages
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 21
Event systems
Individual components announce data they wish to share (publish) with others
Other components may register an interest in the kind of data (subscribe). They are invoked when the data appears
How does this achieve modifiability?
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 22
Implementing event systems
Several different ways to achieve an event system:• Callbacks
• Event Handling in Java Swing
• Observer design pattern
• Event notification pattern
• Message Manager
• (this is not a complete list)
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 23
Event handling in Java Swing
Some examples:User closes a window WindowListenerTable selection changes ListSelectionListenerUser clicks a button ActionListener
Event Source
Event Listener
Event Listener
Event ListenerEventObject
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 24
Java Swing…
public class MyClass implements ActionListener {public void actionPerformed( ActionEvent e ) { … }
}
someComponent.addActionListener( instanceOfMyclass );
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 25
Observer design pattern
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 26
Limitations of observer
the basic implementation described in the pattern has some limitations
• can’t tell why an object is being told to update (except by digging through code)
• one size fits all: an observer might not be interested in all changes in the subject
• an observer has only one routine that dispatches updates
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 27
Event notification pattern
Dirk Riehle created the Event Notification Pattern to address some of these problems (http://www.riehle.org/papers/1996/tapos-1996-event.html)
An event represents an abstract state change of an object (a subject). The event notification mechanism notifies dependent objects (observers) when a change has occurred; the dependent objects can then update themselves (sometimes through explicit invocation)
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 28
Event notification pattern: How-To
Make abstract state changes for an object (a subject) visible by providing state change objects as part of its interface
A dependent object ( an observer) uses event stub objects to represent its dependencies as first-class objects
Event stubs are linked to state change objects via event link objects
Event link objects propagate change
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 29
Event notification pattern: Basic design
Observer
OpForEv1(..)OpForEv2(..)
Subject
StateChg1(..)StateChg2(..)
EventStuboperationobserver
Forward(..)
observer->operation(..)
StateChangeAnnounce(..)Register(..)
Unregister(..)
For all registeredstubs:stub->Forward(..)
1..n
1..n 1..n
Overallimplicitinvocation
Indirect invocation
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 30
Event notification pattern: Refined design
Observer
OpForEv1(..)OpForEv2(..)
Subject
StateChg1(..)StateChg2(..)
EventStuboperationobserver
Forward(..)
StateChangeAnnounce(..)Register(..)
Unregister(..)
For all registeredstubs:stub->Forward(..)
1..n
1..n 1..n
Overallimplicitinvocation
Indirect invocation
EventLink
Forward(..)
inherits
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 31
Using the event notification pattern
We will break into groups and try out the event notification pattern in class
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 32
Message manager
Sometimes you want even more flexibility
For instance, if building a programming environment, perhaps you want to be able to add tools on the fly and have them respond to events
A message manager can help• Receive messages and route them to registered parties
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 33
Heterogeneous use
Systems are generally built from multiple styles
Three kinds of heterogeneity:• Locationally heterogeneous: run-time structures reveal different styles in
different areas
• Hierarchically heterogeneous: a component of one style, when decomposed is structured according to another style
• Simultaneously heterogeneous: different styles depending on point of view
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 34
Characterizing and comparing styles
The following categories are useful in comparing and characterizing styles:
• What kinds of components and connectors are used in the style?
• What are the control structures?
• How is data communicated?
• How do data and control interact?
• What kind of reasoning does the style support?
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 35
Components & Connectors
“A component is a unit of software that performs some function at runtime.” [p.105]
“A connector is a mechanism that mediates communication, coordination, or cooperation among components” [p. 105]
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 36
Control Issues
How does control pass among components?
Topology: • What is the topology of a batch-sequential data-flow style?
• What is the topology of a main-program-and-subroutine style?
Other topologies include star, arbitrary… Topology maychange at runtime.
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 37
Control Issues...
Synchronicity: How interdependent are the component’s actions upon each other’s control states?
• E.g., lockstep - state of one component implies state of all others
• E.g., synchronous - components synchronize regularly; other state relationships are unpredictable
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 38
Control Issues...
Binding Time: When is the partner in a communication established?• Program-write time?
• Compile-time?
• Invocation-time?
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 39
Issues...
Data Issues:• Topology• Continuity: Continuous vs. sporadic; volume• Mode: Passed, shared, copy-out-copy-in, etc.• Binding Time: Same as control issue
Control/Data Interaction Issues:• Shape of control and data topologies• Directionality: does data flow in direction of control?
Type of Reasoning
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 40
Estilos de arquitectura – 2
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 41
Architectural Styles & Properties
Important concepts• Component, Connectors or Relationships• View
- A partial aspect of a software architecture that shows specific properties of a software system.
- 4 views of Software Architecture: Logical View, Process View, Physical View, Development View
• Functional Property- Deals with particular aspect of a system’s functionality.- Related to Specified Functional requirement.- Seldom explicitly stated in SAs., and mostly assumed implicitly.- Stating explicitly with Functional Properties help in traceability of an architectural
element to its functional requirements.• Non-Functional Property
- Not covered by its functional description.- Addresses aspects like reliability, compatibility, maintainability, interoperability ,
changeability, efficiency, testability and reusability of a software system.
Advantages and disadvantages
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 42
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 43
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 44
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 45
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 46
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 47
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 48
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 49
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 50
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 51
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 52
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 53
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 54
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 55
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 56
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 57
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 58
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 59
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 60
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 61
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 62
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 63
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 64
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 65
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 66
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 67
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 68
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 69
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 70
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 71
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 72
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 73
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 74
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 75
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 76
FEUP, Ademar Aguiar
Arquitectura de Sistemas de Software, 2005-06
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 77
FEUP ● Ademar Aguiar ● Arquitectura de Sistemas de Software, 2005-06 78