See all glossary terms

Private/Public Properties

In large organizations, Encapsulation is necessary. It allows different teams to work on different parts of the codebase without needing to know how the other parts work internally, as long as they know how to interact with them.
Each team is free to work on their parts of the code in any way they want, as long as all teams agree on how the external Interface should look.
In some languages, this can be enforced at a language level, by marking properties as private or public. A private property is only accessible from within the script it is defined in, while a public property can be accessed from other scripts. Some languages also have protected properties, which are only accessible from subclasses.
In GDScript, there's no private or public keyword. Instead, GDScript uses a convention to mark properties as private or public. A property is considered private if its name starts with an underscore (_). This is called pseudo-private. It's a convention, not a language feature, so it's up to the programmer to respect it.