• No results found

Advanced Topics in model-based Software Development

N/A
N/A
Protected

Academic year: 2021

Share "Advanced Topics in model-based Software Development"

Copied!
51
0
0

Loading.... (view fulltext now)

Full text

(1)

model-based

Software Development

Prof. Dr. Bernhard Rumpe

Software Systems Engineering

Technische Universität Braunschweig http://www.sse-tubs.de/

(2)

bei/08.10.16.ASD

TU Braunschweig

Seite1

Trends in software development

ƒ Size and complexity of systems continually increase:

• Isolated solutions → company-wide integration → E-Commerce

→ Systems-Of-Systems → World-Wide Cyber-Infrastructure

ƒ New technologies:

• EJB, XML, .Net, ...

ƒ Diversification of application domains:

• Embedded systems, business systems, telecommunication, mobility, ad-hoc changing infrastructures

ƒ Growing methodological experience how to deal with challenges • Agile Methods, e.g, address

unstable requirements, time-to-market pressure, lean and effective development for small projects

• Improved analytical techniques

(3)

bei/08.10.16.ASD

TU Braunschweig

Seite2

Very short overview of Extreme Programming

ƒ „Best Practices“.

ƒ Abandons many software development elements

ƒ Activities (among others)

Coding

• Incremental

• Coding standards • Runs of all tests • Refactoring

Testing

• Tests developed together with the code • Functional tests

(4)

bei/08.10.16.ASD

TU Braunschweig

Seite3

Idealized View on Model Driven Architecture

application classes define data structures (PIM)

system complete and running system

class diagram Nr. 2 („PSM“):

adaptation, extension, technical design T

T T T

T T T

T

+ behavior for technical classes

code generation +

integration with manually written code state machines describe

states and behavior

Requirement

use cases and scenarios:

(5)

bei/08.10.16.ASD

TU Braunschweig

Seite4

Problems of Model Driven Architecture

system T T T T T T T T Requirement • No reuse

• Tool chain too long • No efficient tools • Tracing problems • Evolution is awkward

• Lot of information missing, e.g. - Design rationale

- Non-functional reqs.

• “Agile” development is not possible

• SE-Models are not integrated with other Engineering Models (spatial, biological, ...)

(6)

bei/08.10.16.ASD

TU Braunschweig

Seite5

Core elements of an agile modelling method

ƒ Incremental modelling

ƒ Modelling tests

ƒ Automatic analysis: Types, dataflow, control flow, ...

ƒ Code generation for system and tests from compact models

ƒ Small increments

ƒ Intensive simulation with customer participation for feedback

ƒ Refactoring for incremental extension and optimisation

ƒ Common ownership of models

ƒ ...

This approach uses elements of agile methods based on the UML notation

(7)

bei/08.10.16.ASD

TU Braunschweig

Seite6

ƒ Two kinds of models are used for the system and the executable

tests

Model-based “programming”

consistency analyser „smells“ & errors statecharts class diagrams C++, Java … parameterized code generator system deployment diagram sequence diagrams object diagrams __: __: __: OCL test code generator tests

(8)

bei/08.10.16.ASD

TU Braunschweig

Seite7

How the approach supports agile development

Core characteristics of agility: Improvement through use of UML:

Reactivity:

flexibility to deal with changes

+ incremental, small cycles + model-based refactoring

Efficiency

of the developers

+ increased through advanced notation & tools

Rely on individuals + less tedious work

? skilled people are necessary

Simplicity + refactoring increases extensibility

Customer focus + even more rapid feedback

Quality

is an emerging property

+ automated tests

+ common ownership &

pairwise development of models + better review-able designs

(9)

bei/08.10.16.ASD

TU Braunschweig

Seite8

(10)

bei/08.10.16.ASD

TU Braunschweig

Seite9

Typical infrastructure of an automated test

objects under test o1 o3 o4 o2 o1 o3 o4 o2 o5 ƒ Principle: use

