New concept Mixin Methods

Adam D Ruppe destructionator at gmail.com
Tue Dec 27 01:15:42 UTC 2022


On Sunday, 25 December 2022 at 15:29:40 UTC, Timon Gehr wrote:
> I don't think it's about saving the typing, it's about not 
> allowing bugs to appear because people _forgot_ to type.

This is exactly true... and it brings to mind an alternate idea: 
require a non-abstract method must be overridden in a child class.

Consider this:

class Dupable {
     __mustOverride("hint message") Dupable dup() { return new 
Dupable(); }
}

class Child : Dupable {
    // if you forgot to override dup, you'd get the wrong type out
    // but since the parent had mustoverride, the compiler will 
tell us
}


error: class Child must override method `Dupable dup`
hint: hint message


Then it prods them in the right direction and the hint message 
can tell them to mixin something.

Destroy.


More information about the Digitalmars-d mailing list