aleskva
aleskva

Reputation: 1825

Library written into more files

I found a Dart library, which hasn't got any main lib.dart file with library 'lib'; at the beginning, but which has more files with library 'lib.sublib'; at the beginning. I understand this notation, but I have a question:

What if I want to have no main lib.dart file, but have eg three parts of my library as explained above and additionally I want to have one file, which joins all three sublibs into one for case if the user wants to use all three parts of the library?

What's right? See my two drafts below. Is any of them correct? Or should it be written anyhow else?

Draft I:

//lib.dart
library 'lib';
part 'superlib.dart';
part 'bestlib.dart';

//superlib.dart
part of 'lib';
...

//bestlib.dart
part of 'lib';
...

Draft II:

//lib.dart
library 'lib';
export 'superlib.dart';
export 'bestlib.dart';

//superlib.dart
library 'lib.super';
...

//bestlib.dart
library 'lib.best';
...

Upvotes: 2

Views: 53

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657957

Both attempts are fine.

The first difference is that the parts can access private fields, functions, classes, class members (where the name starts with an underscore _) of each other part because they are in the same library.

The second difference is that the parts can not be imported individually by user if they are in the same library. Just the library itself could be imported.

Upvotes: 2

Related Questions