software architecture - university of washington · software architecture. outline 2 • what is a...

44
Emina Torlak [email protected] CSE 403: Software Engineering, Winter 2016 courses.cs.washington.edu/courses/cse403/16wi/ Software Architecture

Upload: others

Post on 20-Jun-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Emina Torlak [email protected]

CSE 403: Software Engineering, Winter 2016courses.cs.washington.edu/courses/cse403/16wi/

Software Architecture

Page 2: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Outline

2

• What is a software architecture?

• What does an architecture look like?

• What is a good architecture?

• Properties of architectures

• Example architectures

Page 3: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

basicssoftware architecture: motivation & definition

Page 4: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Why software architecture?

4

“There are two ways of constructing a software design: one way is to make it so simple that there are obviously no deficiencies; the other is to make it so complicated that there are no obvious deficiencies.”

C.A.R. Hoare (1985)

Page 5: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

The basic problem: from requirements to code

5

Requirements

Code

??

How to bridge the gap between requirements and code?

Page 6: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

The basic problem: solve with inspiration

6

Requirements

Code

a miracle happens

Page 7: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

The basic problem: solve with engineering

7

Requirements

Code

Software Architecture

Provides a high-level framework to build and evolve a software system.

Page 8: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

depictwhat does an architecture look like?

Page 9: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Box and arrow diagrams

9

Very common and highly valuable.

But what does a box represent? An arrow? A layer? Adjacent boxes?

Page 10: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

An architecture: components and connectors

10

• Components define the basic computations comprising the system and their behaviors

• abstract data types, filters, etc.

• Connectors define the interconnections between components

• procedure call, event announcement, asynchronous message sends, etc.

• The line between them may be fuzzy at times• A connector might (de)serialize data, but can it perform

other, richer computations?

Page 11: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

• UML = unified modeling language

• A standardized way to describe (draw) architecture

• Also implementation details such as subclassing, uses (dependences), and much more

• Widely used in industry

• Topic of next lecture

A standard notation for architecture: UML

11

Page 12: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

judgewhat is a good architecture?

Page 13: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

A good architecture …

13

• Satisfies functional and performance requirements

• Manages complexity

• Accommodates future change

• Is concerned with• reliability, safety, understandability,

compatibility, robustness

Page 14: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

A good architecture …

13

• Satisfies functional and performance requirements

• Manages complexity

• Accommodates future change

• Is concerned with• reliability, safety, understandability,

compatibility, robustness

Leads to modularity and separation of concerns.

Page 15: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

A modular architecture helps with …

14

• System understanding: interactions between modules

• Reuse: high-level view shows opportunity for reuse

• Construction: breaks development down into work items

• Evolution: high-level view shows evolution path

• Management: helps understand work items and track progress

• Communication: provides vocabulary; a picture says 1000 words

Page 16: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

You know your software is modular when it is …

15

Page 17: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

You know your software is modular when it is …

15

• Decomposable• can be broken down into pieces

Page 18: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

You know your software is modular when it is …

15

• Decomposable• can be broken down into pieces

• Composable• pieces are useful and can be combined

Page 19: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

You know your software is modular when it is …

15

• Decomposable• can be broken down into pieces

• Composable• pieces are useful and can be combined

• Understandable• one piece can be examined in isolation

Page 20: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

You know your software is modular when it is …

15

• Decomposable• can be broken down into pieces

• Composable• pieces are useful and can be combined

• Understandable• one piece can be examined in isolation

• Adaptable• change in requirements affects few modules

Page 21: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

You know your software is modular when it is …

15

• Decomposable• can be broken down into pieces

• Composable• pieces are useful and can be combined

• Understandable• one piece can be examined in isolation

• Adaptable• change in requirements affects few modules

• Safe• an error affects few other modules

Page 22: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Achieving modularity: think about interfaces

16

• Public interface: data and behavior of the object that can be seen and executed externally by "client" code.

