(Noob question) Should subclasses be defined in separate modules?

thebluepandabear therealbluepandabear at protonmail.com
Fri Jan 13 05:17:59 UTC 2023


(Sorry if this is a duplicate.)

If I have the following code inside of a module:

```D
class Obj {
     private {
         string name = "Hi";
     }
}

class ObjDerived : Obj {

}
```

Is it best practice to define `ObjDerived` inside another module, 
since `ObjDerived` can still access the members of `Obj` (since 
`private` is only applied to modules), or does this go against 
the intended use of the language?

As a beginner, I am having an extremely tough time understanding 
why you would want to place these two classes in the same module 
or even have this intended behavior of `private`. I am coming 
from Java/Kotlin which are both strictly OO language and have 
different ways of encapsulation.




More information about the Digitalmars-d-learn mailing list