Computer Science / Software Engineering Notes Network

Software Modelling and Design

Matthew Barnes

Contents

Requirements analysis        5

Requirement definition        5

Types of requirements        5

Functional requirement        5

Nonfunctional requirement        5

Design requirement        5

Constraints        5

Assumptions        5

Types of functional requirements        6

Normal        6

Error        6

Safety        6

Security        6

Requirement definition process        6

Define scope        6

Operational scenarios        7

Identify interfaces        7

Writing requirements        8

Level requirements        8

Access verification        8

Access verification (sanity check)        9

Baseline requirements        9

UML        10

Code design        10

Why use UML        10

Models        10

Design representation        10

Dealing with complex problems        10

Hierarchy relationships        10

Modelling in UML        11

Functional modelling (use case diagrams)        11

System boundary        11

Actors        11

Use case        12

Association        12

Generalisation        12

Types of generalisation        12

Include        12

Extend        13

Multiplicity        13

Use case diagram example        14

Object modelling (class diagrams)        14

Classes        14

Associations and multiplicity        15

Labels        15

Association classes        15

Reflexive associations        15

Directionality        15

Qualifiers        15

Generalisations        16

Aggregations and compositions        16

Aggregation        16

Composition        16

Object Constraint Language (OCL)        17

Object modelling (object diagrams)        17

Types of objects        18

Abbott’s Heuristic        18

Dynamic modelling        19

Interaction diagrams        19

Sequence diagrams        19

Communication diagrams        21

State machine diagrams        21

Activity diagrams        23

Model validation and verification        25

Event-B        25

Introduction to Event-B        26

The basics        26

Defining types        27

Relations and functions        27

Ordered pair        27

Cartesian product        28

Relations        28

Domain and range        28

Relational image        28

Partial function        28

Well-definedness        29

Restrictions and subtractions        29

Function overriding        30

Total function        30

Relational inverse        30

Relational composition        30

Symbols        30

Multiplicity to association        34

Classes and associations        35

Primary and secondary carrier sets        36

Class diagrams        36

Class declaration in Event-B        37

Class definition in Event-B        37

AddPlayer        37

AddItem        37

ReadItem        38

WriteItem        38

ChangeRequirement        39

LevelUp        39

EquipItem        39

RemovePlayer        40

RemoveItem        40

Extension refinement        41

Refinement step        41

What can you do with refinement        41

Syntax        41

Machine extension        41

Event extension        41

Examples        42

Queues        43

Injective functions        43

Single queue        43

Multiple queues        44

Modelling state machines        45

What is a state machine        45

Modelling states        45

Invariants relating to the states        46

Partition operator        46

Set comprehension        46

Query event        46

Miscellaneous        47

Test design        47

Testing terms        47

Test cases        47

Equivalence class testing        48

Weak normal ECT        48

Strong normal ECT        49

Weak robust ECT        49

Strong robust ECT        50

Boundary value testing        50

Normal BVT        50

Adding robustness        50

Adding worst-cases        51

Adding robustness + worst-cases        51

Extras        51

Design patterns        51

Get-15 and Tic-tac-toe        52

Design patterns        52

Composite pattern        53

Taxonomies        54

Observer        54

Adapter        54


Requirements analysis

Requirement definition

Types of requirements

Functional requirement

Nonfunctional requirement

Design requirement

Constraints

Assumptions

Types of functional requirements

Normal

Error

Safety

Security

Requirement definition process

Define scope

Operational scenarios

Identify interfaces

“Fortnite ninja fornite ninja fornite ninja fornite ninja

ninga”

- Anonymous

Writing requirements

Level requirements

Access verification

Access verification (sanity check)

Baseline requirements


UML

Code design

Why use UML

Models

Design representation

Dealing with complex problems

Hierarchy relationships

Modelling in UML

Functional modelling (use case diagrams)

System boundary

Actors

Use case

Association

Generalisation

Types of generalisation

Include

