Pipo
Pipo

Reputation: 5093

Eiffel: change the signature of a inherited feature

How is the correct way to change the signature of a feature in Eiffel if any? if there is no option as I understood, how would be the correct way to define in a parent class that there will be a feature to be able to select but still don't know arguments number and types (types are resolvable with polymorphism...)

Is the only available playing with polymorphism having an argument into class a to select of type ANY?

class SELECTABLE

class SELECTABLE

    select
        deferred 
        end

end -- class

class DB_SERVICE

class DB_SERVICE

inherit
    SELECTABLE
        (...)

feature -- Status setting


    select (a_db_connection: DB_CONNECTION)
        local
            l_qry: STRING
        do
            item := first_item_from_qry (l_qry)
        end

end -- class

Upvotes: 0

Views: 66

Answers (1)

Eric Bezault
Eric Bezault

Reputation: 141

Having the following in class SELECTABLE is indeed a solution:

select (a: ANY)
    deferred
    end

Another solution is to use TUPLE:

select (a: TUPLE)
    deferred
    end

This allows you to have more than one argument in descendant classes:

select (a: TUPLE [db_connection: DB_CONNECTION])
    do
        a.db_connection.do_something
    end

which can be called:

a_db_server.select (a_db_connection)

or:

select (a: TUPLE [db_connection: DB_CONNECTION; db_parameters: DB_PARAMETERS])
    do
        a.db_connection.do_something (a.db_parameters)
    end

which can be called:

a_db_server.select (a_db_connection, a_dp_parameters)

Note that in that case, the need for the explicit tuple notation [...] in the argument of select is optional.

And of course, select is a keyword in Eiffel. You will have to use another name for your feature.

Upvotes: 1

Related Questions