<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://debianws.lexgopc.com/wiki143/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=207.237.255.178</id>
	<title>wiki143 - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://debianws.lexgopc.com/wiki143/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=207.237.255.178"/>
	<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Special:Contributions/207.237.255.178"/>
	<updated>2026-10-24T11:36:10Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Property_(programming)&amp;diff=3172762</id>
		<title>Property (programming)</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Property_(programming)&amp;diff=3172762"/>
		<updated>2025-01-24T17:45:56Z</updated>

		<summary type="html">&lt;p&gt;207.237.255.178: This appears to be a spam edit from https://en.wikipedia.org/w/index.php?title=Property_%28programming%29&amp;amp;diff=prev&amp;amp;oldid=1078510302.  Reverting it.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{short description|Sort of class member in programming languages}}&lt;br /&gt;
{{more citations needed|date=January 2022}}&lt;br /&gt;
A &#039;&#039;&#039;property&#039;&#039;&#039;, in some [[object-oriented programming|object-oriented]] [[programming language]]s, is a special sort of [[Class (computer science)|class]] member, intermediate in functionality between a [[field (computer science)|field]] (or data member) and a [[method (computer science)|method]]. The syntax for reading and writing of properties is like for fields, but property reads and writes are (usually) translated to &#039;[[accessor method|getter]]&#039; and &#039;[[mutator method|setter]]&#039; method calls. The field-like syntax is easier to read and write than many method calls,{{citation needed|date=March 2020}} yet the interposition of method calls &amp;quot;under the hood&amp;quot; allows for [[data validation]], [[active updating]] (e.g., of [[GUI]] elements), or implementation of what may be called &amp;quot;[[wikt:read-only|read-only]] fields&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Support in languages ==&lt;br /&gt;
&lt;br /&gt;
Programming languages that support properties include [[ActionScript 3]], [[C Sharp (programming language)|C#]], [[D (programming language)|D]], [[Object Pascal|Delphi]]/[[Free Pascal]], eC, [[F Sharp (programming language)|F#]], [[Kotlin (programming language)|Kotlin]], [[JavaScript]], [[Objective-C#Objective-C 2.0|Objective-C 2.0]], [[Python (programming language)|Python]], [[Scala (programming language)|Scala]], [[Swift (programming language)|Swift]], [[Lua (programming language)|Lua]], and [[Visual Basic]].&lt;br /&gt;
&lt;br /&gt;
Some object-oriented languages, such as [[Java (programming language)|Java]] and [[C++]], do not support properties, requiring the programmer to define a pair of &#039;&#039;[[accessor method|accessor]]&#039;&#039; and &#039;&#039;[[mutator method|mutator]]&#039;&#039; methods instead.&amp;lt;ref&amp;gt;{{cite web |title=Accessors And Mutators In Java |url=https://www.c-sharpcorner.com/UploadFile/3614a6/accessors-and-mutators-in-java/ |website=C# Corner - Community of Software and Data Developers |access-date=5 January 2022}}&amp;lt;/ref&amp;gt;{{citation needed|date=March 2020}}&lt;br /&gt;
&lt;br /&gt;
[[Oberon-2]] provides an alternative mechanism using object variable visibility flags.{{citation needed|date=March 2020}}&lt;br /&gt;
&lt;br /&gt;
Other languages designed for the [[Java virtual machine|Java Virtual Machine]], such as [[Groovy (programming language)|Groovy]], natively support properties.&lt;br /&gt;
&lt;br /&gt;
While [[C++]] does not have first class properties, they can be emulated with [[operator overloading]].&amp;lt;ref&amp;gt;{{cite web |title=Portability of Native C++ properties |url=https://stackoverflow.com/questions/5772480/portability-of-native-c-properties |website=Stack Overflow |publisher=Stack Overflow |access-date=5 January 2022}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also note that some C++ compilers support first class properties as language extensions.{{citation needed|date=March 2020}}&lt;br /&gt;
* In [[Microsoft Visual Studio]],&amp;lt;ref&amp;gt;{{cite web |title=property (C++) |url=https://docs.microsoft.com/en-us/cpp/cpp/property-cpp?view=msvc-170 |website=Microsoft technical documentation |publisher=Microsoft |access-date=5 January 2022 |ref=21 November 2021}}&amp;lt;/ref&amp;gt; [[GNU Compiler Collection|GCC]], and [[LLVM|llvm/clang]],&amp;lt;ref&amp;gt;{{cite web |title=clang::MSPropertyDecl Class Reference |url=https://clang.llvm.org/doxygen/classclang_1_1MSPropertyDecl.html |website=Clang: a C language family frontend for LLVM |access-date=5 January 2022}}&amp;lt;/ref&amp;gt; the &#039;&#039;&#039;&amp;lt;code&amp;gt;__declspec(property)&amp;lt;/code&amp;gt;&#039;&#039;&#039; creates properties similar to [[C Sharp (programming language)|C#]].&lt;br /&gt;
* [[Borland C++]] and [[C++Builder|Borland/CodeGear/Embarcadero C++Builder]] use the &#039;&#039;&#039;&amp;lt;code&amp;gt;__property&amp;lt;/code&amp;gt;&#039;&#039;&#039; keyword.&amp;lt;ref&amp;gt;{{cite web |title=__property Keyword Extension |url=https://docwiki.embarcadero.com/RADStudio/Sydney/en/Property |website=Embarcadero/IDERA Documentation Wiki |access-date=5 January 2022}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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. Omitting a method from the pair yields a &#039;&#039;read-only&#039;&#039; or an uncommon &#039;&#039;write-only&#039;&#039; property.&lt;br /&gt;
&lt;br /&gt;
In some languages with no built-in support for properties, a similar construct can be implemented as a single method that either returns or changes the underlying data, depending on the context of its invocation. Such techniques are used e.g. in [[Perl]]. {{citation needed|date=March 2020}}&lt;br /&gt;
&lt;br /&gt;
Some languages ([[Ruby (programming language)|Ruby]], [[Smalltalk]]) achieve property-like syntax using normal methods, sometimes with a limited amount of [[syntactic sugar]].&lt;br /&gt;
&lt;br /&gt;
== Syntax variants ==&lt;br /&gt;
&lt;br /&gt;
Some languages follow well-established syntax conventions for formally specifying and utilizing properties and methods.&lt;br /&gt;
&lt;br /&gt;
Among these conventions:&lt;br /&gt;
&lt;br /&gt;
* Dot notation&lt;br /&gt;
* Bracket notation&lt;br /&gt;
&lt;br /&gt;
=== Dot notation ===&lt;br /&gt;
&lt;br /&gt;
The following example demonstrates dot notation in JavaScript.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=JavaScript&amp;gt;&lt;br /&gt;
document.createElement(&#039;pre&#039;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Bracket notation ===&lt;br /&gt;
&lt;br /&gt;
The following example demonstrates bracket notation in JavaScript.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=JavaScript&amp;gt;&lt;br /&gt;
document[&#039;createElement&#039;](&#039;pre&#039;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example syntax ==&lt;br /&gt;
&lt;br /&gt;
=== C# ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
class Pen &lt;br /&gt;
{&lt;br /&gt;
    private int color; // private field&lt;br /&gt;
    &lt;br /&gt;
    // public property&lt;br /&gt;
    public int Color &lt;br /&gt;
    {  &lt;br /&gt;
        get&lt;br /&gt;
        {&lt;br /&gt;
            return this.color;&lt;br /&gt;
        }&lt;br /&gt;
        set &lt;br /&gt;
        {&lt;br /&gt;
            if (value &amp;gt; 0) {&lt;br /&gt;
                this.color = value;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
// accessing:&lt;br /&gt;
Pen pen = new Pen();&lt;br /&gt;
int color_tmp = 0;&lt;br /&gt;
// ...&lt;br /&gt;
pen.Color = 17;&lt;br /&gt;
color_tmp = pen.Color;&lt;br /&gt;
// ...&lt;br /&gt;
pen.Color = ~pen.Color; // bitwise complement ...&lt;br /&gt;
&lt;br /&gt;
// another silly example:&lt;br /&gt;
pen.Color += 1; // a lot clearer than &amp;quot;pen.set_Color(pen.get_Color() + 1)&amp;quot;!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Recent C# versions also allow &amp;quot;auto-implemented properties&amp;quot; where the backing field for the property is generated by the compiler during compilation. This means that the property must have a setter. However, it can be private.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
class Shape &lt;br /&gt;
{&lt;br /&gt;
    public int Height { get; set; }&lt;br /&gt;
    public int Width { get; private set; }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== C++ ===&lt;br /&gt;
{{unreferenced section|date=October 2016}}&lt;br /&gt;
{{confusing|date=October 2016}}&lt;br /&gt;
[[C++]] does not have first class properties, but there exist several ways to emulate properties to a limited degree. Two of which follow:&lt;br /&gt;
&lt;br /&gt;
==== Using Standard C++ ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
template &amp;lt;typename T&amp;gt; class property {&lt;br /&gt;
        T value;&lt;br /&gt;
    public:&lt;br /&gt;
        T &amp;amp; operator = (const T &amp;amp;i) {&lt;br /&gt;
            return value = i;&lt;br /&gt;
        }&lt;br /&gt;
        // This template class member function template serves the purpose to make&lt;br /&gt;
        // typing more strict. Assignment to this is only possible with exact identical types.&lt;br /&gt;
        // The reason why it will cause an error is temporary variable created while implicit type conversion in reference initialization.&lt;br /&gt;
        template &amp;lt;typename T2&amp;gt; T2 &amp;amp; operator = (const T2 &amp;amp;i) {&lt;br /&gt;
            T2 &amp;amp;guard = value;&lt;br /&gt;
            throw guard; // Never reached.&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        // Implicit conversion back to T. &lt;br /&gt;
        operator T const &amp;amp; () const {&lt;br /&gt;
            return value;&lt;br /&gt;
        }&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
struct Foo {&lt;br /&gt;
    // Properties using unnamed classes.&lt;br /&gt;
    class {&lt;br /&gt;
            int value;&lt;br /&gt;
        public:&lt;br /&gt;
            int &amp;amp; operator = (const int &amp;amp;i) { return value = i; }&lt;br /&gt;
            operator int () const { return value; }&lt;br /&gt;
    } alpha;&lt;br /&gt;
&lt;br /&gt;
    class {&lt;br /&gt;
            float value;&lt;br /&gt;
        public:&lt;br /&gt;
            float &amp;amp; operator = (const float &amp;amp;f) { return value = f; }&lt;br /&gt;
            operator float () const { return value; }&lt;br /&gt;
    } bravo;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
struct Bar {&lt;br /&gt;
    // Using the property&amp;lt;&amp;gt;-template.&lt;br /&gt;
    property &amp;lt;bool&amp;gt; alpha;&lt;br /&gt;
    property &amp;lt;unsigned int&amp;gt; bravo;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
int main () {&lt;br /&gt;
    Foo foo;&lt;br /&gt;
    foo.alpha = 5;&lt;br /&gt;
    foo.bravo = 5.132f;&lt;br /&gt;
&lt;br /&gt;
    Bar bar;&lt;br /&gt;
    bar.alpha = true;&lt;br /&gt;
    bar.bravo = true; // This line will yield a compile time error&lt;br /&gt;
                      // due to the guard template member function.&lt;br /&gt;
    ::std::cout &amp;lt;&amp;lt; foo.alpha &amp;lt;&amp;lt; &amp;quot;, &amp;quot;&lt;br /&gt;
                &amp;lt;&amp;lt; foo.bravo &amp;lt;&amp;lt; &amp;quot;, &amp;quot;&lt;br /&gt;
                &amp;lt;&amp;lt; bar.alpha &amp;lt;&amp;lt; &amp;quot;, &amp;quot;&lt;br /&gt;
                &amp;lt;&amp;lt; bar.bravo&lt;br /&gt;
                &amp;lt;&amp;lt; ::std::endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Also see [https://stackoverflow.com/a/5924594 Stack Overflow] for a more detailed example.&lt;br /&gt;
&lt;br /&gt;
==== C++, Microsoft, GCC, LLVM/clang and C++Builder-specific ====&lt;br /&gt;
&lt;br /&gt;
An example taken from the MSDN [http://msdn.microsoft.com/en-us/library/yhfk0thd.aspx documentation page].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// declspec_property.cpp&lt;br /&gt;
struct S&lt;br /&gt;
{&lt;br /&gt;
   int i;&lt;br /&gt;
   void putprop(int j)&lt;br /&gt;
   { &lt;br /&gt;
      i = j;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   int getprop()&lt;br /&gt;
   {&lt;br /&gt;
      return i;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   __declspec(property(get = getprop, put = putprop)) int the_prop;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   S s;&lt;br /&gt;
   s.the_prop = 5;&lt;br /&gt;
   return s.the_prop;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== D ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;d&amp;quot;&amp;gt;&lt;br /&gt;
class Pen&lt;br /&gt;
{&lt;br /&gt;
    private int m_color; // private field&lt;br /&gt;
    &lt;br /&gt;
    // public get property&lt;br /&gt;
    public int color () {&lt;br /&gt;
        return m_color;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    // public set property&lt;br /&gt;
    public void color (int value) {&lt;br /&gt;
         m_color = value;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;d&amp;quot;&amp;gt;&lt;br /&gt;
auto pen = new Pen;&lt;br /&gt;
pen.color = ~pen.color; // bitwise complement&lt;br /&gt;
&lt;br /&gt;
// the set property can also be used in expressions, just like regular assignment&lt;br /&gt;
int theColor = (pen.color = 0xFF0000);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In D version 2, each property accessor or mutator must be marked with @property:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;d&amp;quot;&amp;gt;&lt;br /&gt;
class Pen&lt;br /&gt;
{&lt;br /&gt;
    private int m_color; // private field&lt;br /&gt;
    &lt;br /&gt;
    // public get property&lt;br /&gt;
    @property public int color () {&lt;br /&gt;
        return m_color;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    // public set property&lt;br /&gt;
    @property public void color (int value) {&lt;br /&gt;
        m_color = value;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Delphi/Free Pascal ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;delphi&amp;quot;&amp;gt;&lt;br /&gt;
type TPen = class&lt;br /&gt;
  private&lt;br /&gt;
    FColor: TColor;&lt;br /&gt;
    function GetColor: TColor;&lt;br /&gt;
    procedure SetColor(const AValue: TColor);&lt;br /&gt;
  public&lt;br /&gt;
    property Color: Integer read GetColor write SetColor;&lt;br /&gt;
end;&lt;br /&gt;
&lt;br /&gt;
function TPen.GetColor: TColor;&lt;br /&gt;
begin&lt;br /&gt;
  Result := FColor;&lt;br /&gt;
end;&lt;br /&gt;
&lt;br /&gt;
procedure TPen.SetColor(const AValue: TColor);&lt;br /&gt;
begin&lt;br /&gt;
  if FColor &amp;lt;&amp;gt; AValue&lt;br /&gt;
   then FColor := AValue;&lt;br /&gt;
end;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;delphi&amp;quot;&amp;gt;&lt;br /&gt;
// accessing:&lt;br /&gt;
var Pen: TPen;&lt;br /&gt;
// ...&lt;br /&gt;
Pen.Color := not Pen.Color;&lt;br /&gt;
&lt;br /&gt;
(*&lt;br /&gt;
Delphi and Free Pascal also support a &#039;direct field&#039; syntax -&lt;br /&gt;
&lt;br /&gt;
property Color: TColor read FColor write SetColor;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
property Color: TColor read GetColor write FColor;&lt;br /&gt;
&lt;br /&gt;
where the compiler generates the exact same code as for reading and writing&lt;br /&gt;
a field. This offers the efficiency of a field, with the safety of a property.&lt;br /&gt;
(You can&#039;t get a pointer to the property, and you can always replace the member&lt;br /&gt;
access with a method call.)&lt;br /&gt;
*)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== eC ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ec&amp;quot;&amp;gt;&lt;br /&gt;
class Pen &lt;br /&gt;
{&lt;br /&gt;
   // private data member&lt;br /&gt;
   Color color;&lt;br /&gt;
public:&lt;br /&gt;
   // public property&lt;br /&gt;
   property Color color &lt;br /&gt;
   {  &lt;br /&gt;
      get { return color; }&lt;br /&gt;
      set { color = value; }&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
Pen blackPen { color = black };&lt;br /&gt;
Pen whitePen { color = white };&lt;br /&gt;
Pen pen3 { color = { 30, 80, 120 } };&lt;br /&gt;
Pen pen4 { color = ColorHSV { 90, 20, 40 } };&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== F# ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fsharp&amp;quot;&amp;gt;&lt;br /&gt;
type Pen() = class&lt;br /&gt;
    let mutable _color = 0&lt;br /&gt;
&lt;br /&gt;
    member this.Color&lt;br /&gt;
        with get() = _color&lt;br /&gt;
        and set value = _color &amp;lt;- value&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fsharp&amp;quot;&amp;gt;&lt;br /&gt;
let pen = new Pen()&lt;br /&gt;
pen.Color &amp;lt;- ~~~pen.Color&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== JavaScript ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
function Pen() {&lt;br /&gt;
    this._color = 0;&lt;br /&gt;
}&lt;br /&gt;
// Add the property to the Pen type itself, can also&lt;br /&gt;
// be set on the instance individually&lt;br /&gt;
Object.defineProperties(Pen.prototype, {&lt;br /&gt;
    color: {&lt;br /&gt;
        get: function () {&lt;br /&gt;
            return this._color;&lt;br /&gt;
        },&lt;br /&gt;
        set: function (value) {&lt;br /&gt;
            this._color = value;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var pen = new Pen();&lt;br /&gt;
pen.color = ~pen.color; // bitwise complement&lt;br /&gt;
pen.color += 1; // Add one&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ActionScript 3.0 ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;actionscript3&amp;quot;&amp;gt;&lt;br /&gt;
package {&lt;br /&gt;
	public class Pen {&lt;br /&gt;
		private var _color:uint = 0;&lt;br /&gt;
		&lt;br /&gt;
		public function get color ():uint {&lt;br /&gt;
			return _color;&lt;br /&gt;
		}&lt;br /&gt;
		&lt;br /&gt;
		public function set color(value:uint):void {&lt;br /&gt;
			_color = value;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;actionscript3&amp;quot;&amp;gt;&lt;br /&gt;
var pen:Pen = new Pen();&lt;br /&gt;
pen.color = ~pen.color; // bitwise complement&lt;br /&gt;
pen.color += 1; // add one&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Objective-C 2.0 ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;objc&amp;quot;&amp;gt;&lt;br /&gt;
@interface Pen : NSObject&lt;br /&gt;
@property (copy) NSColor *colour;	// The &amp;quot;copy&amp;quot; attribute causes the object&#039;s copy to be&lt;br /&gt;
					// retained, instead of the original.&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
@implementation Pen&lt;br /&gt;
@synthesize colour;			// Compiler directive to synthesise accessor methods.&lt;br /&gt;
					// It can be left behind in Xcode 4.5 and later.&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above example could be used in an arbitrary method like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;objc&amp;quot;&amp;gt;&lt;br /&gt;
Pen *pen = [[Pen alloc] init];&lt;br /&gt;
pen.colour = [NSColor blackColor];&lt;br /&gt;
float red = pen.colour.redComponent;&lt;br /&gt;
[pen.colour drawSwatchInRect: NSMakeRect(0, 0, 100, 100)];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PHP ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
class Pen&lt;br /&gt;
{&lt;br /&gt;
    private int $color = 1;&lt;br /&gt;
&lt;br /&gt;
    function __set($property, $value)&lt;br /&gt;
    {&lt;br /&gt;
        if (property_exists($this, $property)) { &lt;br /&gt;
            $this-&amp;gt;$property = $value;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    function __get($property)&lt;br /&gt;
    {&lt;br /&gt;
        if (property_exists($this, $property)) {&lt;br /&gt;
            return $this-&amp;gt;$property;&lt;br /&gt;
        }&lt;br /&gt;
        return null;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$p = new Pen();&lt;br /&gt;
$p-&amp;gt;color = ~$p-&amp;gt;color; // Bitwise complement&lt;br /&gt;
echo $p-&amp;gt;color;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python ===&lt;br /&gt;
&lt;br /&gt;
Properties only work correctly for new-style classes (classes that have &amp;lt;code&amp;gt;object&amp;lt;/code&amp;gt; as a [[Superclass (computer science)|superclass]]), and are only available in Python 2.2 and newer (see [https://www.python.org/download/releases/2.2/descrintro/#property the relevant section of the tutorial &#039;&#039;Unifying types and classes in Python 2.2&#039;&#039;]). Python 2.6 added a new syntax involving decorators for defining properties.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
class Pen:&lt;br /&gt;
    def __init__(self) -&amp;gt; None:&lt;br /&gt;
        self._color = 0  # &amp;quot;private&amp;quot; variable&lt;br /&gt;
&lt;br /&gt;
    @property&lt;br /&gt;
    def color(self):&lt;br /&gt;
        return self._color&lt;br /&gt;
&lt;br /&gt;
    @color.setter&lt;br /&gt;
    def color(self, color):&lt;br /&gt;
        self._color = color&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
pen = Pen()&lt;br /&gt;
# Accessing:&lt;br /&gt;
pen.color = ~pen.color  # Bitwise complement ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Ruby ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
class Pen&lt;br /&gt;
  def initialize&lt;br /&gt;
    @color = 0&lt;br /&gt;
  end&lt;br /&gt;
    &lt;br /&gt;
  # Defines a getter for the @color field&lt;br /&gt;
  def color&lt;br /&gt;
    @color&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Defines a setter for the @color field&lt;br /&gt;
  def color=(value)&lt;br /&gt;
    @color = value&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
pen = Pen.new&lt;br /&gt;
pen.color = ~pen.color    # Bitwise complement&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ruby also provides automatic getter/setter synthesizers defined as instance methods of Class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
class Pen&lt;br /&gt;
  attr_reader :brand    # Generates a getter for @brand (Read-Only)&lt;br /&gt;
  attr_writer :size     # Generates a setter for @size  (Write-Only)&lt;br /&gt;
  attr_accessor :color  # Generates both a getter and setter for @color (Read/Write)&lt;br /&gt;
&lt;br /&gt;
  def initialize&lt;br /&gt;
    @color = 0          # Within the object, we can access the instance variable directly&lt;br /&gt;
    @brand = &amp;quot;Penbrand&amp;quot;&lt;br /&gt;
    @size = 0.7         # But we could also use the setter method defined by the attr_accessor Class instance method&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
pen = Pen.new&lt;br /&gt;
puts pen.brand           # Accesses the pen brand through the generated getter&lt;br /&gt;
pen.size = 0.5           # Updates the size field of the pen through the generated setter&lt;br /&gt;
pen.color = ~pen.color   &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Visual Basic ===&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic (.NET 2003–2010) ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vbnet&amp;quot;&amp;gt;&lt;br /&gt;
Public Class Pen&lt;br /&gt;
 &lt;br /&gt;
    Private _color As Integer &#039; Private field&lt;br /&gt;
&lt;br /&gt;
    Public Property Color() As Integer &#039; Public property&lt;br /&gt;
        Get&lt;br /&gt;
            Return _color&lt;br /&gt;
        End Get&lt;br /&gt;
        Set(ByVal value As Integer)&lt;br /&gt;
            _color = value&lt;br /&gt;
        End Set&lt;br /&gt;
    End Property&lt;br /&gt;
&lt;br /&gt;
End Class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vbnet&amp;quot;&amp;gt;&lt;br /&gt;
&#039; Create Pen class instance&lt;br /&gt;
Dim pen As New Pen()&lt;br /&gt;
&lt;br /&gt;
&#039; Set value&lt;br /&gt;
pen.Color = 1&lt;br /&gt;
&lt;br /&gt;
&#039; Get value&lt;br /&gt;
Dim color As Int32 = pen.Color&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic (only .NET 2010) ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vbnet&amp;quot;&amp;gt;&lt;br /&gt;
Public Class Pen&lt;br /&gt;
&lt;br /&gt;
    Public Property Color() As Integer &#039; Public property&lt;br /&gt;
&lt;br /&gt;
End Class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vbnet&amp;quot;&amp;gt;&lt;br /&gt;
&#039; Create Pen class instance&lt;br /&gt;
Dim pen As New Pen()&lt;br /&gt;
&lt;br /&gt;
&#039; Set value&lt;br /&gt;
pen.Color = 1&lt;br /&gt;
&lt;br /&gt;
&#039; Get value&lt;br /&gt;
Dim color As Int32 = pen.Color&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Visual Basic 6 ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vbnet&amp;quot;&amp;gt;&lt;br /&gt;
&#039; in a class named clsPen&lt;br /&gt;
Private m_Color As Long&lt;br /&gt;
&lt;br /&gt;
Public Property Get Color() As Long&lt;br /&gt;
    Color = m_Color&lt;br /&gt;
End Property&lt;br /&gt;
&lt;br /&gt;
Public Property Let Color(ByVal RHS As Long)&lt;br /&gt;
    m_Color = RHS&lt;br /&gt;
End Property&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vbnet&amp;quot;&amp;gt;&lt;br /&gt;
&#039; accessing:&lt;br /&gt;
Dim pen As New clsPen&lt;br /&gt;
&#039; ...&lt;br /&gt;
pen.Color = Not pen.Color&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Attribute (computing)]]&lt;br /&gt;
* [[Bound property]]&lt;br /&gt;
* [[Field (computer science)]]&lt;br /&gt;
* [[Indexer (programming)]]&lt;br /&gt;
* [[Method (computer programming)]]&lt;br /&gt;
* [[Mutator method]]&lt;br /&gt;
* [[Uniform access principle]]&lt;br /&gt;
&lt;br /&gt;
{{Authority control}}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
{{DEFAULTSORT:Property (Programming)}}&lt;br /&gt;
&amp;lt;!--Categories--&amp;gt;&lt;br /&gt;
[[Category:Object-oriented programming]]&lt;br /&gt;
[[Category:Articles with example C Sharp code]]&lt;br /&gt;
[[Category:Articles with example C++ code]]&lt;br /&gt;
[[Category:Articles with example D code]]&lt;br /&gt;
[[Category:Articles with example JavaScript code]]&lt;br /&gt;
[[Category:Articles with example PHP code]]&lt;br /&gt;
[[Category:Articles with example Python (programming language) code]]&lt;br /&gt;
[[Category:Articles with example Ruby code]]&lt;/div&gt;</summary>
		<author><name>207.237.255.178</name></author>
	</entry>
</feed>