• relatively complete object diagram (OD) for test data

• partial OD and OCL as oracle

• sequence diagram (SD) or Java as test driver

+

test data test driver

expected result and/or OCL-contract as test oracle OD OD OCL SD or Java

(11)

bei/08.10.16.ASD

TU Braunschweig

Seite10

description

ƒ linear structure of an exemplaric system run

ƒ + OCL for property description

OCL constraints describe

properties during the test run

copper912: Auction bidPol: BiddingPolicy timePol: TimingPolicy test driver validateBid(bid) return OK return t newCurrentClosingTime(copper912, bid) t.time == bid.time + extensionTime «trigger» handleBid(bid) SD

(12)

bei/08.10.16.ASD

TU Braunschweig

Seite11

Test pattern

ƒ Systems need to be testable

ƒ Example: Side effects like file protocol must be captured

redefined method

stores arguments in attribute: no side effects and results can be checked

method with side effects logs its text in a file

Protocol

void setLogfile (String filename) void writeToLog (String text)

ProtocolDummy

void writeToLog (String text) String logLastLine = ““

int logCount = 0

Test pattern describe typical processes & structures for test definition

(13)

bei/08.10.16.ASD

TU Braunschweig

Seite12

Test pattern for standard problems

ƒ side effects (DB, GUI)

capsule with adapter & dummies

ƒ static attributes

capsule with singleton object

ƒ object creation

factory

ƒ frameworks

separation of application and

framework through adapter

ƒ time

simulation through controllable

clock

ƒ concurrency

simulation through explicit

scheduling

(14)

bei/08.10.16.ASD TU Braunschweig Seite13

Testing of

embedded software

through simulation

(15)

bei/08.10.16.ASD

TU Braunschweig

Seite14

Simulation for autonomic driving

ƒ Caroline, an autonomously driving car in the DARPA Urban

Challenge 2007

ƒ Testing the intelligence

ƒ The context is:

• a street map • pedestrians

• other cars driving • ...

ƒ Use of SE-models (e.g. state machines) and other kinds of models

(e.g. maps) to feed the simulation engine

• Simulation as technology to early capture problems • and validate (as well understand) requirements.

(16)

bei/08.10.16.ASD

TU Braunschweig

Seite15

Simulation Runs

ƒ

virtual journeys in complex traffic situations

ƒ

automatic regression tests

ID = 22 v = 4m/s

loc = (23.4; -12.2)

(17)

bei/08.10.16.ASD

TU Braunschweig

Seite16

Simulation Runs

ƒ

virtual journeys in complex traffic situations

(18)

bei/08.10.16.ASD

TU Braunschweig

Seite17

ƒ Test-Infrastructure needs simulation of its context:

ƒ context can be: geographical, sociological, etc.

ƒ Simulation helps to understand complexity

Model-based simulation for SE

statecharts class diagrams C++, Java … system deployment diagram sequence diagrams object diagrams __: __: __: OCL tests Further DSLs Further DSLs

(19)

bei/08.10.16.ASD

TU Braunschweig

Seite18

Model-Based

(20)

bei/08.10.16.ASD

TU Braunschweig

Seite19

Software Evolution

ƒ “Software evolution is the key problem in software development.”

Oscar Nierstrasz

ƒ Requirements change

ƒ Platforms and system contexts evolve

ƒ Bugs needs to be fixed

ƒ Time and space optimisations are desired

ƒ ⇒ Existing software needs to be evolved

ƒ ⇒ Code as well as models need to be adapted to keep them

(21)

bei/08.10.16.ASD

TU Braunschweig

Seite20

Refactoring as a special form of transformation

ƒ Refactoring is a technique to

• improve internal structure / architecture of a system, while • preserving observable behaviour

ƒ Refactoring rules:

• series of systematically applicable, goal directed steps

ƒ Powerful through

• simplicity of piecewise application and

• flexibility of combination of systematic steps

ƒ Roots:

