Search code examples
eiffel

Eiffel: a way to call precursor redefined feature on another function


I'm looking for a way to call Precursor on another feature. The context is that I redefine a routine calling another heir's feature that calls mine, and I'd like to call it explicitly. Is there a way to do something such as in java Precursor.feature_a.

If not, the only alternative I find is to write a feature_a_implementation and call it from redefined feature. Is there a particular reason not to have this mechanism? The consequences of doing that would be to define 2 times the contract of feature_a into feature_a and feature_a_implementation


Solution

  • Feature replication can be used for that:

    class A feature
        f do print ("A") end
    end
    
    class B inherit
        A redefine f select f end
        A rename f as g end
    feature
        f do print ("B") end
        h do g end
    end
    

    Feature f of class A appears in class B twice: under name f (the redefined and selected version) and under name g (the original version). The feature h calls g and prints A as expected.