how to achieve C's Token Pasting (##) Operator to generate variable name in D?

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Jun 4 18:42:05 UTC 2020


On Thu, Jun 04, 2020 at 06:09:35PM +0000, mw via Digitalmars-d-learn wrote:
[...]
> ----------------------------------------------------------------------
> 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);
>   }
> }
> ----------------------------------------------------------------------

TBH, whenever I run into a diamond inheritance problem or similar, my
first reaction is, I'm using the wrong tool for modelling my data; I
should be using some kind of component-based system instead of OO
inheritance.

Nowadays I rarely use OO-style inheritance for data modelling anymore;
it's still useful for rare cases where a straight hierarchy makes sense
(traditional GUI widgets, for example, or parse trees), but for complex
modelling I just stop pretending that there's a direct mapping from
problem domain to language constructs, and instead build containers that
have arbitrary component combinations as an infrastructure instead.

Recently I've been dabbling in ECS (entity-component-system) adaptations
from gamedev: the system part is not useful to me, but the idea behind
entity-component storage is very useful for modelling complex data, much
more suitable than traditional OO inheritance IMO.


T

-- 
I am Ohm of Borg. Resistance is voltage over current.


More information about the Digitalmars-d-learn mailing list