Extension Visibility
In this chapter, you did not declare any of your extensions with a visibility modifier, so they are implicitly public. Public extensions are accessible from anywhere in your codebase. At scale, you may find that the classes you extend can become bloated with the number of new functions and properties you have added.
You can avoid this by opting for a regular function rather than an extension, but there are a lot of situations where extensions do a better job of simplifying your code. Another option to prevent extension bloat is to add visibility modifiers to your extensions – much like you can do with regular functions and properties.
Marking an extension as private prohibits use of the extension outside the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access