Extend

Multiplicity

Use case diagram example

Object modelling (class diagrams)

Classes

Associations and multiplicity

Labels

Association classes

Reflexive associations

Directionality

Qualifiers

Generalisations

Aggregations and compositions

Aggregation

Composition

Object Constraint Language (OCL)

Object modelling (object diagrams)

Things in class diagrams

Things in object diagrams

Class

Object

Association

Link

Generalisations

N/A (they don’t exist in object diagrams)

Types of objects

Abbott’s Heuristic

Part of speech

Model component

Examples

Proper noun

Instance

Alice

Common noun

Class

Field officer

Doing verb

Operation

Creates, submits, selects

Being verb

Inheritance

Is a kind of, is one of either

Having verb

Aggregation

Has, consists of, includes

Modal verbs

Constraints

Must be

Adjective

Attribute

Blue square

Dynamic modelling

Interaction diagrams

Sequence diagrams

Communication diagrams

State machine diagrams

Activity diagrams

or

Model validation and verification


Event-B

Introduction to Event-B

The basics

context BuildingContext
sets USER
end


machine Building
variables register in out
invariants


inv1: register  USER // set of registered users
inv2: register = in  out // all registered users must be
                           // either inside or outside
inv3: in  out = {} // no user can be inside and outside

initialisation in, out, register := {}, {}, {}

events

Enter

  any s where

    s  out  register

  then

    in := in  {s}

    out := out \ {s}

  end

Leave

  any s where

    s  in  register

  then

    in := in \ {s}

    out := out  {s}

  end

Keyword

Example

Explanation

context

context BuildingContext

Defines the scope of the machines/systems, e.g. everything we describe is within the context of the building, namely, “BuildingContext”.

sets

sets USER

Defines the types of groups within the whole system, e.g. there is a “USER” group within the building’s context.

end

end

Simply marks the end of a clause, for example the ‘end’ in ‘context ... sets ... end’ marks the end of the clause describing the context of the system. It is also used with events.

machine

machine Building

Marks the start of a clause that describes a machine within the context of the system, e.g. there is a “Building” machine in the building’s context.

variables

variables register in out

Defines the variables within a machine, e.g. ‘register’, ‘in’ and ‘out’ are variables within the ‘Building’ machine.

invariants

inv1: register  USER

Invariants are rules that the variables must abide by, e.g. the ‘register’ variable must always be a subset of ‘USER’.

initialisation

initialisation in, out, register := {}, {}, {}

Defines variables at the start of the machine’s lifetime, e.g. ‘in’, ‘out’ and ‘register’ variables will all be empty sets at the start

events

events Enter ... Leave ...

Marks the start of the definition of events related to a machine, e.g. ‘Enter’ and ‘Leave’ are events defined in the machine ‘Building’.

Defining types

Relations and functions

Ordered pair

Cartesian product

Relations

Domain and range

Relational image

Partial function

Well-definedness

Restrictions and subtractions

Type of restriction or subtraction

Syntax

Explanation

Example

Domain restriction

A  R

Filter out domain elements, leaving only the domain elements specified.

{1,3} ◁ {1→10,2→20,3→30} = {1→10,3→30}

Domain subtraction

A ⩤ R

Remove specified domain elements.

{1,3} ⩤ {1→10,2→20,3→30} = {2→20}

Range restriction

R ▷ B

Filter out range elements, leaving only the range elements specified.

{1→10,2→20,3→30}{10,30} = {1→10,3→30}

Range subtraction

R ⩥ B

Remove specified range elements.

{1→10,2→20,3→30}{10,30} = {2→20}

Function overriding

Total function

Relational inverse

Relational composition

Symbols

Symbol

Meaning

Example / Illustration

Ordered Pair

Not a relation or a function, just one pairing from one element to another.

Cartesian product

Every single possible pairing from elements of one set to another.

Relations

These kinds of mappings can map from one domain element to multiple range elements.

Normal relation

