Lecture 12: Structural Software Modelling 2015-06-25 Prof. Dr. - - PowerPoint PPT Presentation

lecture 12 structural software modelling
SMART_READER_LITE
LIVE PREVIEW

Lecture 12: Structural Software Modelling 2015-06-25 Prof. Dr. - - PowerPoint PPT Presentation

Softwaretechnik / Software-Engineering Lecture 12: Structural Software Modelling 2015-06-25 Prof. Dr. Andreas Podelski, Dr. Bernd Westphal 12 2015-06-25 main Albert-Ludwigs-Universit at Freiburg, Germany Contents of the Block


slide-1
SLIDE 1

– 12 – 2015-06-25 – main –

Softwaretechnik / Software-Engineering

Lecture 12: Structural Software Modelling

2015-06-25

  • Prof. Dr. Andreas Podelski, Dr. Bernd Westphal

Albert-Ludwigs-Universit¨ at Freiburg, Germany

slide-2
SLIDE 2

Contents of the Block “Design”

– 12 – 2015-06-25 – Scontents –

2/38 (i) Introduction and Vocabulary (ii) Principles of Design

a) modularity b) separation of concerns c) information hiding and data encapsulation d) abstract data types, object orientation

(iii) Software Modelling

a) views and viewpoints, the 4+1 view b) model-driven/based software engineering c) Unified Modelling Language (UML) d) modelling structure

  • 1. (simplified) class diagrams
  • 2. (simplified) object diagrams
  • 3. (simplified) object constraint logic (OCL)

e) modelling behaviour

  • 1. communicating finite automata
  • 2. Uppaal query language
  • 3. basic state-machines
  • 4. an outlook on hierarchical state-machines

(iv) Design Patterns

L 1: 20.4., Mo

Introduction

T 1: 23.4., Do L 2: 27.4., Mo L 3: 30.4., Do L 4: 4.5., Mo

Development Process, Metrics

T 2: 7.5., Do L 5: 11.5., Mo

  • 14.5., Do

L 6: 18.5., Mo L 7: 21.5., Do

  • 25.5., Mo
  • 28.5., Do

Requirements Engineering

T 3: 1.6., Mo

  • 4.6., Do

L 8: 8.6., Mo L 9: 11.6., Do L 10: 15.6., Mo T 4: 18.6., Do L 11: 22.6., Mo L 12: 25.6., Do L 13: 29.6., Mo L 14: 2.7., Do

Architecture & Design, Software Modelling

T 5: 6.7., Mo L 15: 9.7., Do

Quality Assurance

L 16: 13.7., Mo

Invited Talks

L 17: 16.7., Do T 6: 20.7., Mo

Wrap-Up

L 18: 23.7., Do

slide-3
SLIDE 3

Contents & Goals

– 12 – 2015-06-25 – Sprelim –

4/38

Last Lecture:

  • Design basics and vocabulary:

modularity, separation of concerns, information hiding, data encapsulation, ADT, . . . This Lecture:

  • Educational Objectives: Capabilities for following tasks/questions.
  • What is the signature defined by this class diagram?
  • Give a system state corresponding to this class diagram.
  • Which system state is denoted by this object diagram?
  • To which value does this Proto-OCL formula evaluate on the given system state?
  • Give system states such that the given formula evaluates to true/false/⊥.
  • Why is Proto-OCL a 3-valued logic?
  • Content:
  • Class Diagrams
  • Object Diagrams
  • Proto-OCL
slide-4
SLIDE 4

Class Diagrams

– 12 – 2015-06-25 – main –

5/38

slide-5
SLIDE 5

Object System Signature

– 12 – 2015-06-25 – Sumlsig –

6/38

  • Definition. An (Object System) Signature is a 6-tuple

S = (T, C, V, atr , F, mth) where

  • T is a set of (basic) types,
  • C is a finite set of classes,
  • V is a finite set of typed attributes, i.e., each v ∈ V has type
  • V is a finite set of typed attributes v : T, i.e., each v ∈ V has type T,
  • atr : C → 2V maps each class to its set of attributes.
  • F is a finite set of typed behavioural features f : T1, . . . , Tn → T,
  • mth : C → 2F maps each class to its set of behavioural features.
  • A type can be a basic type τ ∈ T , or C0,1, or C∗, where C ∈ C .

Note: Inspired by OCL 2.0 standard OMG (2006), Annex A.

slide-6
SLIDE 6

Object System Signature Example

– 12 – 2015-06-25 – Sumlsig –

7/38

S0 = ({Int}, {C, D}, {x : Int, p : C0,1, n : C∗}, {C → {p, n}, D → {p, x}}, {f : Int → Bool, get x : Int}, {C → ∅, D → {f, get x}})

slide-7
SLIDE 7

Object System Signature Example

– 12 – 2015-06-25 – Sumlsig –

7/38

S0 = ({Int}, {C, D}, {x : Int, p : C0,1, n : C∗}, {C → {p, n}, D → {p, x}}, {f : Int → Bool, get x : Int}, {C → ∅, D → {f, get x}})

C D

x : Int f(Int) : Bool get x() : Int

  • p

0..1 ×

  • p

0..1 ×

  • n

0..∗ ×

slide-8
SLIDE 8

And The Other Way Round

– 12 – 2015-06-25 – Sumlsig –

8/38 C D

x : Int f(Int) : Bool get x() : Int

  • p

0..1 ×

  • p

0..1 ×

  • n

0..∗ ×

slide-9
SLIDE 9

Shorthand Notation

– 12 – 2015-06-25 – Sumlsig –

9/38 C D

x : Int f(Int) : Bool get x() : Int

  • p

0..1 ×

  • p

0..1 ×

  • n

0..∗ ×

C D

x : Int f(Int) : Bool get x() : Int p 0..1 p 0..1 n 0..∗