• Private implementation: internal data and methods in the object, used to help implement the public interface, but cannot be directly accessed.

• Client: code that uses your module.

Page 23: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Achieving modularity: think about interfaces

16

• Public interface: data and behavior of the object that can be seen and executed externally by "client" code.

• Private implementation: internal data and methods in the object, used to help implement the public interface, but cannot be directly accessed.

• Client: code that uses your module.

Page 24: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Achieving modularity: think about interfaces

16

• Public interface: data and behavior of the object that can be seen and executed externally by "client" code.

• Private implementation: internal data and methods in the object, used to help implement the public interface, but cannot be directly accessed.

• Client: code that uses your module. Public interface is the speaker, volume buttons, station dial.

Private implementation is the guts of the radio (transistors, capacitors, voltage readings, etc.) that user should not see.

Page 25: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

knowproperties of architectures

Page 26: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Key properties of an architecture

18

• Coupling

• Cohesion

• Style conformity

• Matching

Page 27: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Coupling (loose vs tight)

19

• Coupling: the kind and quantity of interconnections among modules

• Modules that are loosely coupled (or uncoupled) are better than those that are tightly coupled

• The more tightly coupled two modules are, the harder it is to work with them separately

Page 28: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Tightly or loosely coupled?

20

User Interface Graphics

Data StorageApplication Level Classes

Business Rules Enterprise Level Tools

-End1

*

-End2

*-End3

*

-End4*

-End5

*

-End6

*

-End7*

-End8*

-End9*

-End10

*

-End11*

-End12*

-End13

*

-End14*

-End15

*

-End16

*

-End17

*

-End18

*

-End19*

-End20*

-End21

*

-End22

*

-End23*-End24*

-End25*-End26*

Page 29: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Tightly or loosely coupled?

21

User Interface Graphics

Data Storage Application Level Classes

Business Rules Enterprise Level Tools

-End1

*

-End2

*

-End3*

-End4

*

-End5*

-End6*

-End9

*

-End10

*

-End11

*

-End12

*

-End13*

-End14*

-End15*

-End16*

-End7*

-End8 *

Page 30: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Cohesion (strong vs weak)

22

• Cohesion: how closely the operations in a module are related

• Tight relationships improve clarity and understanding

• Classes with good abstraction usually have strong cohesion

• No schizophrenic classes!

Page 31: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Strong or weak cohesion?

23

class Employee {

public:

FullName GetName() const; Address GetAddress() const; PhoneNumber GetWorkPhone() const;

bool IsJobClassificationValid(JobClassification jobClass); bool IsZipCodeValid (Address address); bool IsPhoneNumberValid (PhoneNumber phoneNumber);

SqlQuery GetQueryToCreateNewEmployee() const; SqlQuery GetQueryToModifyEmployee() const; SqlQuery GetQueryToRetrieveEmployee() const;

… }

Page 32: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Style conformity: what is a style?

24

• An architectural style defines • The vocabulary of components and connectors for a family

of architectures

• Constraints on the elements and their combination

• Topological constraints (no cycles, etc.)

• Execution constraints (timing, etc.)

• By choosing a style, one gets all the known properties of that style (for any architecture in that style)

• For example: performance, lack of deadlock, ease of making particular classes of changes, etc.

Page 33: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Style conformity: more than boxes and arrows

25

• Consider pipes & filters (Garlan and Shaw)• Pipes must compute local transformations

• Filters must not share state with other filters

• There must be no cycles

• If these constraints are violated, it’s not a pipe & filter system• One can’t tell generally this from a picture

• One can formalize these constraints

Page 34: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Style conformity: more than boxes and arrows

25

• Consider pipes & filters (Garlan and Shaw)• Pipes must compute local transformations

• Filters must not share state with other filters

• There must be no cycles

• If these constraints are violated, it’s not a pipe & filter system• One can’t tell generally this from a picture

• One can formalize these constraints

scan parse optimize generate

Page 35: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Component matching

26

