Common · Knowledge
Property (programming)
Type of class member in object-oriented programming which is accessed like a field but implemented as subroutine(s)
A property, in some object-oriented programming languages, is a special sort of class member, intermediate in functionality between a field (or data member) and a method. The syntax for reading and writing of properties is like for fields, but property reads and writes are (usually) translated to 'getter' and 'setter' method calls.
Read more
The field-like syntax is easier to read and write than many method calls, yet the interposition of method calls "under the hood" allows for data validation, active updating (e.g., of graphical user interface (GUI) elements), or implementing what may be called "read-only fields". Programming languages that support properties include C#, D, ECMAScript (ActionScript 3, JavaScript), eC, F#, Kotlin, Object Pascal (Delphi, Free Pascal), Objective-C 2.0, Python, Scala, Swift, Lua, and Visual Basic. Some object-oriented languages, such as Java and C++, do not support properties, requiring the programmer to define a pair of accessor and mutator methods instead. Oberon-2 provides an alternative mechanism using object variable visibility flags. Other languages designed for the Java virtual machine, such as Groovy, support properties natively. While C++ does not have first class properties, they can be emulated with operator overloading. Some C++ compilers support first class properties as language extensions. In many object-oriented languages properties are implemented as a pair of accessor–mutator methods, but accessed using the same syntax as for public fields.
Text: Wikipédia, CC BY-SA 4.0. ·