On Monday, 31 August 2015 at 14:44:27 UTC, jmh530 wrote:
On Monday, 24 August 2015 at 11:10:16 UTC, Dicebot wrote:
Rough summary of the talk I have given for recent Berlin D meetup event:
https://blog.dicebot.lv/posts/2015/08/OOP_composition_with_mixins

It seems like mixin templates can be used like alias this, but mixin templates are more general. When would I want to use alias this instead of a mixin template?

`alias this` is more suitable for cases when reused functionality is self-contained and useful separately. It is closer in spirit to inheritance because you take existing entity and provide its API as part of new aggregate.

As a simple rule of a thumb, I'd go for `alias this` approach when mixed in functionality does not need to know anything about surrounding context (== has no template parameters). mixin template feels more convenient for small configurable building blocks that don't have well-defined semantics without any specific context.

Important difference between `alias this` and `mixin` is that `alias this` allows implicit casting to the aliased field type - which can be both merit and drawback depending on design intentions.

Reply via email to