Logo BCDDLogo CSC
BCDDBehavioural Contract-Driven Design
version 1.0-beta
ITEN

Chapter 16 — The number of copies of a part

The block of flats has five floors, and on each floor there is a button. The buttons are identical: each provides Pressione and Comando. This chapter describes how to indicate the number of copies of a part and what each copy guarantees.

Multiplicity

In the line of a part, after the name of the entity that describes it (here Pulsante), the number of copies of the part contained in the entity can be indicated between square brackets: pulsante : Pulsante [1 .. 5] indicates from one to five copies. This indication is called multiplicity. The two numbers, the minimum and the maximum, are integers, and the minimum does not exceed the maximum. Without multiplicity a part has exactly one copy.

-- The staircase light, with one button per floor.

ENTITY LuceScale VERSION 0.1
  STATUS HYPOTHESIS
  PURPOSE "The person on the stairs presses the button on their floor and has light to go up or down"

  OFFERS Pressione
  OFFERS Luce
  USES   Alimentazione

  COMPOSED OF
    pulsante : Pulsante [1 .. 5]
    lampada  : Lampada

  GUARANTEE ls1: VERBAL "When someone presses any one of the buttons, the light switches on"
                 VERIFY BY JUDGEMENT "a person who presses the button on each floor and watches"
  GUARANTEE ls2: VERBAL "The light switches off 90 s after the last press on any one of the buttons, with a tolerance of 5 s"
                 VERIFY BY JUDGEMENT "a person who presses buttons on different floors and measures with a stopwatch"
END

The entity guarantees now refer to “any one of the buttons”.

What each copy guarantees

Each copy keeps in full the guarantees of the entity that describes the part: each button provides Pressione and Comando and keeps the guarantee pu1. Multiplicity establishes nothing else:

A copy does not use what another copy of the same part provides: the OFFERS line of one copy does not satisfy the USES line of another copy.

The report

$ bcdd check --strict LuceScale.csc
bcdd check --strict LuceScale.csc
lines: 19 (recognised 14, comments 1, blank 4, unrecognised 0)
blocks: 1
  line 3: ENTITY LuceScale VERSION 0.1, STATUS HYPOTHESIS
    line 7: OFFERS Pressione in Pressione.csc at line 3: VERSION 0.1, STATUS HYPOTHESIS, no errors
    line 8: OFFERS Luce in Luce.csc at line 3: VERSION 0.1, STATUS HYPOTHESIS, no errors
    line 9: USES Alimentazione in Alimentazione.csc at line 3: VERSION 0.1, STATUS HYPOTHESIS, no errors
    line 12: pulsante : Pulsante in Pulsante.csc at line 3: VERSION 0.1, STATUS HYPOTHESIS, no errors
    line 13: lampada : Lampada in Lampada.csc at line 3: VERSION 0.1, STATUS HYPOTHESIS, no errors

1. ERRORS: 0

2. DEGREE OF THE CONTRACTUAL LINES
  verbal: 2
  formal: 0
  declared extension: 0
  unrecognised: 0
  line 15: GUARANTEE ls1 verbal
  line 17: GUARANTEE ls2 verbal

3. UNDECIDED: 0

4. PENDING APPROVAL, NOT CONTRACT: 2
  line 15: GUARANTEE ls1
  line 17: GUARANTEE ls2

5. UNRECOGNISED LINES: 0

6. UNDECLARED TYPES: 0

7. CSCs NAMED BUT NOT CHECKED: 0

8. USES WITHIN ENTITIES: 2
  line 13: lampada uses Comando: it is provided by pulsante (line 12)
  line 13: lampada uses Alimentazione: LuceScale uses it from outside (line 9)

outcome: no errors

In the report the citation of the part does not show the multiplicity: line 12: pulsante : Pulsante in Pulsante.csc. For the purposes of closure the line counts as a single part, whatever the number of copies.

Summary

Special cases

Minimum greater than the maximum. With [5 .. 1]:

1. ERRORS: 1
  line 12: [E19] the part pulsante has an invalid number of copies: [5 .. 1]. Write [minimum .. maximum] with two integers: the minimum 0 or more, the maximum at least 1 and not smaller than the minimum

The line still counts as a part: closure is checked as if the multiplicity were correct. The same error appears for a limit with a decimal part, such as [1.5 .. 5]. The minimum 0 indicates a part that may be absent (chapter 19).

Incomplete multiplicity. The line pulsante : Pulsante [1 .. ] is not recognised and is not a part: the entity turns out to lack the button, with the errors of chapter 13.

1. ERRORS: 2
  line 7: [E16] the public connector Pressione of LuceScale (provided) is not assigned to any part
  line 13: [E14] the part lampada uses connector Comando: no other part of LuceScale provides it, nor does LuceScale use it from outside
…
5. UNRECOGNISED LINES: 1
  line 12: pulsante : Pulsante [1 .. ]

Copies that must each use the command of the others. A button has an indicator light that flashes at every command, including those of the other buttons. For this reason it provides and uses Comando:

-- The button with the indicator light.

ENTITY PulsanteSpia VERSION 0.1
  STATUS HYPOTHESIS
  PURPOSE "The button receives the press, commands the lamp and lights its indicator at every command"

  OFFERS Pressione
  OFFERS Comando
  USES   Comando

  GUARANTEE ps1: VERBAL "Each press is followed by an accendi within 0.1 s"
                 VERIFY BY INSPECTION "the recorded presses and commands"
  GUARANTEE ps2: VERBAL "At every accendi, sent by this button or by another, the indicator light of the button flashes for 1 s"
                 VERIFY BY JUDGEMENT "a person who presses a button and watches the indicator lights of the others"
END

In an entity with pulsante : PulsanteSpia [1 .. 5] the copy that sends the command does not satisfy the USES lines of the other copies:

1. ERRORS: 1
  line 12: [E14] the part pulsante uses connector Comando: no other part of LuceSpia provides it, nor does LuceSpia use it from outside

If each button must use the command of the others, the buttons are written as distinct parts, one per floor (piano1 : PulsanteSpia, piano2 : PulsanteSpia, …): each part satisfies the USES lines of the others.