www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - private with module name support

reply Newbie2019 <newbie2019 gmail.com> writes:
When init a projects, or design encapsulation  type. It is 
frequently feed need to made some target only accept by one 
special module(not package but only module).

With current solution, I has to use package(Player) , this is not 
perfect because people can modify package name to made the 
resource accessible.  This is also not work well for a package.d 
module(not able to access from same folder).

the code look like this:

=======================
module PlayerImplement;

private(Player) void doSomeThing(){

}

=======================
module Player;
import PlayerImplement;
void doKill(){
        doSomeThing();
}

=======================

Is this make any sense ?
Aug 08 2019
parent reply Newbie2019 <newbie2019 gmail.com> writes:
On Friday, 9 August 2019 at 01:17:28 UTC, Newbie2019 wrote:
 Is this make any sense ?
The app init function basic only call once, and call from the app entry pointer, do so can avoid other module unexpected call component init function(right now I guard it with a global inited var). I know class inheritance also can do the trick, but class has extra cost so not suit for simple case.
Aug 08 2019
parent reply 12345swordy <alexanderheistermann gmail.com> writes:
On Friday, 9 August 2019 at 01:24:30 UTC, Newbie2019 wrote:
 On Friday, 9 August 2019 at 01:17:28 UTC, Newbie2019 wrote:
 Is this make any sense ?
The app init function basic only call once, and call from the app entry pointer, do so can avoid other module unexpected call component init function(right now I guard it with a global inited var). I know class inheritance also can do the trick, but class has extra cost so not suit for simple case.
Are you trying to implement the functionality as if it were C? Look into .di files.
Aug 08 2019
parent Newbie2019 <newbie2019 gmail.com> writes:
On Friday, 9 August 2019 at 01:40:01 UTC, 12345swordy wrote:
 Are you trying to implement the functionality as if it were C? 
 Look into .di files.
di file will not solve the problem, and in most case the public interface(or api) and implement part in same package, use di make no sense. This new feature allow to split complex source code from one file into multi, without losing the type protection from outside.
Aug 08 2019