• Ingen resultater fundet

Model-based Software Engineering

N/A
N/A
Info
Hent
Protected

Academic year: 2022

Del "Model-based Software Engineering"

Copied!
43
0
0

Indlæser.... (se fuldtekst nu)

Hele teksten

(1)

Model-based Software Engineering

(02341, spring 2016)

Ekkart Kindler

(2)

I. Introduction

(3)

Ekkart Kindler

Programming vs. SE

Program

Programmer Programming

Software

Software Engineer Software Engineering

(4)

Ekkart Kindler

Modelling

(5)

Ekkart Kindler

(6)

Ekkart Kindler

Place Transition

1 source 1 target

Arc

* PetriNet

Token

* Node

Object

Analysis

Design

Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName

Bundle-SymbolicName: APetriNetEditorIn15Minutes.diagr Bundle-Version: 1.0.0.qualifier

Bundle-ClassPath: .

Bundle-Activator: PetriNets.diagram.part.PetriNetDiagr Bundle-Vendor: %providerName

Bundle-Localization: plugin Export-Package: PetriNets.diagram.edit.parts,

PetriNets.diagram.part, PetriNets.diagram.providers Require-Bundle: org.eclipse.core.runtime,

org.eclipse.core.resources, org.eclipse.core.expressions, org.eclipse.jface, org.eclipse.ui.ide, org.eclipse.ui.views, org.eclipse.ui.navigator, org.eclipse.ui.navigator.resources, org.eclipse.emf.ecore, org.eclipse.emf.ecore.xmi, org.eclipse.emf.edit.ui, org.eclipse.gmf.runtime.emf.core, org.eclipse.gmf.runtime.emf.commands.core, org.eclipse.gmf.runtime.emf.ui.properties, org.eclipse.gmf.runtime.diagram.ui, org.eclipse.gmf.runtime.diagram.ui.properties, org.eclipse.gmf.runtime.diagram.ui.providers, org.eclipse.gmf.runtime.diagram.ui.providers.ide, org.eclipse.gmf.runtime.diagram.ui.render, org.eclipse.gmf.runtime.diagram.ui.resources.ed org.eclipse.gmf.runtime.diagram.ui.resources.e APetriNetEditorIn15Minutes;visibility:=reexpor

package PetriNets.impl;

