Friends in D, the easy way!

Mr.Bingo Bingo at Namo.com
Mon Jun 18 06:37:41 UTC 2018


These go in the module you want allow access to the outside world 
just as if they were in the same module!

auto Setter(string name, alias O, T)(T t)
{
	mixin("t."~name~" = O();");
}

auto ref Getter(string name, T)(T t)
{
	mixin("return t."~name~";");
}



x.Setter!("privateFieldName", { return value; }); // 
privateFieldName = value;
x.Getter!("privateFieldName"); // = privateFieldName


You can think me now... or later, which ever you choose! I hope 
there is no SOLID henchmen here!

Of course, these should be used only between modules that are 
tightly coupled... This can happen when a derived class needs 
access to it's parent as if it were in the same module but the 
modules are split only for parsing.







More information about the Digitalmars-d mailing list