I was wondering what the reasoning is behind the way libraries and their content are defined. More specifically, a library needs to list all parts and the parts need to stat
You can find some informations in this thread.
From Gilad Bracha :
Originally, parts were not tied to their libraries. People complained because it was difficult to give good tool support (i.e., what scope are you in when you open a part but not a library that uses it?).
I have not seen this specifically addressed anywhere, but I have wondered about this as well, and the conclusion I've come to is that it's a symptom of using library level privacy as opposed to class level privacy.
If a library only needed to list its parts then you could gain access to any library's internal properties simply by declaring it a part:
library hax;
part 'packages/somelib/secret.dart';
I now have access to any private field or method in secret.dart. I can do this with any third-party package I've imported, making the concept of privacy a joke.
Similarly, if only a part of
declaration was required, any file could inject itself into a library by declaring that it was part of that library.
However, by requiring both a part
declaration in the file declaring the library, and a part of
declaration in the file that is to be included in the library, Dart avoids this situation.