In particular:

  • visibility for attributes and association ends (+, −, #, ∼): later
  • initial values, properties: not here, cf. UML lecture
  • associations in general (names, reading direction, ternary; visibility, navigability, etc. of

association ends): not here, cf. UML lecture

  • inheritance: later (maybe)
  • behavioural features: not here, cf. UML lecture
slide-10
SLIDE 10

Object System Structure

– 12 – 2015-06-25 – Sumlstruc –

10/38

  • Definition. A Object System Structure of signature

S = (T, C, V, atr , F, mth) is a domain function D which assigns to each type a domain, i.e.

  • τ ∈ T is mapped to D(T),
  • C ∈ C is mapped to an infinite set D(C) of (object) identities.
  • object identities of different classes are disjoint, i.e.

∀ C, D ∈ C : C = D → D(C) ∩ D(D) = ∅,

  • on object identities, (only) comparision for equality “=” is defined.
  • C∗ and C0,1 for C ∈ C are mapped to 2D(C).

We use D(C ) to denote

C∈C D(C); analogously D(C∗).

Note: We identify objects and object identities, because both uniquely determine each other (cf. OCL 2.0 standard).

slide-11
SLIDE 11

Basic Object System Structure Example

– 12 – 2015-06-25 – Sumlstruc –

11/38

Wanted: a structure for signature S0 = ({Int}, {C, D}, {x : Int, p : C0,1, n : C∗}, {C → {p, n}, D → {p, x}}, {f : Int → Bool, get x : Int}, {C → ∅, D → {f, get x}})

A structure D maps

  • τ ∈ T to some D(τ), C ∈ C to some identities D(C) (infinite, pairwise disjoint),
  • C∗ and C0,1 for C ∈ C to D(C0,1) = D(C∗) = 2D(C).

D(Int) = Z D(C) = N+ × {C} ∼ = {1C, 2C, 3C, ...} D(D) = N+ × {D} ∼ = {1D, 2D, 3D, ...} D(C0,1) = D(C∗) = 2D(C) D(D0,1) = D(D∗) = 2D(D)

slide-12
SLIDE 12

System State

– 12 – 2015-06-25 – Sumlstruc –

12/38

Definition. Let D be a structure of S = (T, C, V, atr , F, mth). A system state of S wrt. D is a type-consistent mapping σ : D(C ) (V (D(T ) ∪ D(C∗))). That is, for each u ∈ D(C), C ∈ C , if u ∈ dom(σ)

  • dom(σ(u)) = atr(C)
  • σ(u)(v) ∈ D(τ) if v : τ, τ ∈ T
  • σ(u)(v) ∈ D(D∗) if v : D0,1 or v : D∗ with D ∈ C

We call u ∈ D(C ) alive in σ if and only if u ∈ dom(σ). We use ΣD

S to denote the set of all system states of S wrt. D.

slide-13
SLIDE 13

System State Example

– 12 – 2015-06-25 – Sumlstruc –

13/38

S0 = ({Int}, {C, D}, {x : Int, p : C0,1, n : C∗}, {C → {p, n}, D → {p, x}}, {f : Int → Bool, get x : Int}, {C → ∅, D → {f, get x}}) D(Int) = Z, D(C) = {1C, 2C, 3C, ...}, D(D) = {1D, 2D, 3D, ...}

A system state is a partial function σ : D(C ) (V (D(T ) ∪ D(C∗))) such that

  • dom(σ(u)) = atr(C),
  • σ(u)(v) ∈ D(τ) if v : τ, τ ∈ T ,
  • σ(u)(v) ∈ D(C∗) if v : D∗ or v : D0,1 with D ∈ C .
slide-14
SLIDE 14

System State Example

– 12 – 2015-06-25 – Sumlstruc –

13/38

S0 = ({Int}, {C, D}, {x : Int, p : C0,1, n : C∗}, {C → {p, n}, D → {p, x}}, {f : Int → Bool, get x : Int}, {C → ∅, D → {f, get x}}) D(Int) = Z, D(C) = {1C, 2C, 3C, ...}, D(D) = {1D, 2D, 3D, ...}

A system state is a partial function σ : D(C ) (V (D(T ) ∪ D(C∗))) such that

  • dom(σ(u)) = atr(C),
  • σ(u)(v) ∈ D(τ) if v : τ, τ ∈ T ,
  • σ(u)(v) ∈ D(C∗) if v : D∗ or v : D0,1 with D ∈ C .
  • Concrete, explicit system state:

σ1 = {1C → {p → ∅, n → {5C}}, 5C → {p → ∅, n → ∅}, 1D → {p → {5C}, x → 23}}..

  • Alternative: symbolic system state

σ2 = {c1 → {p → ∅, n → {c2}}, c2 → {p → ∅, n → ∅}, d → {p → {c2}, x → 23}}. assuming c1, c2 ∈ D(C), d ∈ D(D), c1 = c2. Can be seen as denoting a set of system states including σ1 — how many?

slide-15
SLIDE 15

Class Diagrams at Work

– 12 – 2015-06-25 – main –

14/38

slide-16
SLIDE 16

Visualisation of Implementation

– 12 – 2015-06-25 – Scdatwork –

15/38

  • The class diagram syntax can be used to visualise code:

provide rules which map (parts of) the code to class diagram elements.

1

package pac ;

2 3

import pac .D;

4 5

p u bli c c l a s s C {

6 7

p u bli c D n ;

8 9

p u bli c void p r i n t n x () {

10

System . out . p r i n t f (

11

”%i \n” , n . get x () ) ; };

12 13

p u bli c C() {};

14

}

1

package pac ;

2 3

import pac .C;

4 5

p u bli c c l a s s D {

6 7

p r i va te i nt x ;

8 9

p u bli c i nt get x ()

10

{ return x ; };

11 12

p u bli c D() {};

13

}

slide-17
SLIDE 17

Visualisation of Implementation

– 12 – 2015-06-25 – Scdatwork –

15/38

  • The class diagram syntax can be used to visualise code:

provide rules which map (parts of) the code to class diagram elements.

pac

+ C

+ print nx(); + C();

+ D

− x : int + get x() : int; + D(); + n 0..1

1

package pac ;

2 3

import pac .D;

4 5

p u bli c c l a s s C {

6 7

p u bli c D n ;

8 9

p u bli c void p r i n t n x () {

10

System . out . p r i n t f (

11

”%i \n” , n . get x () ) ; };

12 13

p u bli c C() {};

14

}

1

package pac ;

2 3

import pac .C;

4 5

p u bli c c l a s s D {

6 7

p r i va te i nt x ;

8 9

p u bli c i nt get x ()

10

{ return x ; };

11 12

p u bli c D() {};

13

}

slide-18
SLIDE 18

Visualisation of Implementation: Example

– 12 – 2015-06-25 – Scdatwork –

16/38

  • open favourite IDE,
  • open favourite project,
  • press “generate class diagram”
  • wait. . . wait. . . wait. . .
cd UMLClassDiagram1 Byteco…torCall «C# class» Attributes + containingType : IT…
  • isDeferringCtor : Boo…
Operations + IsDeferringCtor(met… + TraverseChildren(m…
  • FindCtorCall(containi…
Byteco…antics «C# class» Attributes Operations + CLRExpressionSema… Byteco…nalyzer «C# class» Attributes
  • currentCatchClauseE…
  • exceptionsThrown :...
  • parent : ExceptionAn…
Operations + ExplicitlyThrownEx... + TraverseChildren(m… + TraverseChildren(tr… + TraverseChildren(ca… + TraverseChildren(re… + TraverseChildren(th…
  • MethodExceptionAna…
Byteco…mplifier «C# class» Attributes
  • sink : Sink
Operations + Rewrite(arrayIndex… + Rewrite(boundExpr… + Rewrite(targetExpre… + Simplify(sink : Sink, …
  • ExpressionSimplifier(…
Byteco…averser «C# delegate» Attributes Operations + Invoke(source : IEx… Byteco…mparer «C# class» Attributes Operations + Equals(x : IFieldRef… + FieldComparer() + GetHashCode(obj : … Byteco…mparer «C# class» Attributes Operations + Equals(x : IMethod… + GetHashCode(obj : … + MethodComparer() Byteco…ypeInfo «C# class» Attributes + Constructor : Functi… + ConstructorId : Con…
  • constructor : Function
  • constructorId : Cons…
  • typeParameterToSel...
Operations + Selector(typeParam… + TypeInfo(sink : Sink… Byteco…Emitter «C# class» Attributes
  • parent : StatementT…
Operations + SourceContextEmitt… + Visit(statement : ISt…
  • EmitSourceContext(s…
Byteco…antics «C# class» Attributes + subTypes : Diction...
  • parent : WholeProgr…
Operations + GetExplicitlyImple... + TraverseChildren(m… + WholeProgramExpr…
  • FindOverrides(type ...
Byteco…antics «C# class» Attributes
  • codeUnderAnalysis :...
  • parent : WholeProgr…
  • sink : Sink
Operations + TranslateAssemblie... + WholeProgramMet... Byteco…nslator «C# class» Attributes + Factory : TraverserF…
  • contractProviders :
...
  • pdbReaders :
IDicti...
  • sink : Sink
  • traverser : BCTMeta…
Operations + BaseTranslator(fact... + getModifiedIdentifi... + getPostconditionTr... + getPreconditionTra... + getPriority() : Integer + initialize() + isOneShot() : Boolean + TranslateAssemblie... Byteco…or::BCT «C# class» Attributes + Host : IMetadataHost
  • modules :
List<IMo... Operations + BCT() + Inline(bplFileName : … + TranslateAssembly(... + TranslateAssembly...
  • BuildAssignment(sin...
  • BuildIfCmd(b : Expr,
  • BuildIfCmd(b : Expr,
  • BuildReturnCmd(b :
  • BuildStmtList(cmd :
  • callPostTranslationT...
  • checkTransitivelyCal...
  • CreateDelegateAdd...
  • CreateDelegateCrea...
  • CreateDelegateRem...
  • CreateDispatchMeth...
  • createPhoneBoogieC…
  • EmitDummySourceC…
  • finalizeNavigationAn…
  • GenerateInAndOutE...
  • Main(args : String[*]…
  • NameUpToFirstPerio…
  • outputBackKeyWarni…
  • outputBoogieTracke…
Byteco…averser «C# class» Attributes + Factory : TraverserF… + PdbReader : PdbRe… + PdbReaders : IDicti...
  • entryPoint : IMethod…
  • privateTypes :
List<...
  • sawCctor : Boolean
  • sink : Sink
Operations + BCTMetadataTrave... + getModifiedIdentifi... + getPostconditionTr... + getPreconditionTra... + GetTypeDefinitionF... + TranslateAssemblie... + TraverseChildren(m… + TraverseChildren(ty… + TraverseChildren(as… + TraverseChildren(fie… + TraverseChildren(m…
  • addPhoneTopLevelD…
  • CreateDefaultStructC…
  • CreateStaticConstruc…
  • CreateStructCopyCo…
  • InitializeFieldsInCon...
  • IsStubMethod(metho…
  • trackControlVariable…
  • trackNavigationVaria…
  • trackPhoneApplicatio…
  • trackPhonePageNam…
Byteco…antics «C# class» Attributes Operations + CLRSemantics() + getTranslator(sink :... + MakeExpressionTra… Byteco…btypes «C# class» Attributes
  • subTypes :
Dictiona...
  • visitedTypes :
Hash... Operations + RecordSubtypes(su... + TraverseChildren(ty… Byteco…nalyzer «C# class» Attributes
  • exceptionsExplicitly...
  • resultsChanged : Bo…
Operations + ComputeExplicitlyT... + TraverseChildren(m…
  • ExceptionAnalyzer()
Byteco…averser «C# class» Attributes + TranslatedExpressi...
  • contractContext : Bo…
  • currentExpressionIs…
# sink : Sink # StmtTraverser : Sta… Operations + ExpressionTraverser… + IsConversionOperat… + IsOperator(method… + TraverseChildren(m… + TraverseChildren(ad… + TraverseChildren(ad… + TraverseChildren(ad… + TraverseChildren(ad… + TraverseChildren(ar… + TraverseChildren(as… + TraverseChildren(bit… + TraverseChildren(bit… + TraverseChildren(bl… + TraverseChildren(bo… + TraverseChildren(ca… + TraverseChildren(ch… + TraverseChildren(co… + TraverseChildren(co… + TraverseChildren(co… + TraverseChildren(cr… + TraverseChildren(cr… + TraverseChildren(cr… + TraverseChildren(de… + TraverseChildren(di… + TraverseChildren(du… + TraverseChildren(eq… + TraverseChildren(ex… + TraverseChildren(gr… + TraverseChildren(gr… + TraverseChildren(lef… + TraverseChildren(le… + TraverseChildren(le… + TraverseChildren(lo… + TraverseChildren(m… + TraverseChildren(m… + TraverseChildren(no… + TraverseChildren(ol… + TraverseChildren(on… + TraverseChildren(po… + TraverseChildren(re… + TraverseChildren(ri… + TraverseChildren(su… + TraverseChildren(ta… + TraverseChildren(th… + TraverseChildren(ty… + TraverseChildren(un… + TraverseChildren(ve…
  • AssertOrAssumeNon…
  • BooleanValueOfCom…
  • EmitLineDirective(m…
  • handleStructConstr...
  • IsConstantNull(iExpr…
  • LoadAddressOf(cont…
  • LoadParameter(para…
  • PossiblyCoerceRefTo…
  • ResolveUnspecialize…
  • translateAddRemov...
  • TranslateAssignment…
  • TranslateDelegateCr…
  • TranslateHavocCurre…
  • translateStructDefaul…
  • TraverseAdditionRig…
  • TraverseBitwiseAndR…
  • TraverseBitwiseOrRi…
  • TraverseDivisionRigh…
  • TraverseExclusiveOr…
  • TraverseLeftShiftRig…
  • TraverseModulusRig…
  • TraverseMultiplicatio…
  • TraverseRightShiftRi…
  • TraverseSubtraction…
  • VisitAssignment(targ…
# TranslateArgument... ~ IsAtomicInstance(e… Byteco…ralHeap «C# class» Attributes
  • HeapVariable : Varia…
  • InitialPreludeText : S…
  • Read : Function
  • sink : Sink
  • Write : Function
Operations + CreateEventVariable… + CreateFieldVariable(… + GeneralHeap() + MakeHeap(sink : Si… + ReadHeap(o : Expr, … + WriteHeap(tok : ITo… «C# class» Attributes + AllocConstBool : Fu… + AllocImplies : Functi… + AllocVariable : Varia… + ArrayContentsVaria… + ArrayLengthFunctio… + AsFunction : Function + BitwiseAnd : Function + BitwiseExclusiveOr : … + BitwiseNegation : F… + BitwiseOr : Function + Bool2Union : Function + BoolValueType : Co… + BoxFromBool : Proc… + BoxFromInt : Proce… + BoxFromReal : Proc… + BoxFromUnion : Pro… + DefaultHeapValue : … + DefaultReal : Const… + DisjointSubtree : Fu… + ExceptionVariable : … + FieldType : CtorType + FieldTypeDecl : Typ… + Int2Real : Function + Int2Union : Function + IntValueType : Con… + LeftShift : Function + NullRef : Constant + Real2Int : Function + Real2Union : Function + RealDivide : Function + RealGreaterThan : F… + RealGreaterThanOr… + RealLessThan : Fun… + RealLessThanOrEqu… + RealMinus : Function + RealModulus : Func… + RealPlus : Function + RealTimes : Function + RealType : CtorType + RealValueType : Co… + RefToDelegateMeth… + RefToDelegateRecei… + RefToDelegateType… + RefType : CtorType + RefTypeDecl : Type… + RightShift : Function + Subtype : Function + TypeConstructorFun… + TypeType : Type + TypeTypeDecl : Typ… + Unbox2Bool : Functi… + Unbox2Int : Function + Unbox2Real : Functi… + Unbox2Union : Fun… + Union2Bool : Function + Union2Int : Function + Union2Real : Function + UnionType : Type + UnionTypeDecl : Ty… # CommonText : String # DynamicTypeFuncti… # RealTypeDecl : Typ… Operations + CreateTypeFunction… + CreateTypeVariable... + DynamicType(o : Ex… + FromUnion(tok : IT… + Heap() + ToUnion(tok : IToke… «C# class» Attributes Operations + HeapFactory() Byteco…ameter «C# class» Attributes + inParameterCopy : … + outParameterCopy : … + underlyingParamete… Operations + MethodParameter(p… + ToString() : String Byteco…averser «C# class» Attributes
  • currStatement : ITry…
  • mostNestedTryState...
Operations + MostNestedTryState… + MostNestedTryState… + TraverseChildren(tr… + TraverseChildren(la… Byteco…Module «C# class» Attributes
  • sourceUnit : IUnit
  • targetUnit : IUnit
Operations + ReparentModule(ho… + RewriteChildren(roo… Byteco…Options «C# class» Attributes + assemblies : List<S... + breakIntoDebugger … + captureState : Bool… + dereference : Deref… + exemptionFile : String + getMeHere : Boolean + heapRepresentation … + instrumentBranches … + libpaths : List<Stri... + modelExceptions : I… + monotonicHeap : B… + phoneControls : Stri… + phoneFeedbackCod… + phoneNavigationCo… + stub : List<String > + wholeProgram : Bo… Operations + Options() Byteco…Prelude «C# class» Attributes Operations + Emit(wr : TokenTex… + Prelude() Byteco…mparer «C# class» Attributes
  • resolveTypes : Boole…
~ instance : RelaxedT… ~ resolvingInstance : … Operations + Equals(x : ITypeRef… + GetHashCode(r : IT…
  • RelaxedTypeEquival…
Byteco…tionFor «C# class» Attributes ~ declaration : String ~ name : String ~ required : Boolean Operations ~ ParsePrelude(initial… ~ RepresentationFor(… ~ RepresentationFor(… Byteco…r::Sink «C# class» Attributes + AllocationMethodNa… + cciLabels : Dictiona... + delegateTypeToDel... + delegateTypeToDel... + delegateTypeToDel... + delegateTypeToDel... + Heap : Heap + initiallyDeclaredPro... + LabelVariable : Loca… + LocalCounter : Inte… + LocalExcVariable : L… + LocalVarMap : Dicti... + MethodThrowsExce... + nestedTryCatchFin... + Options : Options + ReferenceTypeNam… + ReturnVariable : For… + StaticFieldFunction : … + ThisVariable : Formal + TranslatedProgram … + TranslationPlugins ... + tryCatchFinallyIden... + UniqueNumberAcro…
  • arityToNaryIntFunct...
  • arityToNaryTypeFun...
  • assemblyBeingTransl…
  • declaredEvents :
Di...
  • declaredFields :
Dic...
  • declaredMethods :
...
  • declaredProperties :...
  • declaredRealConsta...
  • declaredStringConst...
  • declaredStructCopy...
  • declaredStructDefa...
  • declaredStructEqual...
  • declaredTypeConsta...
  • declaredTypeFuncti...
  • declaredTypeParam...
  • delegateMethods :
...
  • escapingGotoEdges ...
  • exemptionList :
List...
  • globalVariables :
IDi...
  • heap : Heap
  • localCounter : Integer
  • localVarMap :
Dictio...
  • methodBeingTransla…
  • mostNestedTryState…
  • options : Options
  • projectionFunctions ...
  • thisVariable : Formal
  • translationPlugins :
...
  • typeParameterFunct...
  • uniqueNumberSeed
  • whiteList : Boolean
~ host : IContractAwa… ~ operandStack : Sta... Operations + AddDelegate(type : … + AddDelegateType(t… + AddEscapingEdge(tr… + BeginAssembly(asse… + BeginMethod(metho… + BeginMethod(contai… + CciTypeToBoogie(ty… + ConsolidatedGeneri… + CreateFreshLocal(ty… + CreateFreshLocal(t : … + DelegateAdd(type : … + DelegateCreate(typ… + DelegateRemove(ty… + EndAssembly(asse… + EscapingEdges(try... + FindOrCreateCatchL… + FindOrCreateCciLab… + FindOrCreateConsta… + FindOrCreateConsta… + FindOrCreateConsta… + FindOrCreateContin… + FindOrCreateDelega… + FindOrCreateEventV… + FindOrCreateFieldV… + FindOrCreateFinally… + FindOrCreateGlobal… + FindOrCreateLocalV… + FindOrCreateNaryIn… + FindOrCreateNaryTy… + FindOrCreateProced… + FindOrCreateProced… + FindOrCreateProced… + FindOrCreateProper… + FindOrCreateTypeP… + FindOrCreateTypeR… + FindOrCreateTypeR… + FindOrDefineType(t… + FindOrDefineType + FindParameter + GenerateDy + GetConso + getMe + Get + G + Sink * Heap 1 Sink * Opti… 1 Byteco…dsHeap «C# class» Attributes
  • InitialPreludeText : S…
  • sink : Sink
Operations + CreateEventVariable… + CreateFieldVariable(… + MakeHeap(sink : Si… + ReadHeap(o : Expr, … + SplitFieldsHeap() + WriteHeap(tok : ITo… Byteco…averser «C# class» Attributes + factory : TraverserF… + lastSourceLocation : … + PdbReader : PdbRe… + StmtBuilder : StmtLi…
  • captureState : Boolean
  • captureStateCounter
  • contractContext : Bo…
  • sink : Sink
Operations + GenerateDispatchC… + RaiseException(e : … + RaiseException() + StatementTraverser… + TranslateMethod(m... + TraverseChildren(tr… + TraverseChildren(as… + TraverseChildren(as… + TraverseChildren(bl… + TraverseChildren(br… + TraverseChildren(co… + TraverseChildren(co… + TraverseChildren(do… + TraverseChildren(ex… + TraverseChildren(fo… + TraverseChildren(fo… + TraverseChildren(go… + TraverseChildren(la… + TraverseChildren(lo… + TraverseChildren(pu… + TraverseChildren(re… + TraverseChildren(re… + TraverseChildren(s… + TraverseChildren(th… + TraverseChildren(w…
  • ExpressionFor(expre…
  • RaiseExceptionHelpe…
Byteco…ception «C# class» Attributes Operations + TranslationExceptio… + TranslationExceptio… Byteco…Helper «C# class» Attributes ~ catchClauseCounter … ~ finallyClauseCounte… ~ tmpVarCounter : Int… Operations + BuildAssignCmd(le... + BuildAssignCmd(lhs … + BuildStmtList(cmds … + BuildStmtList(cmd : … + BuildStmtList(tcmd … + ConsolidatedGeneri... + CreateUniqueMetho… + GenerateCatchClaus… + GenerateFinallyClau… + GenerateTempVarN… + IsStruct(typ : IType… + Token(objectWithLo… + TurnStringIntoValid…
  • ConsolidatedGeneri...
  • GetRidOfSurrogateC…
«C# class» Attributes + Priority : Integer Operations + getTranslator(sink :... + MakeExpressionTra… + MakeMetadataTrav... + MakeStatementTrav… + TraverserFactory() Byteco…erences «C# class» Attributes
  • internedKeys :
Dicti...
  • sourceUnitIdentity :
… ~ originalAssemblyIde… ~ targetAssembly : IA… Operations + Rewrite(assemblyRe… + Rewrite(moduleRef… + RewriteUnitReferen… Byteco…rogram «C# class» Attributes + subTypes : Diction... Operations + getTranslator(sink :... + MakeExpressionTra… + MakeMetadataTrav... + WholeProgram()
  • ca. 35 classes,
  • ca. 5,000 LOC C#
slide-19
SLIDE 19

Documentation of Implementation

– 12 – 2015-06-25 – Scdatwork –

17/38

Tron Joystick? . . . Keyboard? Control Player

colour score direction speed

Gameplay Render OpenGL? . . . aalib? AI? Segment

x0, y0 x1, y1 colour

Engine

areawidth areaheight

1..∗ notify update 0..∗ head world 1..∗

  • Note: a class diagram may be partial, i.e. show only certain aspects of a signature.
  • Note: a signature can be defined by a set of class diagrams.
slide-20
SLIDE 20

Object Diagrams

– 12 – 2015-06-25 – main –

18/38

slide-21
SLIDE 21

Object Diagram

– 12 – 2015-06-25 – Sod –

19/38

S0 = ({Int}, {C, D}, {x : Int, p : C0,1, n : C∗}, {C → {p, n}, D → {p, x}}, {f : Int → Bool, get x : Int}, {C → ∅, D → {f, get x}}), D(Int) = Z σ = {1C → {p → ∅, n → {5C}}, 5C → {p → ∅, n → ∅}, 1D → {p → {5C}, x → 23}}.

slide-22
SLIDE 22

Object Diagram

– 12 – 2015-06-25 – Sod –

19/38

S0 = ({Int}, {C, D}, {x : Int, p : C0,1, n : C∗}, {C → {p, n}, D → {p, x}}, {f : Int → Bool, get x : Int}, {C → ∅, D → {f, get x}}), D(Int) = Z σ = {1C → {p → ∅, n → {5C}}, 5C → {p → ∅, n → ∅}, 1D → {p → {5C}, x → 23}}.

id : class v1 = d1 . . . vn = dn id : class r

  • ptional

mandatory

  • “compartment”
  • ptional
  • ptional
  • We may represent σ graphically as follows:

1C : C p = ∅ 5C : C p = ∅ n = ∅ 1D : D x = 23 n p

  • r (symbolic identities)

c1 : C p = ∅ c2 : C p = ∅ n = ∅ d : D x = 23 n p

slide-23
SLIDE 23

Alternative Presentation, Dangling References

– 12 – 2015-06-25 – Sod –

20/38

S0 = ({Int}, {C, D}, {x : Int, p : C0,1, n : C∗}, {C → {p, n}, D → {p, x}}, {f : Int → Bool, get x : Int}, {C → ∅, D → {f, get x}}), D(Int) = Z

  • σ1 = {1C → {p → ∅, n → {5C}}, 5C → {p → ∅, n → ∅}, 1D → {p → {5C}, x → 23}}.

1C : C p = ∅ 5C : C p = ∅ n = ∅ 1D : D x = 23 n p 1C : C 5C : C 1D : D x = 23 n p | p | p | n

  • σ2 = {1C → {p → ∅, n → {5C}}, 1D → {p → {5C}, x → 23}}.

1C : C p = ∅ 5C : C X 1D : C x = 23 n p 1C : C 5C : C X 1D : C x = 23 n p | p | p | n

“dangling reference” (∃ u ∈ dom(σ) ∃ r : T, T / ∈ T • σ(u)(r) ⊂ dom(σ))

slide-24
SLIDE 24

Partial vs. Complete Object Diagrams

– 12 – 2015-06-25 – Sod –

21/38

S0 = ({Int}, {C, D}, {x : Int, p : C0,1, n : C∗}, {C → {p, n}, D → {p, x}}, {f : Int → Bool, get x : Int}, {C → ∅, D → {f, get x}}), D(Int) = Z

  • σ = {1C → {p → ∅, n → {5C}}, 5C → {p → ∅, n → ∅}, 1D → {p → {5C}, x → 23}}.

Recall definition system state:

  • Each attribute of an object alive in σ obtains a value by σ.
  • IOW: Each σ assigns to each attribute of each of its alive objects a value from D(V ).

May hinder readability of object diagrams of system states with many alive objects. . .

  • So: partial object diagrams

1C : C 5C : C 1D : C n p

“It is (should be, must not, . . . ) be possible that a C-object and a D-object have a link to one C-object”

  • An object diagram is
  • partial if it is a projection of a proper system state, and
  • complete if we say that it is complete and it uniquely defines a system state.
slide-25
SLIDE 25

Complete vs. Partial Examples

– 12 – 2015-06-25 – Sod –

22/38

σ = {1C → {p → ∅, n → {5C}}, 5C → {p → ∅, n → ∅}, 1D → {p → {5C}, x → 23}}. Complete or partial?

  • 1C : C

p = ∅ 5C : C n = ∅ p = ∅ 1D : D x = 23 n p

  • 1C : C

5C : C 1D : D x = 23 n

  • 1C : C

5C : C 1D : D

slide-26
SLIDE 26

Object Diagrams at Work

– 12 – 2015-06-25 – main –

23/38

slide-27
SLIDE 27

Example: Data Structure (Schumann et al., 2008)

– 12 – 2015-06-25 – Sodatwork –

24/38

BaseNode

+ parent : BaseNode∗ + prevSibling : BaseNode∗ + nextSibling : BaseNode∗ + firstChild : BaseNode∗ + lastChild : BaseNode∗

Node

+ data : T + Node( data : T)

Iterator

+ operator++() : Iterator + operator−−() : Iterator + operator∗() : BaseNode

Forest

+ appendTopLevel( data: T ) + appendChild( parent : Iterator, data : T ) + remove( it : Iterator ) + depth( it : Iterator ) : int + end() : Iterator + begin() : Iterator + empty() : bool + size() : int

− node − begin it − end it

slide-28
SLIDE 28

Example: Illustrative Object Diagram (Schumann et al., 2008)

– 12 – 2015-06-25 – Sodatwork –

25/38

: Iterator : Forest : Iterator A : Node E : Node end : BaseNode B : Node C : Node F : Node D : Node

begin it end it node node firstChild parent firstChild parent nextSib prevSib lastChild firstChild parent nextSib prevSib lastChild firstChild parent nextSib prevSib

BaseNode

+ parent : BaseNode∗ + prevSibling : BaseNode∗ + nextSibling : BaseNode∗ + firstChild : BaseNode∗ + lastChild : BaseNode∗

Node

+ data : T + Node( data : T)

Iterator

+ operator++() : Iterator + operator−−() : Iterator + operator∗() : BaseNode

Forest

+ appendTopLevel( data: T ) + appendChild( parent : Iterator, data : T ) + remove( it : Iterator ) + depth( it : Iterator ) : int + end() : Iterator + begin() : Iterator + empty() : bool + size() : int

− node − begin it − end it

slide-29
SLIDE 29

Object Diagrams for Analysis

– 12 – 2015-06-25 – Sodatwork –

26/38

: M ctime = 27 : N data = d1 : M ctime = 5 : N data = d2 : N data = d3 : N data = d4 : M ctime = 9 : N data = d5 | | | | |

slide-30
SLIDE 30

Towards Object Constraint Logic (OCL) — “Proto-OCL” —

– 12 – 2015-06-25 – main –

27/38

slide-31
SLIDE 31

Constraints on System States

– 12 – 2015-06-25 – Socl –

28/38

C

x : Int

  • Example: for all C-instance, x should never have the value 27.

∀ c : C • x(c) = 27

  • Syntax (wrt. signature S = (T, C, V, atr , F, mth)), c a logical variable:

F ::= c : τC | v(F) : τC → D(τ)⊥, if v : τ ∈ atr(C) | v(F) : τC → τD, if v : D0,1 ∈ atr(C) | v(F) : τC → 2τD, if v : D∗ ∈ atr(C) | f(F1, . . . , Fn) : τ1 × · · · × τn → τ, if f : τ1 × · · · × τn → τ | ∀ c : C • F : τC × B⊥ → B⊥

slide-32
SLIDE 32

Semantics

– 12 – 2015-06-25 – Socl –

29/38

  • Syntax: F ::= c | v(F) | f(F1, . . . , Fn) | ∀ c : C • F
  • Proto-OCL Types:
  • values of τC: D(C) ˙

∪ {⊥}

  • values of D(τ)⊥: D(τ) ˙

∪ {⊥}

  • values of 2τC : D(C∗) ˙

∪ {⊥}

  • values of B⊥: {true, false} ˙

∪ {⊥}

  • plus: integer, strings, whatever you like (need not be in T ), values including ⊥.
  • Semantics:
  • Ic(σ, β) = β(c),
  • Iv(F)(σ, β) = σ (IF(σ, β)) (v) if IF(σ, β) = ⊥, and ⊥ otherwise,
  • If(F1, . . . , Fn)(σ, β) = fI(IF1(σ, β), . . . , IFn(σ, β)),
  • I∀ c : C • F(σ) =

     true , if IF(σ, β[c := u]) = true for all u ∈ dom(σ) ∩ D(C) false , if IF(σ, β[c := u]) = false for some u ∈ dom(σ) ∩ D(C) ⊥ , otherwise

slide-33
SLIDE 33

Semantics Cont’d

– 12 – 2015-06-25 – Socl –

30/38

  • Proto-OCL is a three-valued logic: a formula evaluates to true, false, or ⊥.
  • Example: ∧I(·, ·) : {true, false, ⊥}2 → {true, false, ⊥} is defined as follows:

x1 true true true false false false ⊥ ⊥ ⊥ x2 true false ⊥ true false ⊥ true false ⊥ ∧I(x1, x2) true false ⊥ false false false ⊥ false ⊥

We assume common logical connectives ¬, ∧, ∨, . . . with canonical 3-valued interpretation.

  • Example: +I(·, ·) : (Z ˙

∪ {⊥})2 → Z ˙ ∪ {⊥}

+I(x1, x2) =

  • x1 + x2

, if x1 = ⊥ and x2 = ⊥ ⊥ , otherwise

We assume common arithmetic operations −, /, ∗, . . . and relation symbols >, <, ≤, . . . with monotone 3-valued interpretation.

  • And we assume the special unary function symbol isUndefined:

isUndefinedI(x) =

  • true

, if x = ⊥, false , otherwise

isUndefined I is definite: it never yields ⊥.

slide-34
SLIDE 34

Semantics Cont’d

– 12 – 2015-06-25 – Socl –

31/38

  • Lift σ to a total function which yields ⊥ for non-existing objects or attributes:

σI(u)(v) =          ⊥ , if u / ∈ dom(σ) or v / ∈ dom(σ(u)) u′ , if σ(u)(v) = {u′} and v : C0,1 for some C ⊥ , if σ(u)(v) = ∅ and v : C0,1 for some C σ(u)(v) , otherwise

In the following, we use σ and σI interchangeably; which one is meant should be clear from context.

Example:

σ :

u1 : C x = 13 u2 : C x = 27 |

n n p

|

p

C

x : Int

n 0..1 m 0..∗

  • σI(u1)(x) =
  • σI(u1)(y) =
  • σI(u3)(x) =
  • σI(u3)(y) =
  • σI(u2)(n) =
  • σI(u1)(n) =
  • σI(u1)(p) =
  • σI(u2)(p) =
slide-35
SLIDE 35

Example: Evaluate Formula for System State

– 12 – 2015-06-25 – Socl –

32/38 σ : u: C x = 13

C

x : Int

  • infix notation: ∀ c : C • x(c) = 27
  • prefix notation: ∀ c : C • =(x(c), 27)

Note: = as a binary function symbol, 27 as a 0-ary function symbol.

  • Example:

I∀ c : C • =(x(c), 27)(σ, ∅) = true, because. . . I=(x(c), 27)(σ, β), β = {x → u} =

slide-36
SLIDE 36

Example: Evaluate Formula for System State

– 12 – 2015-06-25 – Socl –

32/38 σ : u: C x = 13

C

x : Int

  • infix notation: ∀ c : C • x(c) = 27
  • prefix notation: ∀ c : C • =(x(c), 27)

Note: = as a binary function symbol, 27 as a 0-ary function symbol.

  • Example:

I∀ c : C • =(x(c), 27)(σ, ∅) = true, because. . . I=(x(c), 27)(σ, β), β = {x → u} = =I( Ix(c)(σ, β), I27(σ, β) ) =

slide-37
SLIDE 37

Example: Evaluate Formula for System State

– 12 – 2015-06-25 – Socl –

32/38 σ : u: C x = 13

C

x : Int

  • infix notation: ∀ c : C • x(c) = 27
  • prefix notation: ∀ c : C • =(x(c), 27)

Note: = as a binary function symbol, 27 as a 0-ary function symbol.

  • Example:

I∀ c : C • =(x(c), 27)(σ, ∅) = true, because. . . I=(x(c), 27)(σ, β), β = {x → u} = =I( Ix(c)(σ, β), I27(σ, β) ) = =I( σ( Ic(σ, β) )(x), 27I ) =

slide-38
SLIDE 38

Example: Evaluate Formula for System State

– 12 – 2015-06-25 – Socl –

32/38 σ : u: C x = 13

C

x : Int

  • infix notation: ∀ c : C • x(c) = 27
  • prefix notation: ∀ c : C • =(x(c), 27)

Note: = as a binary function symbol, 27 as a 0-ary function symbol.

  • Example:

I∀ c : C • =(x(c), 27)(σ, ∅) = true, because. . . I=(x(c), 27)(σ, β), β = {x → u} = =I( Ix(c)(σ, β), I27(σ, β) ) = =I( σ( Ic(σ, β) )(x), 27I ) = =I( σ( β(c) )(x), 27I ) = =I( σ( u )(x), 27I ) = =I( 13, 27 ) = true . . . and u is the only C-object in σ.

slide-39
SLIDE 39

More Interesting Example

– 12 – 2015-06-25 – Socl –

33/38 σ : u: C x = 13 |

n

C

x : Int

n 0..1

∀ c : C • x(n(c)) = 27

  • Similar to the previous slide, we need the value of

σ ( σ( Ic(σ, β) )(n) ) (x)

  • Ic(σ, β) = β(c) = u
  • σ( Ic(σ, β) )(n) = σ( u )(n) = ⊥
  • σ ( σ( Ic(σ, β) )(n) ) (x) = σ( ⊥ )(x) = ⊥
slide-40
SLIDE 40

Object Constraint Language (OCL)

– 12 – 2015-06-25 – Socl –

34/38

OCL is the same — just with less readable (?) syntax.

Literature: (OMG, 2006; Warmer and Kleppe, 1999).

slide-41
SLIDE 41

Examples (from lecture “Softwaretechnik 2008”)

– 12 – 2015-06-25 – Socl –

35/38

TeamMember name : String age : Integer name : String Location participants 2..* meetings * title : String numParticipants : Integer start : Date duration: Time Meeting move(newStart : Date) 1 *

context Meeting

inv: self.participants->size() = numParticipants

context Location

inv: name="Lobby" implies meeting->isEmpty()

  • Prof. Dr. P. Thiemann, http://proglang.informatik.uni-freiburg.de/teaching/swt/2008/
slide-42
SLIDE 42

Where To Put OCL Constraints?

– 12 – 2015-06-25 – Socl –

36/38

  • Notes: A UML note is a diagram element of the form

text text can principally be everything, in particular comments and constraints. Sometimes, content is explicitly classified for clarity: OCL: F

  • Conventions:

C

. . . . . . F

stands for

C

. . . . . . context C inv : F

slide-43
SLIDE 43

References

– 12 – 2015-06-25 – main –

37/38

slide-44
SLIDE 44

References

– 12 – 2015-06-25 – main –

38/38

Kopetz, H. (2011). What I learned from Brian. In Jones, C. B. et al., editors, Dependable and Historic Computing, volume 6875 of LNCS. Springer. Lovins, A. B. and Lovins, L. H. (2001). Brittle Power - Energy Strategy for National Security. Rocky Mountain Institute. Ludewig, J. and Lichter, H. (2013). Software Engineering. dpunkt.verlag, 3. edition. OMG (2006). Object Constraint Language, version 2.0. Technical Report formal/06-05-01. Schumann, M., Steinke, J., Deck, A., and Westphal, B. (2008). Traceviewer technical documentation, version 1.0. Technical report, Carl von Ossietzky Universit¨ at Oldenburg und OFFIS. Warmer, J. and Kleppe, A. (1999). The Object Constraint Language. Addison-Wesley.