10 Scope your code with access modifiers

After reading this lesson, you will be able to

  • Make your values, variables, functions, and classes accessible only from their class
  • Limit your code accessibility to a class and its subclasses

In lesson 9, you learned about packages. Protecting your code by limiting its accessibility is a good practice, especially when creating external modules for third parties. By doing so, you also reduce your code’s public entry points, making it easier to use. This approach also prevents external manipulations that could expose sensitive data or introduce undesired behavior in your code. In this lesson, you’ll learn about the Scala access modifiers, which are reserved keywords to change your code elements’ visibility. ...

Get Get Programming with Scala now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.