• Opdyke/Johnson 1992 had 23 refactorings on C++

(22)

bei/08.10.16.ASD

TU Braunschweig

Seite21

Refactoring example 1

ƒ Pull Up Attribute “ident” into superclass: structural generalization

ƒ Factor Method “checkPasswd()” and adapt it

ƒ Preservation of observable behaviour?

• depends on viewpoint: class, component, system

Person Guest checkPasswd() Bidder long ident checkPasswd() Bidder Person checkPasswd() long ident Guest Refactoring CD CD

(23)

bei/08.10.16.ASD

TU Braunschweig

Seite22

Principle of refactoring

ƒ Refactoring is orthogonal to adding functionality

ƒ An idealised diagram:

quality of design functionality

programming refactoring

target: 100% of the functionality, acceptable design

100% 100%

(24)

bei/08.10.16.ASD

TU Braunschweig

Seite23

Example: moving an attribute

ƒ Attribute „att“ shall be moved from class A to B

// code

a.att a.exp is the navigation path from A to B

A att … B … ⇓ A … B att … /connection 1 1 {frozen} … // Code a.exp.att ⇓ context A a inv: a.connection == a.exp; context A a1, A a2 inv:

a1 != a2 implies a1.connection != a2.connection CD … A … B att … CD Code CD Code OCL

(25)

bei/08.10.16.ASD

TU Braunschweig

Seite24

Refactoring example: changing data structures

A series of steps to apply: 1. Identify old data structure:

here: long to be replaced by Money

long currentBidInCent

Auction …

2. Add new datastructure + queries

+ compile Money bestBid long currentBidInCent Auction … currentBidInCent = ... bestBid.setValue... assert M

4. Add code for new data structure & invariants wherever old data structure is changed

+ compile & run tests

context Auction inv M: currentBidInCent ==

bestBid.valueInCent() 3. Identify invariants to relate both

5. Modify places where old data structure was used

+ compile & run tests

= ... currentBidInCent ...

= ... bestBid.valueInCent() ...

6. Simplify + compile & run tests

7. Remove old data structure + compile & run tests

Money bestBid

(26)

bei/08.10.16.ASD

TU Braunschweig

Seite25

Test as observation for refactoring

ƒ Both structure and behaviour are observed by tests

test = driver and “observer”

setup & call compare with expected result time axis snapshots of the test run observe creation check property observe interaction

(27)

bei/08.10.16.ASD

TU Braunschweig

Seite26

Validation of refactorings using tests

ƒ Observation remains invariant under refactoring

test: driver and “observer”

Observation

test: driver and “observer”

Refactoring

Observation

(28)

bei/08.10.16.ASD

TU Braunschweig

Seite27

Evolution as strategic refactoring

ƒ Evolution in the small supports evolution in the large

ƒ Evolution in the small:

• Transformation rules

= small, manageable and systematic steps

ƒ General goals of transformations:

• reasoning,

• deriving implementation oriented artefacts, • building abstractions e.g. for reengineering, • evolutionary improvement

ƒ Transformation calculi can serve as technical basis for an

(29)

bei/08.10.16.ASD

TU Braunschweig

Seite28

Examples for Transformational Development

ƒ Mathematical calculi for reasoning

ƒ State machine transformations for error completion,

determinism, …

ƒ Stepwise refinement of programs

(Bauer, Partsch) for software development

ƒ Hoare calculus for reasoning over programs

ƒ Refactoring (Opdyke, Fowler) for evolution

(30)

bei/08.10.16.ASD

TU Braunschweig

Seite29

Streams & Behaviors

ƒ Communication histories over channels are modeled by

streams:

• streams s = <1,2,a,3,b,b, ...>

ƒ Channel valuations assign streams to channel names: −→C = C M

ƒ An I/O behavior relates input and output channel valuations:

β : −→I P(−→O)

(31)

bei/08.10.16.ASD

TU Braunschweig

Seite30