A relation of any mapping from one set to another. Think of this as simply a subset of the cartesian product.

Total relation

Like a normal relation, but all of the domain is mapped to something.

Surjective relation

Like a normal relation, but all of the range is being mapped by something.

Total surjective relation

Like a normal relation, but all elements from the domain map to all elements in the range.

Functions

Like relations, but you cannot map one domain element to multiple range elements.

Partial function

Not all of the domain has to be mapped.

Total function

Maps all elements of the domain to an element of the range.

Partial injection

Not all elements of the domain have to be mapped, but the ones that are need to map to unique range elements.

Total injection

All elements from the domain need to be mapped, and they all need unique range elements.

Partial surjection

Not all domain elements need to be mapped, but all elements from the range need to be mapped from something.

Total surjection

All elements from the domain need to be mapped, and all elements from the range need to be mapped by something.

Bijection

All elements from the domain need to be mapped, all the elements from the range need to be mapped and no two domain elements should map to the same range element.

Multiplicity to association

0..1

Injective

1

Injective + surjective

1..*

Surjective

*

None

0..1

Partial function (functional)

Partial injective function

Partial injective + surjective function

Partial surjective function

Partial function

1

Total function (totality + functional)

Total injective function

Total injective + surjective function (bijection)

Total surjective function

Total function

1..*

Total relation (totality)

Total injective relation

Total injective + surjective relation

Total surjective relation

Total relation

*

Partial relation (none)

Partial injective relation

Partial injective + surjective relation

Partial surjective relation

Partial relation

Classes and associations

Primary and secondary carrier sets

Class diagrams

Class declaration in Event-B

sets ITEM DATA PLAYER

constants LEVEL
axioms LEVEL = 1..99
variables item, player, data, requirement, level, equipped

invariants
 item
 ⊆ ITEM

  player ⊆ PLAYER
 data ∈ item → DATA
 requirement ∈ item → LEVEL
 level ∈ player → LEVEL

  equipped ∈ player ⇸ item

initialisation

item := {} player := {} data := {} requirement := {} level := {}

Class definition in Event-B

AddPlayer

AddPlayer
 
any p, l where
   p ∈ PLAYER
   p ∉ player
   l ∈ LEVEL
 
then
   player := player ∪ {p}
   level(p) := l
 
end

AddItem

AddItem
 
any i, l, d where
   i ∈ ITEM

    i ∉ item
   d ∈ DATA
   l ∈ LEVEL
 
then
   item := item ∪ {i}
   data(i) := d

    requirement(i) := l
 
end

ReadItem

ReadItem
 
any i, p, result where

    i ∈ item

    p ∈ player

    level(p) ≥ requirement(i)
   result = data(i)
 
end

WriteItem

WriteItem
 
any i, p, d where

    i ∈ item

    p ∈ player

    d ∈ DATA

    level(p) ≥ requirement(i)
 
then

    data(i) := d
 
end

ChangeRequirement

ChangeRequirement
 
any i, l where

    i ∈ item

    l ∈ LEVEL

    equipped-1;level(i) ≥ l
 
then

    requirement(i) := l
 
end

LevelUp

LevelUp
 
any p where

    p ∈ player

    level(p) + 1 ∈ LEVEL
 
then

    level(p) := level(p) + 1
 
end

EquipItem

EquipItem
 
any p, i where

    p ∈ player

    i ∈ item

    level(p) ≥ requirement(i)
 
then

    equipped(p) := i
 
end

RemovePlayer

RemovePlayer
 
any p where

    p ∈ player
 
then

    player := player \ {p}

    equipped := {p} ⩤ equipped

    level := {p} ⩤ level
 
end

RemoveItem

RemoveItem
 
any i where

    i ∈ item
 
then

    item := item \ {i}

    requirement := {i} ⩤ requirement

    data := {i} ⩤ data

    equipped := equipped ⩥ {i}
 
end

Extension refinement

Refinement step

