简体   繁体   English

是否在类名前加下划线是确保类在库外部不可用的正确方法?

[英]Is prefacing a class name with underscore the correct way to ensure a class is not usable outside a library?

If I have a helper class defined in a library that I don't want utilized outside of the library, is the correct hiding mechanism to place an underscore in front of the class name? 如果我在库中定义了一个我不想在库外使用的帮助器类,那么在类名前面放置下划线的正确隐藏机制是否正确?

part of foo;

class Bar { } // made available to users of the foo library

class _BarHelp { } // hidden from users of the foo library

Or is there an alternate way of hiding BarHelp ? 还是有隐藏BarHelp的另一种方法?

是的,下划线适用于与函数,方法和字段相同的类名,这使它们成为库私有的。

Yes. 是。 this is correct way and there is no better way to do this in Google Dart language. 这是正确的方法,没有更好的方法可以使用Google Dart语言做到这一点。
It is also the only possible way to use the privacy (does not provided other levels of privacy). 这也是使用隐私的唯一可能方法(未提供其他级别的隐私)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM