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

时间:2015-12-14 17:52:50

标签: dart

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 ?

2 个答案:

答案 0 :(得分:1)

Yes, the underscore works for class names the same as functions, methods, and fields, it makes them library-private.

答案 1 :(得分:0)

是。这是正确的方法,没有更好的方法在Google Dart语言中执行此操作 它也是使用隐私的唯一可能方式(不提供其他级别的隐私)。

相关问题