C++ frequently questioned answers

Nathan Reed nathaniel.reed at gmail.com
Mon Oct 29 00:07:28 PDT 2007


TomD wrote:
> But I wonder if the following is also true for D:
*snip*

I believe it is.  If you take a look at .di files generated by DMD you 
will see they contain all of a class's instance variables (public and 
private).  They also contain implementations of certain methods and 
constructors (usually short ones), presumably for inlining.

While it does violate encapsulation to some extent (ideally, I shouldn't 
have to know how big a class is to create an instance of it, and I 
shouldn't need to recompile client code if I add an instance variable) 
the amount of harm done is small IMHO, and allowing inlining of small 
class methods (and constructors) is well worth it.

Also, in case someone wants to truly hide the implementation, it's 
always possible to make an interface of all the public functions, and a 
factory function for creating instances, and put the actual 
implementation class in another module.

Thanks,
Nathan Reed



More information about the Digitalmars-d mailing list