darkwing
darkwing

Reputation: 63

Barrel Files - Understanding their intended use case?

I am designing a feature where my files are organized under many sub folders. I have created an index file per sub folder to export all the relevant files. Is one of the main purposes of the barrel file to hide the structure from parent folders so they never directly point to a specific file? So then each owning folder can use relative paths to point directly to specific files?

Any guidance would be great!

Upvotes: 3

Views: 3135

Answers (1)

Pace
Pace

Reputation: 43867

Is one of the main purposes of the barrel file to hide the structure from parent folders so they never directly point to a specific file?

Yes.

So then each owning folder can use relative paths to point directly to specific files?

Yes. The closer you are to the symbol in question the more you are expected to know about it.

Another reason is that barrels will allow you to control what you export. This will let you have symbols internal to a folder (they never get exported out). It also allows you to hide symbols such as spec files (unit tests) which should never be exported.

Upvotes: 2

Related Questions