Simulating sub types

JS js.mdnq at gmail.com
Fri Aug 2 04:02:47 PDT 2013


Nesting classes is strange to me in Dlang because it adds a 
parent pointer to the parent class. I don't see the point of this 
and it seems like an anti-feature. If we wanting that pattern we 
could implement it ourselves. I suppose in some cases it can be 
useful but in my case it breaks logical nesting.

I have two classes A and B. I want B to look like it is derived 
or a member of A.

So I want to do A.B when accessing B to explicitly signal that B 
is from A.

e.g.,

class A { class B { ...

BUT I do not want class B to be physically connecting to A. I 
would like to instantiate it outside of A. I can't do this in 
Dlang. Regardless of why I want to do this, the fact remains that 
I can't do it in Dlang. So, the question is, how can I still get 
the logical behavior? I've tried to put B in a module A, but this 
doesn't seem to work.


In fact, I'm programming from interfaces,

interface A { interface B { ...

class C : A { class D : A.B { ...

So I have for D, analogous to A.B, C.D.

D will never be used, I think outside of D, except when 
inheriting from D to create polymorphic behavior... direct 
injection will be used along with factories and requiring D to be 
a physical child of D will just be a pain in the ass(requiring 
all of C to be implemented I think).

Basically, D will never access the parent(they are just wrappers 
around tight objects. So I don't need the parent pointer, yet I'm 
forced to do so.






More information about the Digitalmars-d-learn mailing list