model-based software engineering (02341)pattern: strategy (gof) name and classification strategy,...

43
Model-based Software Engineering (02341, spring 2016) Ekkart Kindler

Upload: others

Post on 12-May-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Model-based Software Engineering

(02341, spring 2016)

Ekkart Kindler

Page 2: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

II. Modelling with a Purpose

Page 3: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler 1. Models to which end

Understanding the world (conceptual models,

domain models)

Understanding what the software is supposed to do

(requirements)

Understanding and finding your way round in

existing software

Outline the idea of how to realize the software

(architecture)

Overview of componenents and their interplay

Detailed design and realization of the software

3 MBSE (02341 f16), L03

Page 4: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler Models to which end (cntd.)

Generate parts of the software automatically

Define data representations (XML, database

schemas, ...)

Define interfaces between different components of

the software

...

4 MBSE (02341 f16), L03

Page 5: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler

5 MBSE (02341 f16), L03

1 target

2. Domain model

Petri net model

Place Transition

1 source

Arc

*

PetriNet context Arc inv: ( self.source.oclIsKindOf(Place) and self.target.oclIsKindOf(Transition) ) or ( self.source.oclIsKindOf(Transition) and self.target.oclIsKindOf(Place) )

Token *

Node

Object

Page 6: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler Ecore model

6 MBSE (02341 f16), L03

Page 7: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler Representations of model

Same model can have different representations:

Graphical / tree (as of Tutorial 1)

Java

Ecore

XML Schema (XSD)

Different representation might serve different purposes

and have a different focus!

What would the focus for XSDs, Java and Ecore be?

7 MBSE (02341 f16), L03

Page 8: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler 3. Software Models

8 MBSE (02341 f16), L03

Page 9: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler How???

How could the TreeViewer, which does not know anything

about Petri nets (and the classes representing the concepts

of Petri nets), know how this tree should be shown?

9 MBSE (02341 f16), L03

:Place

:Transition

:Arc

:Transition

:Place

:Arc

:Arc

source

target source

target

target source

:Arc source target

:Petrinet

:Token

: input

input TreeViewer Object

1

Page 10: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler TreeViewer

MBSE (02341 f16), L03

input

TreeViewer Object

1

ITreeContentProvider

ILabelProvider

contentProvider

1

labelProvider

1 getText(Object) : String getImage(Object): Image

getChildren(Object) : List getImage(Object): Image

Provides the label and

the icon for each object

For each object, provides

the current list of

children.

10

Page 11: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler 3.2 EMF: Use of TreeViewer

In EMF, this is even more complicated: using a

generic ContentProvider, which creates the

respective ItemProviders and delegates to them

11 MBSE (02341 f16), L03

Page 12: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler 3.3 Update Viewer on Changes

In order to make sure that the viewer properly

updates, whenever changes occur, it registers itself

