View
6
Download
0
Category
Preview:
Citation preview
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
MTAT.03.094
Software Engineering
Lecture 07: Architecture
and Design
Dietmar Pfahl
email: dietmar.pfahl@ut.ee Fall 2015
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Schedule of Lectures
Week 01: Introduction to SE
Week 02: Requirements Engineering I
Week 03: Requirements Engineering II
Week 04: Analysis
Week 05: Development Infrastructure I
Week 06: Development Infrastructure II
Week 07: Architecture and Design
Week 08: No lecture
Week 09: Refactoring
Week 10: Verification and Validation I
Week 11: Industry Lecture (Testing)
Week 12: Verification and Validation II
Week 13: Agile/Lean Methods
Week 14: Industry Lecture (Agile)
Week 15: Measurement / Course
wrap-up, review and exam
preparation
Week 16: no lecture
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Structure of Lecture 07
• What is it? Why bother?
• Terminology: Architect, Architecting, Architecture
• Viewpoints and View Models
• Notation
• Patterns, Styles and DSSAs
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Learning from Others:
Patterns, Styles, and DSSAs
Software Architecture: Foundations, Theory, and Practice; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; © 2008 John
Wiley & Sons, Inc. Reprinted with permission.
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
How to solve a problem?
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Examples of Domains
• Compilers for programming languages
• Consumer electronics
• Electronic commerce system/Web stores
• Video game
• Business applications
• Basic/Standard/“Pro”
We can subdivide, too: • Avionics systems -> Boeing Jets -> Boeing 747-400
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Domain-Specific Software Architectures
• A DSSA is an assemblage of software components
• specialized for a particular type of task (domain),
• generalized for effective use across that domain, and
• composed in a standardized structure (topology) effective for building successful applications.
• DSSAs are the pre-eminent means for maximal reuse of knowledge and prior development.
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Domain-Specific Software Architectures
A DSSA comprises:
• A reference architecture, which describes a general computational framework for a significant domain of applications
• A component library, which contains reusable chunks of domain expertise, and
• An application configuration method for selecting and configuring components within the architecture to meet particular application requirements
Examples:
• ADAGE for avionics, AIS for adaptive intelligent systems, and MetaH for missile guidance, navigation, and control systems
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Reference Architecture – Example
• Structural view of Lunar Lander DSSA
• Invariant with explicit points of variation
• Satellite relay
• Sensors
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Reference Architecture
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Reference Architecture
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Reference Architecture
MURA: Microsoft Upstream Reference Architecture
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
DSSAs also include …
MURA: Microsoft Upstream Reference Architecture
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Extreme Case of DSSA ...
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Product Line Architecture
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Product Line Architecture – Why?
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
How do Product Lines come to be?
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Example: Lunar Lander Game
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Example: Lunar Lander Game
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Product Lines in the Lunar Lander Game
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Product Lines in the Lunar Lander Game
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Product Lines in the Lunar Lander Game
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Product Lines: Components, Features, Products
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Product Lines: Components, Features, Products
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Product Lines: Components, Features, Products
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Product Lines: Components, Features, Products
???
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Better Representation: Variability Model
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
DSSAs vs. Product Lines
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Architectural Patterns
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
State-Logic-Display (a.k.a. Three-Tier Pattern)
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
State-Logic-Display (a.k.a. Three-Tier Pattern)
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
State-Logic-Display in Web Development
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Tiers and Layers
Note: The middle tier might be multi-tiered (resulting in an n-tier architecture)
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Model-View-Controller (MVC)
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Model-View-Controller (MVC)
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
MVC Code Example:
CalculatorModel.java
01 // The Model performs all the calculations needed
02 // and that is it. It doesn't know the View exists
03
04 public class CalculatorModel {
05
06 // Holds the value of the sum of the numbers
07 // entered in the view
08
09 private int calculationValue;
11
12 public void addTwoNumbers(int firstNumber, int secondNumber){
13
14 calculationValue = firstNumber + secondNumber;
16 }
17
18 public int getCalculationValue(){
19
20 return calculationValue;
22 }
24 }
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
MVC Code Example:
CalculatorView.java (1) 01 // This is the View
02 // Its only job is to display what the user sees. It performs no calculations,
03 // but instead passes information entered by the user to whomever needs it.
06
07 import java.awt.event.ActionListener;
09 import javax.swing.*;
10
11 public class CalculatorView extends JFrame{
12
13 private JTextField firstNumber = new JTextField(10);
14 private JLabel additionLabel = new JLabel("+");
15 private JTextField secondNumber = new JTextField(10);
16 private JButton calcButton = new JButton("Calc");
17 private JTextField calcSolution = new JTextField(10);
18
19 CalculatorView(){
20
21 // Sets up the view and adds the components
22
23 JPanel calcPanel = new JPanel();
24
25 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
26 this.setSize(600, 200);
27
28 calcPanel.add(firstNumber);
29 calcPanel.add(additionLabel);
30 calcPanel.add(secondNumber);
31 calcPanel.add(calcButton);
32 calcPanel.add(calcSolution);
33
34 this.add(calcPanel);
35
36 // End of setting up the components --------
38 }
Num1 Num2 +
Calc Sum
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
MVC Code Example:
CalculatorView.java (2) 39
40 public int getFirstNumber(){
42 return Integer.parseInt(firstNumber.getText());
44 }
45
46 public int getSecondNumber(){
48 return Integer.parseInt(secondNumber.getText());
50 }
51
52 public int getCalcSolution(){
54 return Integer.parseInt(calcSolution.getText());
56 }
57
58 public void setCalcSolution(int solution){
60 calcSolution.setText(Integer.toString(solution));
62 }
63
64 // If the calcButton is clicked execute a method
65 // in the Controller named actionPerformed
66
67 void addCalculateListener(ActionListener listenForCalcButton){
69 calcButton.addActionListener(listenForCalcButton);
71 }
72
73 // Open a popup that contains the error message passed
74
75 void displayErrorMessage(String errorMessage){
77 JOptionPane.showMessageDialog(this, errorMessage);
79 }
81 }
Num1 Num2 +
Calc Sum
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
MVC Code Example:
CalculatorController.java (1)
01 import java.awt.event.ActionEvent;
02 import java.awt.event.ActionListener;
03
04 // The Controller coordinates interactions
05 // between the View and Model
06
07 public class CalculatorController {
08
09 private CalculatorView theView;
10 private CalculatorModel theModel;
11
12 public CalculatorController(CalculatorView theView, CalculatorModel theModel) {
13 this.theView = theView;
14 this.theModel = theModel;
15
16 // Tell the View that whenever the calculate button
17 // is clicked to execute the actionPerformed method
18 // in the CalculateListener inner class
19
20 this.theView.addCalculateListener(new CalculateListener());
21 }
22
More on the value and advantage of using inner classes (like CalculateListener): http://www.javaworld.com/article/2077411/core-java/inner-classes.html
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
MVC Code Example:
CalculatorController.java (2)
23 class CalculateListener implements ActionListener{
24
25 public void actionPerformed(ActionEvent e) {
26
27 int firstNumber, secondNumber = 0;
28
29 // Surround interactions with the view with
30 // a try block in case numbers weren't
31 // properly entered
32
33 try{
34
35 firstNumber = theView.getFirstNumber();
36 secondNumber = theView.getSecondNumber();
37
38 theModel.addTwoNumbers(firstNumber, secondNumber);
39
40 theView.setCalcSolution(theModel.getCalculationValue());
42 }
43
44 catch(NumberFormatException ex){
45
46 System.out.println(ex);
48 theView.displayErrorMessage("You Need to Enter 2 Integers");
50 }
52 }
54 }
56 }
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
MVC Code Example:
MVCCalculator.java
01 public class MVCCalculator {
02
03 public static void main(String[] args) {
04
05 CalculatorView theView = new CalculatorView();
06
07 CalculatorModel theModel = new CalculatorModel();
08
09 CalculatorController theController = new CalculatorController(theView,theModel);
10
11 theView.setVisible(true);
12
13 }
14 }
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Two Flavors of MVC: Passive Model
• The passive model is employed when one controller manipulates the model exclusively.
• The controller modifies the model and then informs the view that the model has changed and should be refreshed.
• The model is completely independent of the view and the controller, i.e. there is no means for the model to report changes in its state.
• The HTTP protocol is an example of this. There is no simple way in the browser to get asynchronous updates from the server. The browser displays the view and responds to user input, but it does not detect changes in the data on the server.
• Only when the user explicitly requests a refresh is the server interrogated for changes.
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Two Flavors of MVC: Active Model
Solution: Observer Design Pattern!
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Two Flavors of MVC: Active Model
Figure shows the structure of the active MVC using Observer and how the observer isolates the model from referencing views directly.
Java code example: http://en.wikipedia.org/wiki/Observer_pattern
Observer Pattern:
The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods. It is mainly used to implement distributed event handling systems.
ConcreteObserver = ’listener’ in Java swing framework!
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Benefits and Liabilities of MVC
Benefits
Liabilities
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Patterns, Styles, and DSSAs
Software Architecture: Foundations, Theory, and Practice; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; © 2008 John
Wiley & Sons, Inc. Reprinted with permission.
• Pipes and filters • Data abstraction and
object-oriented organization
• Layered systems • Repositories • Event-based, implicit
invocation • ... and many more
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Design Patterns
• A design pattern is a way of reusing abstract knowledge about a problem and its solution.
• A pattern is a description of the problem and the essence of its solution.
• It should be sufficiently abstract to be reused in different settings.
• Pattern descriptions usually make use of object-oriented characteristics such as inheritance and polymorphism.
ELEMENTS:
Name
A meaningful pattern identifier.
Problem description.
Solution description (might have an example)
Not a concrete design but a template for a design solution that can be instantiated in different ways.
Benefits and Consequences
The results and trade-offs of applying the pattern.
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
The Observer Pattern
Name: Observer
Problem description
• Situations where multiple displays of state are needed.
Solution description
• Separates the display of object state from the object itself.
• See UML description.
Consequences
• Optimisations to enhance display performance are difficult.
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Three Types of
Patterns
Creational patterns:
• Deal with initializing and configuring classes and objects
Structural patterns:
• Deal with decoupling interface and implementation of classes and objects
• Composition of classes or objects
Behavioral patterns:
• Deal with dynamic interactions among societies of classes and objects
• How they distribute responsibility
Observer
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Benefits of Design Patterns
• Design patterns enable large-scale reuse of software architectures and also help document systems
• Patterns explicitly capture expert knowledge and design tradeoffs and make it more widely available
• Patterns help improve developer communication
• Pattern names form a common vocabulary
More on Design Patterns: Mini-Tutorials by Derek Banas https://www.youtube.com/playlist?list=PLF206E906175C7E07
MTAT.03.094 / Lecture 07 / © Dietmar Pfahl 2015
Further Reading
• Len Bass et al, Sofware Architecture in Practice, 2008 (3rd edition).
• Jan Bosch, Design & Use of Software Architectures, 2000.
• Frank Buschmann et al., Pattern-Oriented Software Architecture: A System of Patterns, 1996. Part II: 2001.
• George Fairbanks: Just Enough Software Architecture, 2012.
• Erich Gamma et al., Design Patterns: Elements of Reusable Object-Oriented Software, 1995.
• C. Hofmeister et al., Applied Software Architecture, 1999.
• Philippe B. Kruchten, The 4+1 view model of architecture, IEEE Software, 12(6):42-50, November 1995.
• Mary Shaw and David Garlan, Software Architecture; Perspectives of an Emerging Discipline, 1995.
• Richard Taylor et al.: Software Architecture, University of California at Irvine, Lecture 2011.
• Ian Sommerville: Software Engineering, 9th edition, 2010. (http://www.softwareengineering-9.com/)
• Hans van Vliet: Software Architecture, Free University of Amsterdam, Lecture 2008.
Recommended