On 3/15/20 5:28 PM, Simen Kjærås wrote:
...
Since toStringImpl will always call toStringBase, this could perhaps better be modeled with a template mixin:

mixin template DerivedToString() {
     override string toStringImpl() {
         return this.toStringBase();
     }
}

class Derived2 : Base {
     mixin DerivedToString!();
}

This way, you can have all the logic of toString in the base class, and the only thing a subclass will have to include is one line for the mixin. In addition, since toStringImpl is abstract, the implementer of a subclass will get a compile-time error if he or she forgets to do either the mixin or override toStringImpl themselves.

--
   Simen

Thanks to you and Basile for responses and distinct solutions to consider. I am working on the mixin approach now, but with a brief mixinline in each derived subclass, I do not even need to call a superclass method -- just write the display code once with UDA filtering. I think this is the most sensible approach, until something else unexpected comes up :)

Reply via email to