public class PetriNetImpl extends EObjectImpl implements PetriNet { protected EList<PetriNets.Object> object;

protected PetriNetImpl() { super();

}

protected EClass eStaticClass() { return PetriNetsPackage.Literals.PETRI_NET;

}

public EList<PetriNets.Object> getObject() { if (object == null) {

object = new EObjectContainmentEList<PetriNets.Object>(Petri }

return object;

}

public NotificationChain eInverseRemove(InternalEObject otherEnd, int switch (featureID) {

case PetriNetsPackage.PETRI_NET__OBJECT:

return ((InternalEList<?>)getObject()).basicRemove(otherEn }

return super.eInverseRemove(otherEnd, featureID, msgs);

}

public Object eGet(int featureID, boolean resolve, boolean coreType) { switch (featureID) {

case PetriNetsPackage.PETRI_NET__OBJECT:

return getObject();

}

return super.eGet(featureID, resolve, coreType);

Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName

Bundle-SymbolicName: APetriNetEditorIn15Minutes.diagr Bundle-Version: 1.0.0.qualifier

Bundle-ClassPath: .

Bundle-Activator: PetriNets.diagram.part.PetriNetDiagr Bundle-Vendor: %providerName

Bundle-Localization: plugin Export-Package: PetriNets.diagram.edit.parts,

PetriNets.diagram.part, PetriNets.diagram.providers Require-Bundle: org.eclipse.core.runtime,

org.eclipse.core.resources, org.eclipse.core.expressions, org.eclipse.jface, org.eclipse.ui.ide, org.eclipse.ui.views, org.eclipse.ui.navigator, org.eclipse.ui.navigator.resources, org.eclipse.emf.ecore, org.eclipse.emf.ecore.xmi, org.eclipse.emf.edit.ui, org.eclipse.gmf.runtime.emf.core, org.eclipse.gmf.runtime.emf.commands.core, org.eclipse.gmf.runtime.emf.ui.properties, org.eclipse.gmf.runtime.diagram.ui, org.eclipse.gmf.runtime.diagram.ui.properties, org.eclipse.gmf.runtime.diagram.ui.providers, org.eclipse.gmf.runtime.diagram.ui.providers.ide, org.eclipse.gmf.runtime.diagram.ui.render, org.eclipse.gmf.runtime.diagram.ui.resources.ed org.eclipse.gmf.runtime.diagram.ui.resources.e APetriNetEditorIn15Minutes;visibility:=reexpor

package PetriNets.impl;

public class PetriNetImpl extends EObjectImpl implements PetriNet { protected EList<PetriNets.Object> object;

protected PetriNetImpl() { super();

}

protected EClass eStaticClass() { return PetriNetsPackage.Literals.PETRI_NET;

}

public EList<PetriNets.Object> getObject() { if (object == null) {

object = new EObjectContainmentEList<PetriNets.Object>(Petri }

return object;

}

public NotificationChain eInverseRemove(InternalEObject otherEnd, int switch (featureID) {

case PetriNetsPackage.PETRI_NET__OBJECT:

return ((InternalEList<?>)getObject()).basicRemove(otherEn }

return super.eInverseRemove(otherEnd, featureID, msgs);

}

public Object eGet(int featureID, boolean resolve, boolean coreType) { switch (featureID) {

case PetriNetsPackage.PETRI_NET__OBJECT:

return getObject();

}

return super.eGet(featureID, resolve, coreType);

(7)

Ekkart Kindler

Example of a Petri net

semaphor request1

critical1

idle1

request2

critical2

idle2

(8)

Ekkart Kindler

Stages

 Examples

 Taxonomy (done on blackboard)

 Glossary

 Model (developed on blackboard)

(9)

Ekkart Kindler

1 target

Model for Petri nets

Meta model for Petri nets

Models (Meta Models)

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

(10)

Ekkart Kindler

1 target

Don’t think models as Java

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

(11)

Ekkart Kindler

Syntax

(abstract and concrete)

:Place

:Transition :Arc

:Transition

:Place :Arc

:Arc

source

target source

target target

source

:Arc

source target

:Petrinet

:Token

graphical / concrete syntax

abstract syntax (as an UML object diagram)

(12)

Ekkart Kindler

Benefits of Modelling

 Better understanding

 Mapping of instances to XML syntax (XMI)

 Automatic code generation

API for creating, deleting and modifying model

Methods for loading and saving models (in XMI)

Standard mechanisms for keeping track of changes (observers)

(13)

Ekkart Kindler

GMF

:Place

:Transition :Arc :Transition

:Place :Arc

:Arc

source

target source

target target source

:Arc source

target

:Petrinet

:Token

Place Transition

1 source 1 target

Arc

* PetriNet

Token

* Node

Object Place

Transition

Arc Token

generate an editor

(14)

Ekkart Kindler

Benefits of Modelling

(cntd.)

 Better Understanding

 Mapping of instances to XML syntax (XMI)

 Automatic Code Generation

API for creating, deleting and modifying model

Methods for loading and saving models (in XMI)

Standard mechanisms for keeping track of changes (observers)

Editors and GUIs

(15)

Ekkart Kindler

”Buzzwords”

 Model Driven Architecture (MDA)

OMGTM software development approach for

separating business logic from platform specific details

using models

automatic generators (for code and other models)

 Model-based Software Engineering (MBSE)

General term for making “better” use of models for easing the software development

Ultimately: Getting rid of programming resp. technical artefacts.

(16)

Ekkart Kindler

Theses

 We will always have programming and programmers!

 We should always teach programming!

 But, software engineers should be trained in their engineering and modelling skills!

 And this is where they should be at their best!

 Most of the rest can be automated!

(17)

Ekkart Kindler

3. Modelling with a Purpose

Anologies:

 Models as floor plans (see earlier slides)

Architects and construction engineers use quite different kind of plans – driven by the puprose

They even use models (miniatures)

 Models as maps

Understand the world ( domain)

Find your way round in the software

Place Transition

1 source 1 target

Arc

*

PetriNet

Token

* Node

Object

(18)

Ekkart Kindler

Maps

(19)

Ekkart Kindler

Software vs Programming

 For programs (small software), models are often not needed, and making them might be a waste of time.

 For software, they are essential for building

something which works out and the different pieces fit to each other

(20)

Tutorial 1: Q & A / Wrap up (BBD)

(21)

II. Modelling with a Purpose

(22)

Ekkart Kindler

1. Models to which end

 Blackboard Discussion (BBD):

Purpose Kind of model

(23)

Ekkart Kindler

2. Domain models

Petri net example revisited (see next two slides)

Discussion:

 Should in/out (opposites of target and source) be in domain model?

 What makes it a domain model?

 What is the difference to a data model or data base schema?

23 MBSE (02341 f16), L02

(24)

Ekkart Kindler

1 target

Petri net: 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

(25)

Ekkart Kindler

Ecore model

(26)

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?

(27)

Ekkart Kindler

Petrinet.java

/** @model */

public interface Petrinet {

/** @model opposite="petrinet" containment="true" */

List<Node> getNodes();

/** @model opposite="petrinet" containment="true" */

List<Arc> getArcs();

/** @model */

String getName();

}

(28)

Ekkart Kindler

Arc.java

/** @model */

public interface Arc {

/** @model opposite="out" required="true" */

Node getSource();

/** @model opposite="in" required="true" */

Node getTarget();

/** @model opposite="arcs" transient="false" */

Petrinet getPetrinet();

}

(29)

Ekkart Kindler

Node.java

/** @model abstract="true" */

public interface Node {

/** @model opposite="nodes" transient="false" */

Petrinet getPetrinet();

/** @model opposite="target" */

List<Arc> getIn();

/** @model opposite="source" */

List<Arc> getOut();

/** @model */

String getName();

(30)

Ekkart Kindler

Transition.java

/**

* @model */

public interface Transition extends Node { }

(31)

Ekkart Kindler

Place.java

/**

* @model */

public interface Place extends Node {

/**

* @model opposite="place" containment="true“

*/

List<Token> getTokens();

}

(32)

Ekkart Kindler

Token.java

/**

* @model */

public interface Token {

/**

* @model opposite="tokens" transient="false"

*/

Place getPlace();

}

(33)

Ekkart Kindler

/** @model */

public interface Petrinet {

/** @model opposite="petrinet" containment="true“ */

List<Node> getNodes();

/** @model opposite="petrinet" containment="true“ */

List<Arc> getArcs();

/** @model */

String getName();

}

(34)

Ekkart Kindler

3. Software Models

Petri net example (cntd.): Models for

 (small part of) the generated code

 framework the generated code uses

(35)

Ekkart Kindler

3.1. Eclipse: JFace

 “JFace is a UI toolkit with classes for handling many common UI programming tasks.”

[https://wiki.eclipse.org/JFace]

 Viewers are a core part of editors (there are different kinds of viewers), which are generic.

 Here, we discuss the TreeViewer, which is the basis for the automatically generated tree editor for Petri nets.

(36)

Ekkart Kindler

TreeViewer

input

TreeViewer Object

1

Assuming that the input object (model) is a Petri net

(37)

Ekkart Kindler

TreeViewer

input

TreeViewer Object

1

Root object of the tree which is to be shown in the TreeViewer

Shows the input as a

tree (with all the features of a tree view like

opening and closing sub-trees, etc)

(38)

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 shloud be shown?

:Place

:Arc :Transition

:Arc

:Arc

source

target source

target target source

:Petrinet

: input

(39)

Ekkart Kindler

TreeViewer

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.

(40)

Ekkart Kindler

TreeViewer

input

TreeViewer Object

1

ITreeContentProvider ILabelProvider

contentProvider labelProvider

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

getChildren(Object) : List

Will come from the generated code

(ItemProviders for each kind of object in the

model): edit code

In the tutorial, you will

(41)

Ekkart Kindler

Similarly for Properties

:Place

:Transition :Arc :Transition

:Place :Arc

:Arc

source

target source

target target source

:Arc source

target

:Petrinet

:Token

: input

IPropertySourceProvider (not discussed here)

(42)

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

Idea is discussed on blackboard (BBD)

(43)

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.

Idea is discussed on

blackboard (BBD); more details next time

Referencer

RELATEREDE DOKUMENTER

S22 AB birth place Expanders - Apply equivalent subjects Search modes - Boolean/Phrase. Interface - EBSCOhost Research Databases Search Screen -

resources and concrete agents are problematic (business trip, vacations, sick leave, etc.)..

Travel Agency functional requirements: Detailed use case diagram plan trip..

Due to the difficulty involved in the design and development of complex software systems, wide ranges of software engineering paradigms have been developed, such as

Within many application domains, among them the analysis of programs involving arith- metic operations and the analysis of hybrid discrete-continuous systems, one faces the prob- lem

 For XOR-joins and -splits allow the user to select from which place a token should be consumed and to which place the token should be produced..  For OR-splits allow the user

Process models are the distilled experience of project plans of successful software projects. they are idealized and abstract from (many) details this is their strength (and

 OCL is dedicated to formulate additional constraints on top of UML models independently from a specific platform and programming language..  There are different technical ways