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

Chapter 20 — Several forms of the same thing: variants

The staircase light is installed in four forms: the lamp can be a ceiling light or a wall light, and the command can be a button or a presence sensor. This chapter describes how to write these forms in a single entity.

Variants

A variant is one of the alternatives of an aspect of the entity, for example the lamp. It is declared with the line VARIANT group = choice: the name to the left of the = sign is the group name, the one to the right the choice. VARIANT lampada = soffitto declares the variant in which the lamp is the ceiling light. The lines that follow, up to the next VARIANT or to END, form the segment of the variant and hold only with that choice. The lines that precede the first VARIANT are the common lines and hold in every composition.

Variants that have the same group name form a group (or choice group): among the choices of a group only one holds. Different groups are independent and combine with one another. With the group lampada (ceiling or wall) and the group comando (button or presence) there are four compositions.

Only entity lines are written in a segment: OFFERS, USES, COMPOSED OF with its parts, entity guarantees and entity scenarios. The purpose, PURPOSE, is written among the common lines.

The files

The presence sensor provides to the person on the stairs a boundary different from the press:

-- The presence sensor, as seen by the person on the stairs.

CSC Presenza VERSION 0.1
  STATUS HYPOTHESIS
  PURPOSE "Whoever enters the staircase is detected by the presence sensor without pressing anything"

  EVENT IN   passaggio

  GUARANTEE pz1: VERBAL "A person walking less than 4 m from the sensor is detected as a passaggio"
                 VERIFY BY JUDGEMENT "a person who walks at different distances from the sensor"
END
-- The presence sensor, one of the two forms of the command.

ENTITY SensorePresenza VERSION 0.1
  STATUS HYPOTHESIS
  PURPOSE "The sensor detects whoever passes and commands the lamp"

  OFFERS Presenza
  OFFERS Comando
  USES   Alimentazione

  GUARANTEE sp1: VERBAL "Each passaggio is followed by an accendi within 0.2 s"
                 VERIFY BY INSPECTION "the recorded passages and commands"
END

The ceiling light and the wall light provide the same boundary, but with different guarantees:

-- The ceiling light, one of the two forms of the lamp.

ENTITY Plafoniera VERSION 0.1
  STATUS HYPOTHESIS
  PURPOSE "The ceiling light switches on at the command and switches off by itself"

  USES   Comando
  USES   Alimentazione
  OFFERS Luce

  GUARANTEE pl1: VERBAL "After an accendi the light is at full brightness within 0.5 s"
                 VERIFY BY JUDGEMENT "a person who observes the ceiling light while the command is sent"
  GUARANTEE pl2: VERBAL "The light switches off 90 s after the last accendi, with a tolerance of 5 s"
                 VERIFY BY JUDGEMENT "a person with a stopwatch"
END
-- The wall light, one of the two forms of the lamp.

ENTITY Applique VERSION 0.1
  STATUS HYPOTHESIS
  PURPOSE "The wall light switches on at the command and switches off by itself"

  USES   Comando
  USES   Alimentazione
  OFFERS Luce

  GUARANTEE ap1: VERBAL "After an accendi the light is at full brightness within 0.05 s"
                 VERIFY BY JUDGEMENT "a person who observes the wall light while the command is sent"
  GUARANTEE ap2: VERBAL "The light switches off 90 s after the last accendi, with a tolerance of 5 s"
                 VERIFY BY JUDGEMENT "a person with a stopwatch"
END

A single entity describes the four forms:

-- The staircase light: ceiling light or wall light, button or presence sensor.

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

  OFFERS Luce
  USES   Alimentazione

  GUARANTEE ls2: VERBAL "The light switches off 90 s after the last command, with a tolerance of 5 s"
                 VERIFY BY JUDGEMENT "a person with a stopwatch"

  VARIANT lampada = soffitto
    COMPOSED OF
      lampada : Plafoniera
  VARIANT lampada = parete
    COMPOSED OF
      lampada : Applique

  VARIANT comando = pulsante
    OFFERS Pressione
    COMPOSED OF
      pulsante : Pulsante
    GUARANTEE ls1: VERBAL "When someone presses the button, the light switches on"
                   VERIFY BY JUDGEMENT "a person who presses the button and watches"
  VARIANT comando = presenza
    OFFERS Presenza
    COMPOSED OF
      presenza : SensorePresenza
    GUARANTEE ls1p: VERBAL "When someone passes in front of the sensor, the light switches on"
                    VERIFY BY JUDGEMENT "a person who enters the staircase and watches"