What can you do with refinement

Syntax

Machine extension

machine M2
refines M1
variables ...
invariants ...
events...

Event extension

E2 extends E1
 
any <additional parameters> where

    <additional conditions>
 
then

    <additional actions>
 
end

Examples

context BuildingContext
sets USER
end


machine Building1
variables register in out
invariants


inv1: register  USER // set of registered users
inv2: register = in  out // all registered users must be
                           // either inside or outside
inv3: in  out = {} // no user can be inside and outside

initialisation in, out, register := {}, {}, {}

events

Enter

  any s where

    s  out  register

  then

    in := in  {s}

    out := out \ {s}

  end

Leave

  any s where

    s  in  register

  then

    in := in \ {s}

    out := out  {s}

  end

machine Building2

refines Building1
variables register in out room2B
invariants


inv1: room2B  in // Everyone in 2B must be in the building

initialisation in, out, register, room2B := {}, {}, {}

events

Enter2B ≙

  any s where

    s  in  register

  then

    room2B := room2B U {s}

  end

Leave2B ≙

  any s where

    s  room2B

  then

    room2B := room2B \ {s}

  end

Queues

Injective functions

Single queue

inv1: element ⊆ ELEMENT

inv2: position ∈ element ↣ POSITION

event        EnqueueJob

 any e p

 where

  e ∉ element

  p ∈ POSITION

  ∀k· k ∈ element ⇒ p > position(k) // p is the highest position of all elements in the queue

 then

  element ≔ element U {e}

  position(e) ≔ p

end

event        DequeueJob

 any e

 where

  e ∈ element

  ∀k· k ∈ element ⇒ position(e) ≤ position(k) // e is the lowest positioned element of the whole queue

 then

  element ≔ element \ {e}

  position ≔ {e}  position

end

Multiple queues

inv1: e_queue ∈ element → queue

inv2: ∀e,k·e ∈ element ∧ k ∈ element ∧

   e ≠ k ∧

   e_queue(e) = e_queue(k)

⇒  position(e) ≠ position(k)

event        QueueJob

 any e p q

 where

  e ∉ element

  p ∈ POSITION

  q ∈ queue

  ∀k· k ∈ element ∧ e_queue(k) = q ⇒ p > position(k) // p is the highest position of all elements in the queue

 then

  element ≔ element U {e}

  position(e) ≔ p

  e_queue(e) ≔ q

end

event        DequeueJob

 any e, q

 where

  e ∈ element

  q ∈ e_queue(e)

  ∀k· k ∈ element ∧ e_queue(k) ⇒ q > position(e) ≤ position(k) // e is the lowest positioned element of the whole queue

 then

  element ≔ element \ {e}

  position ≔ {e} ⩤ position

  e_queue ≔ {e} ⩤ e_queue

end

Modelling state machines

What is a state machine

Modelling states

in ⊆ user \\ users in the ‘in’ state
out ⊆ user
\\ users in the ‘out’ state

Enter
  any u where

    u ∈ out

    u ∉ in
 
then

    in := in U {u}

    out := out \ {u}
 
end

Leave
 
any u where

    u ∈ in

    u ∉ out
 
then

    in := in \ {u}

    out := out U {u}
 
end

Invariants relating to the states

in ∩ out = Ø

Partition operator

Set comprehension

Query event

GetFriends
 
any u, result where

    u ∈ users

    result = { f | f ∈ users ∧ f ∈ friends[{u}] }
 
end

Miscellaneous

Test design

Testing terms

Test cases

ID, date

Module / unit name

Test specification

Expected result

Pass?

Equivalence class testing

Weak normal ECT

Strong normal ECT

Weak robust ECT

Strong robust ECT

Boundary value testing

Normal BVT

Adding robustness

Adding worst-cases

Adding robustness + worst-cases

Extras

Design patterns

Get-15 and Tic-tac-toe

Design patterns

Composite pattern

Taxonomies

Observer

Adapter