Property
PronunciationPROP-er-tee
Definition
A property looks like a plain attribute but runs code when you read or write it, which lets a class validate values or compute them on demand.
Where you hear it
In Python and C# classes, code reviews about validation, and discussions of getters and setters.
Examples
balanceis a read-only property, so callers cannot assign to it.The setter rejects negative ages.
The total property is computed from the line items every time it is read.
Common mistake
Hiding slow work behind a property. People expect reading an attribute to be quick and free of side effects.
Don't confuse with
A method, which you call with parentheses. A property is used without them.
Say it at work
- In a meeting or chat
Turn that getter into a property so callers keep the simple syntax.
- In an email or ticket
Validate it in the setter, not at every call site.
Keep exploring
More in Programming Fundamentals