END

The choice of the command changes what the entity provides to the person on the stairs, Pressione or Presenza: for this reason the OFFERS line is written inside the segment. The part name lampada appears in two choices of the same group: it is the same role, performed by different entities. The short names of guarantees and scenarios, on the other hand, are unique throughout the entity: ls1 and ls1p have different names.

Who chooses

No line of the entity indicates which composition is implemented: the entity describes all the admitted compositions; whoever composes the system implements one of them. The decision is taken when the system is composed and does not change while the system is operating. No line indicates who decides, when or why; among the choices there is no preference or order, and none is the default. A condition such as “wall light if there is a wall socket, otherwise ceiling light” is a decision rule and is not written with variants; if needed, it is written in words in a guarantee.

The report

$ bcdd check --strict LuceScale.csc
bcdd check --strict LuceScale.csc
lines: 32 (recognised 26, comments 1, blank 5, unrecognised 0)
blocks: 1
  line 3: ENTITY LuceScale VERSION 0.1, STATUS HYPOTHESIS
    line 7: OFFERS Luce in Luce.csc at line 3: VERSION 0.1, STATUS HYPOTHESIS, no errors
    line 8: USES Alimentazione in Alimentazione.csc at line 3: VERSION 0.1, STATUS HYPOTHESIS, no errors
    line 15: lampada : Plafoniera in Plafoniera.csc at line 3: VERSION 0.1, STATUS HYPOTHESIS, no errors
    line 18: lampada : Applique in Applique.csc at line 3: VERSION 0.1, STATUS HYPOTHESIS, no errors
    line 21: OFFERS Pressione in Pressione.csc at line 3: VERSION 0.1, STATUS HYPOTHESIS, no errors
    line 23: pulsante : Pulsante in Pulsante.csc at line 3: VERSION 0.1, STATUS HYPOTHESIS, no errors
    line 27: OFFERS Presenza in Presenza.csc at line 3: VERSION 0.1, STATUS HYPOTHESIS, no errors
    line 29: presenza : SensorePresenza in SensorePresenza.csc at line 3: VERSION 0.1, STATUS HYPOTHESIS, no errors

1. ERRORS: 0

2. DEGREE OF THE CONTRACTUAL LINES
  verbal: 3
  formal: 0
  declared extension: 0
  unrecognised: 0
  line 10: GUARANTEE ls2 verbal
  line 24: GUARANTEE ls1 verbal
  line 30: GUARANTEE ls1p verbal

3. UNDECIDED: 0

4. PENDING APPROVAL, NOT CONTRACT: 3
  line 10: GUARANTEE ls2
  line 24: GUARANTEE ls1
  line 30: GUARANTEE ls1p

5. UNRECOGNISED LINES: 0

6. UNDECLARED TYPES: 0

7. CSCs NAMED BUT NOT CHECKED: 0

8. USES WITHIN ENTITIES: 7
  line 15: lampada uses Comando: it is provided by pulsante (line 23) (in: lampada = soffitto, comando = pulsante)
  line 15: lampada uses Comando: it is provided by presenza (line 29) (in: lampada = soffitto, comando = presenza)
  line 15: lampada uses Alimentazione: LuceScale uses it from outside (line 8) (in: lampada = soffitto)
  line 18: lampada uses Comando: it is provided by pulsante (line 23) (in: lampada = parete, comando = pulsante)
  line 18: lampada uses Comando: it is provided by presenza (line 29) (in: lampada = parete, comando = presenza)
  line 18: lampada uses Alimentazione: LuceScale uses it from outside (line 8) (in: lampada = parete)
  line 29: presenza uses Alimentazione: LuceScale uses it from outside (line 8) (in: comando = presenza)

9. COMPOSITIONS: 4
  line 3: ENTITY LuceScale: 4
    lampada = soffitto, comando = pulsante
    lampada = soffitto, comando = presenza
    lampada = parete, comando = pulsante
    lampada = parete, comando = presenza

