Search code examples
eiffel

Alias and multiple names for attributes


Defining various names for a same feature seems possible in Eiffel, what for the attributes?

Is it possible to name an attribute like:

background, bk: COLOR
foreground, fg: COLOR

If not why?


Solution

  • In Eiffel background, bk: COLOR

    is the same as

    background: COLOR
    bk: COLOR
    

    (same convention for local variables, arguments, ...)

    To have a kind of alias on an attribute, you may do

    background: COLOR assign set_background
    bk: COLOR assign set_background
       do
          Result := background
       end
    set_background (c: COLOR)
       do
           background := c
       end
    

    Side note: for function and procedure ... even if it looks an alias

    foo, bar: STRING 
      do 
        Result := "abc" 
      end
    

    In fact, bar is not an alias for foo, they are two different features. In descendant, you can rename, redefine one or the other independently.

    There is no notion of such alias name in Eiffel. The only concept of alias is used to have operator such as plus alias "+" (s: READABLE_STRING_GENERAL): like Current in class STRING_32 . Or also in HASH_TABLE item alias "[]"