0

How to specify when giving a generic parameter that it should implement some specific creation method? as LIST[G -> create make end] doesn't work :-(

class diagram

In my particular case, * SMA_INVERTER_MANAGER_CSV has inherited from CONSUMPTION_SECTOR_MODBUS_DEVICE_CSVa list of devices as devices: LINKED_SET[G] as G -> MEASURING_POINT_MODBUS_DEVICE create make_from_file_path end.

I'd like the SMA_INVERTER_MANAGER_CSV class to be able into devices: LINKED_SET[G] to be able to have either JANITZA_DEVICE, SUNSPEC_DEVICE, ABB_DEVICE, etc. Giving the generic parameter as MEASURING_POINT_MODBUS_DEVICE seems to come out of a sense, but how do I specify that I'd like the creation method to be make_from_file_path

Hope the description is sufficient to understand, refactoring I think this question is linked -> explicit creation type not conforming to type of target

The only workaround for the moment I found working for the moment is

class
    SMA_INVERTER_MANAGER_CSV

inherit
    CONSUMPTION_SECTOR_MODBUS_DEVICE_CSV[SUNSPEC_DEVICE]

create
    make


end

but I'd like it to be

class
    SMA_INVERTER_MANAGER_CSV

inherit
    CONSUMPTION_SECTOR_MODBUS_DEVICE_CSV[MEASURING_POINT_MODBUS_DEVICE]

create
    make


end

which would generate a conformance problem because MEASURING_POINT_MODBUS_DEVICE generic parameter doesn't specify make_from_file_path as creation procedure as its deferred

Pipo
  • 4,653
  • 38
  • 47

1 Answers1

1

There is more than a conformance problem. MEASURING_POINT_MODBUS_DEVICE is deferred. Therefore, it cannot be used as an actual parameter for CONSUMPTION_SECTOR_MODBUS_DEVICE_CSV. If it were allowed, how would CONSUMPTION_SECTOR_MODBUS_DEVICE_CSV create an instance of a deferred class?

One possible solution — supplying an effective class — is mentioned in the question. Another solution is to add a formal generic parameter to SMA_INVERTER_MANAGER_CSV with the corresponding constraint and to use it for the actual generic of CONSUMPTION_SECTOR_MODBUS_DEVICE_CSV.

Alexander Kogtenkov
  • 5,770
  • 1
  • 27
  • 35
  • `how would CONSUMPTION_SECTOR_MODBUS_DEVICE_CSV create an instance of a deferred class` good point! That gave me the key of the reason why! – Pipo Oct 15 '19 at 11:08
  • So solution 1) would be having an effective class which for my example would be to undefer the MEASURING_POINT_MODBUS_DEVICE class, but doing that I'd remove what makes sense for me which is obligate at compile time the descendants to implement `set_measure_units` procedure, I seem to be obligated to redefine it and being unable to have it deferred. So a workaround as at compile time its impossible to solve my problem would be to add a `check implement_it: False end` into its implementation at `MEASURING_POINT_MODBUS_DEVICE` level. Is there any other solution? – Pipo Oct 15 '19 at 11:16
  • @Pipo What about solution 2 mentioned in the answer? – Alexander Kogtenkov Oct 15 '19 at 15:10
  • Actually it was what I intented to do but did not understand how to make it :-( – Pipo Oct 15 '19 at 18:12
  • 1
    @Pipo Instead of fixing the parameter in `SMA_INVERTER_MANAGER_CSV`, it might be possible to keep it: `SMA_INVERTER_MANAGER_CSV [G -> ...]` would inherit `CONSUMPTION_SECTOR_MODBUS_DEVICE_CSV [G]`. Clients of the class would then specify an effective actual parameter as needed, e.g. `SMA_INVERTER_MANAGER_CSV [ABB_DEVICE]`. – Alexander Kogtenkov Oct 16 '19 at 08:22