Kinds of Transformations

ƒ Behavioral Refinement:

• A behavior β

is a refinement of a behavior β

x

:

β

(x)

β

(x)

ƒ Structural Refinement (Decomposition)

(32)

bei/08.10.16.ASD TU Braunschweig Seite31

Semantics of Transformations

Refinement relation =, ⊆ Blackbox behavior Blackbox behavior Transformation rules:

•Add or remove components •Add or remove channels •Refine component behavior •Fold and unfold subsystems

(33)

bei/08.10.16.ASD

TU Braunschweig

Seite32

Example: Communication System

ƒ Data (Consisting of key and value) is accepted via „In“

ƒ and transmitted to the „Remote Data Base“ (RDB)

ƒ Upon sending a key, the requested value is sent

ƒ Problem:

• Transmission from Stub to RDB shall be encrypted

ƒ Solution:

• We evolve the part of the system, we are currently focusing on

Stub RDB

In Key

Req Data

(34)

bei/08.10.16.ASD

TU Braunschweig

Seite33

Example: Communication System

ƒ Step 0:

• Decide what „observed behavior“ will be that is not changed. • Here, we group the observed channels into a component

Stub RDB

In Key

Req Data

(35)

bei/08.10.16.ASD

TU Braunschweig

Seite34

Example: Communication System

ƒ Step 1:

• Add encryption and decryption components

• No connection to the rest of the system: Nothing bad can happen

Stub RDB

In Key

Req Data

(36)

bei/08.10.16.ASD

TU Braunschweig

Seite35

Example: Communication System

ƒ Step 2:

• Define signature and behavior of new components (may be we reuse of the shelf components?)

• Still no connection to the rest of the system: Nothing bad can happen

Stub RDB

In Key

Req Data

(37)

bei/08.10.16.ASD

TU Braunschweig

Seite36

Example: Communication System

ƒ Step 3:

• connect Input and output channels

• RDB now has an additional input channel, but doesn‘t use it yet • Still nothing bad can happen

Stub RDB‘

In Key

Req Data

ENC CData DEC Data

(38)

bei/08.10.16.ASD

TU Braunschweig

Seite37

Example: Communication System

ƒ Step 4:

• establish invariant between channels:

• CData = encrypt* (Data)

• Data‘ = Data (modulo time)

• RDB‘ now can use Data‘ instead of Data

Stub RDB‘

In Key

Req Data

ENC CData DEC Data

(39)

bei/08.10.16.ASD

TU Braunschweig

Seite38

Example: Communication System

ƒ Step 5:

• Remove unused channel Data

Stub RDB‘

In Key

Req ENC CData DEC Data

(40)

bei/08.10.16.ASD

TU Braunschweig

Seite39

Example: Communication System

ƒ Step 6:

• Fold new parts into subcomponents

Stub RDB‘

In Key

Req ENC CData DEC Data

(41)

bei/08.10.16.ASD

TU Braunschweig

Seite40

Constructive use of Models + Evolution

consistency analyser „smells“ & errors statecharts class diagrams C++, Java … parameterized code generator system deployment diagram sequence diagrams object diagrams __: __: __: OCL test code generator tests

(42)

bei/08.10.16.ASD

TU Braunschweig

Seite41

Conclusion

ƒ Further diversification of SE techniques / tools / methods leads to a

portfolio of SE techniques

ƒ Intelligent use of models allows to improve development

ƒ Methodical knowledge allows more efficient processes • correctness by construction

• automated tests over documentation and reviews

• evolutionary development (refactoring) over big-upfront-design phase

(43)

bei/08.10.16.ASD

TU Braunschweig

Seite42

(44)

bei/08.10.16.ASD

TU Braunschweig

Seite43

State machines

ƒ A state machine is a tupel A=(S,M,δ,I) consisting of:

• set of states S,

• set of input and output messages M,

• state transition relation δ: (S×M) → 2(S×M*) and