10. DECLARED ABSENCES: 0

outcome: no errors

Section 9 lists the four compositions. The name of a composition is the sequence of its choices, in the order in which the groups appear in the file. The entries of section 8 have the suffix described in chapter 19: lampada uses Alimentazione: LuceScale uses it from outside (line 8) (in: lampada = soffitto) holds in both compositions with the ceiling light.

A part with variants

If an entity that has variants is in turn a part of another entity, its choices appear in the compositions of the entity that contains it. In the entity Condominio, which contains scale : LuceScale, there are four compositions, and their names are preceded by the name of the part:

9. COMPOSITIONS: 4
  line 3: ENTITY Condominio: 4
    scale.lampada = soffitto, scale.comando = pulsante
    scale.lampada = soffitto, scale.comando = presenza
    scale.lampada = parete, scale.comando = pulsante
    scale.lampada = parete, scale.comando = presenza

The entity that contains the part must hold in every composition of the part. If Condominio provides only Luce, the boundaries Pressione and Presenza provided by the staircase light are used by no part:

1. ERRORS: 2
  line 11: [E17] the part scale provides connector Pressione: no other part of Condominio uses it, nor does Condominio provide it from outside (in: scale.comando = pulsante)
  line 11: [E17] the part scale provides connector Presenza: no other part of Condominio uses it, nor does Condominio provide it from outside (in: scale.comando = presenza)

A single choice of a part cannot be fixed from the entity that contains it: the language does not provide a form for doing so.

Only the choice groups of a part enter the compositions of the entity that contains it, not its optional parts. From outside a part counts for what it provides and uses, and an optional part of it does not change that: a Condominio that contains the staircase light of chapter 19, with the optional twilight sensor, has a single composition, and its report does not have sections 9 and 10.

The limit on compositions

Compositions multiply: every group of two choices and every optional part doubles their number. bcdd checks at most 64 compositions per entity. Beyond this number it does not check the closure of the entity and reports an error; for example, with seven groups of two choices each:

1. ERRORS: 1
  line 1: [E23] entity Troppe has more than 64 compositions: bcdd does not check them one by one. Remove a choice, or divide the entity into smaller entities
…
9. COMPOSITIONS: 0
  line 1: ENTITY Troppe: more than 64, not checked

Summary

Special cases

Incomplete choice. If the presence sensor does not declare OFFERS Comando, in the compositions with the sensor no part provides the command to the lamp:

1. ERRORS: 2
  line 15: [E14] the part lampada uses connector Comando: no other part of LuceScale provides it, nor does LuceScale use it from outside (in: lampada = soffitto, comando = presenza)
  line 18: [E14] the part lampada uses connector Comando: no other part of LuceScale provides it, nor does LuceScale use it from outside (in: lampada = parete, comando = presenza)

The error appears twice, once for each lamp, and each time in a single composition. It is not a declared absence: there is no optional part in the entity to explain it.

Group with a single choice. If the group lampada has only the choice soffitto:

1. ERRORS: 1
  line 13: [E22] choice group lampada has a single choice (soffitto): at least two are needed; a part that may be missing is written with [0 .. 1]

A group has at least two choices. A part that may be present or not is written as an optional part (chapter 19), not with a variant without lines.

Purpose in a segment. A PURPOSE written immediately after VARIANT lampada = parete:

1. ERRORS: 1
  line 17: [E21] PURPOSE cannot appear in a VARIANT segment: write it before the first VARIANT

Variant in a CSC. Variants are written only in entities. A VARIANT line in the CSC Luce:

1. ERRORS: 1
  line 11: [E21] VARIANT cannot appear in a CSC: variants are written in an entity

Common scenario that names a boundary of a single choice. A scenario among the common lines holds in all compositions. If it names Pressione.premuto, in the compositions with the presence sensor the boundary Pressione is not present:

1. ERRORS: 1
  line 13: [E20] Pressione.premuto: LuceScale neither provides nor uses connector Pressione; a scenario can cite only the connectors of LuceScale (in: comando = presenza)

The scenario is moved into the segment comando = pulsante, where it holds only with the button.