When should we use Modules and when Should we use Classes?

Adam D. Ruppe destructionator at gmail.com
Wed Sep 18 12:50:47 UTC 2019


You can only have one instance of a module, so it is really more 
a collection of types, functions, etc. that help each other do a 
particular job.

Then structs and classes can have multiple objects of each type 
so you use them to do most the stuff you run. You can make class 
objects in a loop or array, you can make temporary ones, 
replacable ones, etc. Modules cannot do any of that.

So in short:

* use a module to group classes and functions
* use a class when you need to subclass it and customize 
functionality and/or need several instances
* use a struct for most other cases, it is a generic collection 
of data


More information about the Digitalmars-d-learn mailing list