• Components in an architecture match if they make compatible assumptions about their operating environment (Garlan, Allen, Ockerbloom).

• Mismatches lead to • Excessive code size

• Poor performance

• Error-prone construction

• Having to modify off-the-shelf components

July/August 2009 I E E E S O F T W A R E 67

two things would be necessary. First, design-ers must change how they build components intended to be part of a larger system. Second, the software community must provide new no-tations, mechanisms, and tools that let designers accomplish this.

The World Has ChangedIn the decade and a half since that publication, the state of the practice in component-based reuse has changed dramatically. The problems we identified might seem behind us. Today’s software systems routinely build on many layers of reusable infra-structure (for example, for distributed communi-cation and remote data access), interact with us-ers through standard interfaces (for example, Web browsers), and use large corpuses of open source software (for example, Apache Tomcat). They also have sophisticated development environments that provide direct access to reuse libraries (for ex-ample, Eclipse and NetBeans), and they exploit services created in a global virtual operating en-vironment. Indeed, for every line of code that de-velopers write, they reuse thousands of lines writ-ten by someone else.

But has the problem gone away, or has it simply found a new home in a more modern setting?

The State of Architectural Mismatch TodayThree basic techniques exist for dealing with ar-chitectural mismatch. One is to prevent it. An-other is to detect it when it does occur, hopefully early in the development life cycle, when you can easily consider alternatives. The third is to repair it when it is unavoidable. Modern software develop-ment methods have made advancements in each of these techniques.

Preventing Architectural MismatchThis technique has benefited from developments in a number of areas, including architectural spe-

cialization, open source practices, and virtualiza-tion and common user interfaces.

Architectural specialization. One way to help pre-vent architectural mismatch is to work in an archi-tecturally specialized design domain. Specializa-tion restricts the range of permissible components and the interactions between them, thereby elimi-nating some of the variability that contributes to mismatch.

Figure 2 illustrates common points in the spe-cialization space. At the far left are completely un-constrained architectures. (This would arguably include the system we described in our original article.) Moving to the right, architectures must fit in a narrower design context—for example, ge-neric styles, such as data flow and call-return.3,4 More specific still are specializations of those styles, such as pipes and filters. Further to the right are component integration standards, which typically dictate the kinds of connectors you can use, the kinds of interfaces that components must have, and the global control structures. Next are domain-specific integration standards, and to the far right are product lines.

Assumptions about the application domain

Assumptions about components at the same level

of abstraction

Assumptions about infrastructure

Figure 2. The spectrum of architectural specialization. The figure depicts representative points along a spectrum that characterizes the degrees of specialization, or domain specificity, of a class of architectures. Elements below the axis are examples of architectures in each class.

Figure 1. Three facets of component interaction.1 Each facet identifies a set of assumptions that a component may make about its environment.

Page 36: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Interface mismatch

27

NASA lost a $125 million Mars orbiter because one engineering team used metric units while another used English units for a key spacecraft operation.

Page 37: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

studyexample architectures

Page 38: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Client-server architecture

29

Page 39: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Client-server architecture

29

Separates the client and the server.

Page 40: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Model, view, controller (MVC)

30

Page 41: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Model, view, controller (MVC)

30

Separates:

• the application object (model)

• the way it is represented to the user (view)

• the way in which the user controls it (controller)

Page 42: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Shared nothing (SN) architecture

31

Network

Proc 1

Memory

Proc 2

Memory

Proc N

Memory…

Page 43: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Shared nothing (SN) architecture

31

Separates individual components (nodes) from each other.

Network

Proc 1

Memory

Proc 2

Memory

Proc N

Memory…

Page 44: Software Architecture - University of Washington · Software Architecture. Outline 2 • What is a software architecture? ... • Accommodates future change • Is concerned with

Summary

32

• An architecture provides a high-level framework to build and evolve a software system.

• Strive for modularity: strong cohesion and loose coupling.

• Consider using existing architectural styles or patterns.