• set I ⊆ S×M* of initial states and outputs

ƒ Nondeterminism = underspecification

(45)

bei/08.10.16.ASD

TU Braunschweig

Seite44

State machines

ƒ A state machine is a tupel A=(S,M,δ,I) consisting of:

• set of states S,

• set of input and output messages M,

• state transition relation δ: (S×M) → 2(S×M*) and

• set I ⊆ S×M* of initial states and outputs

ƒ Nondeterminism = underspecification

(46)

bei/08.10.16.ASD

TU Braunschweig

Seite45

Semantics of a state machine

ƒ One transition contains one input message and a sequence of

output messages

ƒ Semantics is a relationship between input and output streams

M : (S,M,δ,I) → 2(M* ×M*)

ƒ Behavioral refinement between automata:

A1 A2 iff M[A1] ⊇ M[A2]

ƒ Refinement rules can be used to

• constrain (detail) behavior description • inherit state machines

(47)

bei/08.10.16.ASD

TU Braunschweig

Seite46

Example transformation rule

ƒ If preconditions are present, the remaining transition must overlap

the removed transition. This must be proven.

A B C foo A B C foo foo ƒ Remove a transition: • if there is an alternative

(48)

bei/08.10.16.ASD

TU Braunschweig

Seite47

Example transformation rule 2

ƒ Multiplies transitions

• useful to remove unwanted transitions

A B1 B2 foo foo A B foo ƒ Split a state

(49)

bei/08.10.16.ASD

TU Braunschweig

Seite48

Example: Statemachine for class Figure

1. Intro. state Sel(ected)

Sel NotSel

2. Intro. state NotSel(ected)

4. Constrain method selectin state NotSel

select/render 3. Define init states

/draw&render /draw

deselect/unrender 5. deselectin state Sel

Error

6. introduce error state

select/ deselect/ deselect/error deselect/ 7. error completion using underspecification

(50)

bei/08.10.16.ASD

TU Braunschweig

Seite49

1. Intro. state Sel(ected)

Sel NotSel

2. Intro. state NotSel(ected)

4. Constrain method selectin state NotSel

select/render 3. Define init states

/draw&render /draw

deselect/unrender 5. deselectin state Sel

Error

6. introduce error state

select/ deselect/ deselect/error deselect/ 7. error completion using underspecification

Example: Statemachine for class Figure

8. specialize deselect: remove transition 9. remove error state 10. specialize initial states NotSel

(51)

bei/08.10.16.ASD

TU Braunschweig

Seite50

1. Intro. state Sel(ected)

Sel NotSel

2. Intro. state NotSel(ected)

4. Constrain method selectin state NotSel

select/render 3. Define init states

/draw&render

deselect/unrender 5. deselectin state Sel 6. introduce error state deselect/

7. error completion

using underspecification

Example: Statemachine for class Figure

8. specialize deselect: remove transition 9. remove error state 10. specialize initial states NotSel

Each step is a refinement of the

References

Related documents

This paper endeavors to investigate the proper translation techniques and strategies used to translate military slang terms which have only partial or no

The coverages for our other lines have been designed to match the needs of small- to mid-sized employers from a broad range of classes, particularly “Main-Street America”

Let us present our approach for one entity: a dataset corresponding to one of the 27 EU Member States (or the EU), one chapter of the nomenclature (or all 99 chapters), and one type

As a result, moving from the complete-market economy with simple utility function to our benchmark economy with incomplete markets and non-constant elasticity of substitution lowers

3 Complete the Third conditional sentences with the correct form of the verbs in brackets.. 1 Ellie’s lost all her work on

It presents the results of research studies dealt with at the health education department at Charles University in Prague - Faculty of Education, which surveyed

This study investigated the language learning beliefs of Iranian EFL learners (i.e., beliefs about foreign language aptitude, the difficulty of language leaning, the nature of

based on the Pediatric Sleep Questionnaire (Chervin et al, 2000). •