Challenge: solve this multiple inheritance problem in your favorite language

Jacob Carlborg doob at me.com
Fri Jun 5 06:40:06 UTC 2020


On 2020-06-04 19:25, mw wrote:

> Actually, I think it still solvable: by dealing with each attribute from 
> the parent class individually (instead of as a whole), just follow 
> Eiffel's method, adding language mechanism (esp `rename`) to allow 
> programmer to decide how to resolve the conflict.
> 
> I'd imaging something like this:
> 
> ----------------------------------------------------------------------
> class Person : NameI, AddrI {
>    mixin NameT!Person rename equals as name_equals;
>    mixin AddrT!Person rename equals as addr_equals;
> 
>    bool equals(Person other) {
>      return this.name_equals(other) &&
>             this.addr_equlas(other);
>    }
> }
> ----------------------------------------------------------------------

It's already possible to do that today:

class Person : NameI, AddrI {
   mixin NameT!Person Name;
   mixin AddrT!Person Addr;

   bool equals(Person other) {
     return Name.equals(other) &&
            Addr.equals(other);
   }
}

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list