Partial classes
Walter Bright
newshound2 at digitalmars.com
Mon Jun 25 13:30:25 PDT 2012
On 6/25/2012 8:26 AM, Manu wrote:
> I suspect this isn't possible in a compiled language like D, but I wonder
> anyway, has anyone considered partial classes in D? Are they technically possible?
> How would they work? Would it depend on link-time code generation?
> I can imagine an implementation where each 'part' occupies a separate
> allocation, and some pointer in Object or somewhere like that (somewhere near
> the typeinfo pointer) binds them together.
Are you talking about adding fields/functions to an arbitrary class without
modifying the original definition of that class?
If so, this would violate principles of encapsulation, and there'd be terrible
consequences (as you could not rely on the class definition being the class
definition without examining the entire code base).
But, you can use UFCS to "add" member functions to an existing class.
Adding data members can be done using the PIMPL technique, string mixins, or
template mixins (but the original class needs to be designed for that).
More information about the Digitalmars-d
mailing list