Adding Properties2:56 with Alena Holligan
We call the variables inside a class, properties. Properties can accept values like strings, integers, and booleans (true/false values), like any other variable. We demonstrate how to use properties by adding an array for the recipe ingredients.
Variables within a class are called properties.
The naming convention for properties is camelCase, like a camel, the “humps” are in the middle. The name starts with a lowercase letter, and all other words, start with a capital letter. For example, $ingredients or $dryIngredients.
Access modifiers allows us to control the access, or visibility, of our properties. These access modifiers are public, private, or protected. If declared using var, the property will be defined as public. When declaring a property, the visibility MUST be defined by an access modifier.
Public: Publicly accessible from anywhere, even from outside the scope of the class.
Private: Accessed within the class itself. It protects properties and methods from being accessed from outside the class.
Protected: Same as private, except by allowing child (sub) classes to access protected parent (super) properties and methods.
You need to sign up for Treehouse in order to download course files.Sign up