as listener to the respective elements (actually to

their ItemProviders.

12 MBSE (02341 f16), L03

:Place

:Transition

:Arc

:Transition

:Place

:Arc

:Arc

source

target source

target

target source

:Arc source target

:Petrinet

:Token

Page 13: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler Discussion

Domain models

vs

Software models

13 MBSE (02341 f16), L03

Page 14: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

III. Design Patterns (How / Software Models)

Page 15: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler

15 MBSE (02341 f16), L03

1. Introduction

Design patterns (in software

engineering) are the distilled experience

of software engineering experts on how

to solve standard problems in software

design.

Page 16: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler

16 MBSE (02341 f16), L03

Design Patterns in SE:

Gamma, Helm, Johnson, Vlissides:

Design Patterns. Addison-Wesley 1995.

Eric Freeman, Elisabeth Freeman:

Head First Design Patterns. O’Reilly

2004 [FF]

Page 17: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler

17 MBSE (02341 f16), L03

Disclaimer

Design patterns are a topic of their own,

worth being taught as a separate course

(e.g. seminar/special course)

This lecture gives just a glimpse of the

general idea and some patterns, which

are important to understand and use

EMF

Page 18: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

III. Design Patterns (How / Software Models)

2. Examples

Page 19: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler Example: Observer (GoF)

Name and classification

Observer, object, behavioural

Intent

”Define a one-to-many dependency between

objects so that an object changes all its dependents

are are notified and updated automatically” [GoF].

Also know as

Dependents, Publish-Subscribe, Listener

dd MBSE (02341 f16), L03

Page 20: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler Example: Observer

Motivation

[...] maintain consistency between related objects

without introducing tight coupling (which increases

reusability) [...]

Typical Example

... update views when the underlying model

changes ...

dd MBSE (02341 f16), L03

Page 21: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler

21 MBSE (02341 f16), L03

Example: Observer

Structure

1

Subject attach(Observer) detach(Observer)

notify()

Observer

update()

ConcrObs

update()

*

observers

ConcrSub state: State

getState() setState(State)

subject

notify() {

forall o:observers

o.update()

}

Page 22: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler Example: Observer

Participants (see structure)

Subject

knows its observers

provides an interface for attaching and detaching Observer objects

Observer

defines the updateing interface for being notified

ConreteSubject

stores the state (of interest)

sends notifications

ConreteObserver

Implements the Observer‘s updating interface to keep its state

consistent

22 MBSE (02341 f16), L03

Page 23: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler Example: Observer

Collaboration

23 MBSE (02341 f16), L03

Page 24: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler

24 MBSE (02341 f16), L03

Scheme (GoF)

Name

Classification

Intent

Also known as (aka)

Motivation

Application

Structure

Participants

Collaboration

Consequences

Implementation

Sample code

Known uses

Related patterns

Page 25: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler

25 MBSE (02341 f16), L03

Example: Simulation Algorithm

1

SimulationState

Simulator

Interface enabled(SimulationState, Transition)

fire(SimulationState, Transition)

1

<<interface>>

algorithm

Algorithm enabled(SimulationState, Transition)

fire(SimulationState, Transition)

Page 26: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler

26 MBSE (02341 f16), L03

Pattern: Strategy (GoF)

Name and classification

Strategy, object-based, behavioural

Intent

Define a family of algorithms, encapsulate each one,

and make them interchangeable. Strategy lets the

algorithm vary independently from clients that use it

[GoF]

Motivation

Avoid hard-wiring of algorithms for making it easier

to change the algorithm …

Page 27: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler

27 MBSE (02341 f16), L03

Pattern: Strategy (cntd.)

Structure

Context contextInterface()

Strategy algInterface()

AlgorithmB

algInterface()

1

strategy

AlgorithmA

algInterface()

AlgorithmC

algInterface()

Page 28: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler

28 MBSE (02341 f16), L03

Pattern: Strategy (cntd)

Page 29: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler

29 MBSE (02341 f16), L03

Questions

Is the “simulation algorithm” a strategy?

Page 30: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler

30 MBSE (02341 f16), L03

Pattern: Abstract Factory

Name and classification

Abstract factory, object, creational

Intent

Provide an interface for creating families of related

or dependent objects without specifying their

concrete classes [GoF]

Motivation

Use of different implementations in different contexts

with easy portability …

Page 31: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler

31 MBSE (02341 f16), L03

Pattern: Abstract Factory (cntd)

AbsFactory createProdA() createProdB()

Factory1 createProdA()

createProdB()

Factory2 createProdA()

createProdB()

Client

AbsProdA

ProdA1 ProdA2

AbsProdB

ProdB1 ProdB2

Page 32: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler

32 MBSE (02341 f16), L03

Pattern: Singleton (GoF)

Name and classification

Singleton, object-based, creational

Intent

Ensure that a class has only one instance, and

provide a global point of access to it [GoF]

Motivation

Page 33: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler Other relevant patterns

Factory Method

Command

(see Tutorial 2)

Adapter

33 MBSE (02341 f16), L03

Page 34: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler

34 MBSE (02341 f16), L03

3. Summary

GoF present 23 patterns

There are many more (and more complex combinations of patterns, e.g. MVC --)

“Pattern terminology” can be used to communicate design!

Patterns should not be used to schematically

Generated code, typically, makes use of many patterns. Automatic code generation “saves us making some design decisions” (observer, singleton, factory, and adapters are part of the EMF-generated code)

Page 35: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler

35 MBSE (02341 f16), L03

Scheme (GoF)

Name

Classification

Intent

Also known as (aka)

Motivation

Application

Structure

Participants

Collaboration

Consequences

Implementation

Sample code

Known uses

Related patterns

Page 36: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler

36 MBSE (02341 f16), L03

4. Model View Controller (MVC)

The domain models are an (the) essential part of

the software

In addition to that we need

Information about the presentation of the model to

the user

The coordination with the user

Page 37: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler

37 MBSE (02341 f16), L03

Modelle View Controller (MVC)

Model

Place Transition

1 source

1 target

Arc

*

PetriNet

Token *

Node

Object

View

Controller

:Arc

Page 38: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler

38 MBSE (02341 f16), L03

MVC

Model

Domain model and functions

View

Representation of model and user interaction

Controller Makes changes and calls functions of the model

queries

informs on changes

makes changes

selects

informs on user interactions

Page 39: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler

39 MBSE (02341 f16), L03

MVC

Model

Domain model and functions

View

Representation of model and user interaction

Controller Makes changes and calls functions of the model

queries

informs on changes

makes changes

selects

informs on user interactions

Page 40: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler

40 MBSE (02341 f16), L03

MVC

MVC is a principle (pattern / architecture)

according to which software should be structured

Eclipse and GEF (as well as GMF) are based on

this principle and guide (force) you in properly

using it

Page 41: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Ekkart Kindler

41 MBSE (02341 f16), L03

EMF, GMF and MVC

Model

Place Transition

1 source

1 target

Arc

*

PetriNet

Token *

Node

Object

View

Controller

:Arc

Page 42: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Tutorial 2: Q & A

Page 43: Model-based Software Engineering (02341)Pattern: Strategy (GoF) Name and classification Strategy, object-based, behavioural Intent Define a family of algorithms, encapsulate each one,

Tutorial 3: Discussion Assignment 3