0

Eiffel Studio seems to pass through my requirements even if I have them enabled on project settings. And as far as I remember I was able some time to put a break point into the requirements...

I don't understand what I'am missing here, as you can see in my example, the requirement passes through as I have the same condition on the code and it goes into (attached {POWER_DEVICE} a_csv.device as l_dev).

enter image description here

U. Windl
  • 3,480
  • 26
  • 54
Pipo
  • 4,653
  • 38
  • 47

1 Answers1

1

A general rule for inherited assertions is the following:

  • preconditions can be only relaxed;
  • postconditions can be only strengthened.

In the particular example the effective precondition is

    True
or else
    valid_csv (a_csv) and then attached {POWER_DEVICE} a_csv.device

This is reflected by the keywords require at the beginning and require else in the middle of the combined precondition in the flat form of the feature. The expression True is inherited. This is the precondition of the feature in the parent.

A possible solution is to move valid_csv (a_csv) to the parent feature, and redefine valid_csv in the descendant. If valid_csv is common for all calls, but the second test varies across descendants, it might be better to introduce a new feature is_known and have 2 precondition subclauses in the parent:

is_valid_csv: is_valid_csv (a_csv)
is_known_csv: is_known_csv (a_csv)

The implementation of is_known_csv in the class POWER_CSV_PROCESSOR would be

is_known_csv (a_csv: ...)
    do
        Result := attached {POWER_DEVICE} a_csv.device
    end

and the precondition of feature process in POWER_CSV_PROCESSOR would be empty.

The caller would then do something like

if processor.is_known_csv (csv) then
    processor.process (csv)
end
Alexander Kogtenkov
  • 5,770
  • 1
  • 27
  • 35
  • Many thx, discovering everyday some `I thought it was...` is there a place I can find the semantic of require else? I wrote it so many times without even thinking about its semantic in fact – Pipo May 05 '20 at 15:00
  • @Pipo Most information is available online. For example, feature contracts and inheritance is discussed at [eiffel.org](https://www.eiffel.org/doc/uuid/c90e6ee3-b39d-48e5-2321-a34e12fd5327#Inheritance_and_contracts). For offline reading, I would go for Object-Oriented Software Construction 2nd edition. It's a bit outdated and does not reflect most recent Eiffel capabilities like [tag:void-safety] or SCOOP. However, it gives good background on the general ideas of object-oriented programming, [tag:design-by-contract], etc. – Alexander Kogtenkov May 05 '20 at 17:19