<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Hudaiya</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Hudaiya"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Hudaiya"/>
	<updated>2026-10-01T06:41:02Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54718</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54718"/>
		<updated>2011-11-03T03:32:05Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Refactoring support in popular IDE(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; As people make changes to the code to realize their short term goals without fully understanding the design of code, the code loses its structure.  The refactoring work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape. &amp;lt;ref name=&amp;quot;reftwo&amp;quot;&amp;gt; Why should you Refactor http://sourcemaking.com/refactoring/why-should-you-refactor &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Fully autonomous factoring doesn't appear to exist at this time in the IDE(s) described below.  However there are papers &amp;lt;i&amp;gt;Inducing Evolution-Robust Pointcuts&amp;lt;/i&amp;gt; &amp;lt;Ref name=&amp;quot;refseven&amp;quot;&amp;gt;Inducing Evolution-Robust Pointcuts, Braem, M.&amp;lt;/ref&amp;gt; and &amp;lt;i&amp;gt;Automatic Refactoring of Erlang Programs&amp;lt;/i&amp;gt;&amp;lt;ref name=&amp;quot;refeight&amp;quot;&amp;gt;Automatic Refactoring of Erlang Programs http://www.ece.cmu.edu/~aavgerin/papers/PPDP09.pdf&amp;lt;/ref&amp;gt; that point the way to the future of refactoring that can be fully automated.  In the context of this wiki article, automatic refactoring means automated refactoring under programmer control and guidance.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common Refactoring Techniques==&lt;br /&gt;
===Extraction Refactoring=== &lt;br /&gt;
There are several refactoring techniques related to extraction: Extract method, Extract local variables, extract constants. The first method &amp;quot;Extract method will create a new method from code you've selected. Extract Local Variable refactoring takes an expression that is being used repeatedly and assigns it to a local variable. Extract constant refactoring is to select a static, constant expression, which the refactoring will convert to a static final constant. This is useful for removing hard-coded numbers and strings from your code&lt;br /&gt;
&lt;br /&gt;
===Inline Refactoring=== &lt;br /&gt;
This type refactoring is the reverse of local variable extraction, in which we remove a local variable and use the value of the variable(typically an expression) in the place where the variable is used. This can be marginally more efficient than using a temporary variable and, by making the code terser, makes it either easier to read or more cryptic, depending on your point of view&amp;lt;ref name=&amp;quot;refthree&amp;quot;&amp;gt; refactoring for everyone http://www.ibm.com/developerworks/library/os-ecref/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Encapsulating Fields===&lt;br /&gt;
Generally its not a good practice to expose the class attributes through public interface. Thus, Encapsulating such fields will make such fields as private or protected as appropriate and generate getters and setters for the associated field.&lt;br /&gt;
&lt;br /&gt;
===Changing Method Signature===&lt;br /&gt;
Here we change the change the parameters, visibility, and return type of a method.&lt;br /&gt;
&lt;br /&gt;
== Other Refactorings ==&lt;br /&gt;
&lt;br /&gt;
There are a multitude of refactorings.  Those that are included with RubyMine&amp;lt;ref name=&amp;quot;reffour&amp;quot;&amp;gt;RubyMine :: Ruby and Ruby on Rails IDE with smart code completion, syntax highlighting and refactoring http://www.jetbrains.com/ruby/features/ruby_ide.html#Refactorings&amp;lt;/ref&amp;gt; include:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename refactoring&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Method&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Module&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Superclass&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Constant&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Field&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Parameter&lt;br /&gt;
&amp;lt;li&amp;gt;Inline Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Pull Up Members&lt;br /&gt;
&amp;lt;li&amp;gt;Push Down Members&lt;br /&gt;
&amp;lt;li&amp;gt;Override Method&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Martin Fowler has online resources for additional refactoring definitions which can be found here http://martinfowler.com/bliki/refactoring.html&amp;lt;ref name=&amp;quot;reffive&amp;quot;&amp;gt;MF Blicki: refactoring http://martinfowler.com/bliki/refactoring.html&amp;lt;/ref&amp;gt; and here http://refactoring.com/catalog/&amp;lt;ref name=&amp;quot;refsix&amp;quot;&amp;gt;Alpha list of refactorings http://refactoring.com/catalog/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Refactoring support in popular IDE(s)==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;font-size: 90%; text-align: center; width: auto;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! IDE&lt;br /&gt;
! Language(s)&lt;br /&gt;
! Refactoring Support&lt;br /&gt;
! Automated Refactoring?&lt;br /&gt;
! Number of Refactoring support&lt;br /&gt;
! Support for Pattern&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
! Borland Delphi&lt;br /&gt;
! Object Oriented Pascal&lt;br /&gt;
! Rename refactoring, Refactor driven “Find References”, Introduce Variable refactoring, Introduce Field refactoring, Inline Variable refactoring, Change Parameters refactoring, Safe Delete refactoring, Push Members Up / Down refactoring, Pull Members Up refactoring, Extract Superclass refactoring, Extract Interface refactoring, Move Members refactoring, Declare variable refactoring, Declare field refactoring, Extract method refactoring, Find unit/import namespace refactoring, Refactor driven “Find in Files”, Extract to resource string refactoring&amp;lt;ref name=&amp;quot;borlandrefactorings&amp;gt;Leveraging What You Have: 10 Top Things Added to Delphi Since Delphi 7 http://edn.embarcadero.com/article/37416&amp;lt;/ref&amp;gt;&lt;br /&gt;
! Yes&lt;br /&gt;
! 17&lt;br /&gt;
! Declare Variable&amp;lt;ref name=&amp;quot;borlanddecvar&amp;quot;&amp;gt;Increased Productivity with Refactoring, Unit Testing, Help Insight, Error Insight, and Sync Edit in Borland Delphi 2005 http://edn.embarcadero.com/article/33278&amp;lt;/ref&amp;gt;&lt;br /&gt;
!&lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
procedure TWinForm1.btnOpen_Click(sender: System.Object;&lt;br /&gt;
  e: System.EventArgs);&lt;br /&gt;
begin&lt;br /&gt;
  if (OpenFileDialog1.ShowDialog =&lt;br /&gt;
      System.Windows.Forms.DialogResult.OK) then&lt;br /&gt;
  begin&lt;br /&gt;
    Assign(f,OpenFileDialog1.FileName);&lt;br /&gt;
    Reset(f);&lt;br /&gt;
    try&lt;br /&gt;
    finally&lt;br /&gt;
      CloseFile(f);&lt;br /&gt;
    end;&lt;br /&gt;
  end;&lt;br /&gt;
end;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
---- After Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
procedure TWinForm1.btnOpen_Click(sender: System.Object;&lt;br /&gt;
  e: System.EventArgs);&lt;br /&gt;
var&lt;br /&gt;
  f: TextFile;&lt;br /&gt;
begin&lt;br /&gt;
  if (OpenFileDialog1.ShowDialog =&lt;br /&gt;
      System.Windows.Forms.DialogResult.OK) then&lt;br /&gt;
  begin&lt;br /&gt;
    Assign(f,OpenFileDialog1.FileName);&lt;br /&gt;
    Reset(f);&lt;br /&gt;
    try&lt;br /&gt;
    finally&lt;br /&gt;
      CloseFile(f);&lt;br /&gt;
    end;&lt;br /&gt;
  end;&lt;br /&gt;
end;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Eclipse &amp;lt;ref name='refeclipse'&amp;gt;Eclipse Refactoring Actions http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-menu-refactor.htm &amp;lt;/ref&amp;gt;&lt;br /&gt;
! C, C++, Java&lt;br /&gt;
! Rename selected Elements, Move selected elements, Change Method Signature, Extraction, Convert Anonymous Class to Nested, Convert Local Variable to Field, Extract Super class and Interface, push down, pull up, Introduce Indirection, Encapsulate Field, Migrate JAR File, Create &amp;amp; Apply Refatoring Scripts&lt;br /&gt;
! Yes&lt;br /&gt;
! 27&lt;br /&gt;
! Introduce Factory&lt;br /&gt;
! &lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
int x= p * 5; 	&lt;br /&gt;
p.x;&lt;br /&gt;
---- After Refactoring&lt;br /&gt;
int x= getFoo(p); (Method Extraction) &lt;br /&gt;
p.getX() (Encapsulate Field)&lt;br /&gt;
|-&lt;br /&gt;
! Kdevelop&lt;br /&gt;
! C, C++&lt;br /&gt;
! Several&amp;lt;ref name=&amp;quot;kdeveloprefactorings&amp;quot;&amp;gt;Kdevelop4: Now with refactoring! http://zwabel.wordpress.com/2008/11/05/kdevelop4-now-with-refactoring/&amp;lt;/ref&amp;gt;. Project wide search/replace and local search/replace.&lt;br /&gt;
! Yes but very limited.&lt;br /&gt;
! 2&lt;br /&gt;
! Rename Class &lt;br /&gt;
! Right click on class name and select Rename&lt;br /&gt;
|-&lt;br /&gt;
! NetBeans &amp;lt;ref name=&amp;quot;refnetbeans&amp;quot;&amp;gt;Refactoring in NetBeans 4.1 http://java.sun.com/developer/technicalArticles/tools/refactoring/&amp;lt;/ref&amp;gt;&lt;br /&gt;
! Java&lt;br /&gt;
! Renaming fields, methods, classes, or packages, Encapsulating fields, Changing method parameters, Moving classes, &lt;br /&gt;
! Yes but very limited &lt;br /&gt;
! 4&lt;br /&gt;
! No&lt;br /&gt;
! &lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Foo{&lt;br /&gt;
  public int n;&lt;br /&gt;
  public int Compute(int val);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
---- After Refactoring (Encapsulating field)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pubic class Foo{&lt;br /&gt;
  private int n;&lt;br /&gt;
  public int getN();&lt;br /&gt;
  public void setN(int val);&lt;br /&gt;
  public int Compute(int arg);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Padre&lt;br /&gt;
! Perl&lt;br /&gt;
! Lexically Rename Variable, Introduce Temporary Variable&amp;lt;ref name=&amp;quot;padrerefactorings&amp;quot; &amp;gt;How to do it in Padre http://padre.perlide.org/howto.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
! Yes&lt;br /&gt;
! Unknown&lt;br /&gt;
! &lt;br /&gt;
! Right click on item to refactor and select refactoring choice from the context menu&lt;br /&gt;
|-&lt;br /&gt;
! RubyMine&lt;br /&gt;
! Ruby&lt;br /&gt;
! Safe Delete, Rename Refactorings, Push Members Down, Pull Members Up, Move Refactorings, Introduce Variable, Introduce Parameter, Introduce Field, Introduce Constant, Inline, Extract Superclass, Extract Module, Extract Partial, Extract Method, Copy / Clone.&lt;br /&gt;
! Yes&lt;br /&gt;
! 15&lt;br /&gt;
! Introduce Temporary&lt;br /&gt;
!&lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
c = a * b + 5&lt;br /&gt;
d = 2 * a * b&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
---- After Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
t = a * b&lt;br /&gt;
c = t + 5&lt;br /&gt;
d = 2 * t&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Visual Studio &amp;lt;ref name=&amp;quot;refvstudio&amp;quot;&amp;gt;7 Refactoring Methods in Visual Studio 2010 http://p2p.wrox.com/content/articles/7-refactoring-methods-visual-studio-2010 &amp;lt;/ref&amp;gt;&lt;br /&gt;
! C, C++, Java, C#&lt;br /&gt;
! Extract Method, Encapsulate Field, Extract Interface, Rename, Promote Variable to Parameter(Changing method signature), Generate Method Stub(Used for testing purposes)&lt;br /&gt;
! Yes&lt;br /&gt;
! 7&lt;br /&gt;
! No&lt;br /&gt;
! Promoting Variable to Parameter&lt;br /&gt;
---- Before Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB();&lt;br /&gt;
}&lt;br /&gt;
public void MethodB()&lt;br /&gt;
{&lt;br /&gt;
    string output = &amp;quot;Test String&amp;quot;;&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
---- After Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB(&amp;quot;Test String&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
public void MethodB(string output)&lt;br /&gt;
{&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Refactoring to Patterns==&lt;br /&gt;
Refactoring to Patterns is the process of improving the design of existing code -- with patterns, the classic solutions to recurring design problems. This is still a young area of research and currently IDEs hardly provide any support for Automated Design Pattern Refactoring. &lt;br /&gt;
A lot of work is currently in progress in this fairly young research topic. Using automated refactorings to move towards, to, or away from a pattern is completely different from using a tool to generate pattern code. Pattern code generators provide an excellent way to over-engineer your code but They provide code does not include testing. By contrast, refactoring lets you discover small design improvements you can safely make to go towards, to, or away from a pattern implementation.  &amp;lt;ref name=&amp;quot;refactor&amp;quot;&amp;gt;Introduction to Refactoring to patterns http://www.informit.com/articles/article.aspx?p=360842&amp;amp;seqNum=11&amp;lt;/ref&amp;gt;. The refactoring support in an IDE attracted the application developers who used to code in editors to move to IDE. &lt;br /&gt;
&lt;br /&gt;
As refactoring tools continue to implement low-level refactorings, like Extract Method, Extract Class , and Pull Up Method , it becomes easier to transform designs by executing sequences of automated refactorings. This has important implications for pattern-directed refactorings because the mechanics for these refactorings are composed of low-level refactorings. In the future, we can hope to see more and more low level refactoring support such that tools could suggest the refactorings that could help in improving the design of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54717</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54717"/>
		<updated>2011-11-03T03:31:13Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Refactoring support in popular IDE(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; As people make changes to the code to realize their short term goals without fully understanding the design of code, the code loses its structure.  The refactoring work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape. &amp;lt;ref name=&amp;quot;reftwo&amp;quot;&amp;gt; Why should you Refactor http://sourcemaking.com/refactoring/why-should-you-refactor &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Fully autonomous factoring doesn't appear to exist at this time in the IDE(s) described below.  However there are papers &amp;lt;i&amp;gt;Inducing Evolution-Robust Pointcuts&amp;lt;/i&amp;gt; &amp;lt;Ref name=&amp;quot;refseven&amp;quot;&amp;gt;Inducing Evolution-Robust Pointcuts, Braem, M.&amp;lt;/ref&amp;gt; and &amp;lt;i&amp;gt;Automatic Refactoring of Erlang Programs&amp;lt;/i&amp;gt;&amp;lt;ref name=&amp;quot;refeight&amp;quot;&amp;gt;Automatic Refactoring of Erlang Programs http://www.ece.cmu.edu/~aavgerin/papers/PPDP09.pdf&amp;lt;/ref&amp;gt; that point the way to the future of refactoring that can be fully automated.  In the context of this wiki article, automatic refactoring means automated refactoring under programmer control and guidance.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common Refactoring Techniques==&lt;br /&gt;
===Extraction Refactoring=== &lt;br /&gt;
There are several refactoring techniques related to extraction: Extract method, Extract local variables, extract constants. The first method &amp;quot;Extract method will create a new method from code you've selected. Extract Local Variable refactoring takes an expression that is being used repeatedly and assigns it to a local variable. Extract constant refactoring is to select a static, constant expression, which the refactoring will convert to a static final constant. This is useful for removing hard-coded numbers and strings from your code&lt;br /&gt;
&lt;br /&gt;
===Inline Refactoring=== &lt;br /&gt;
This type refactoring is the reverse of local variable extraction, in which we remove a local variable and use the value of the variable(typically an expression) in the place where the variable is used. This can be marginally more efficient than using a temporary variable and, by making the code terser, makes it either easier to read or more cryptic, depending on your point of view&amp;lt;ref name=&amp;quot;refthree&amp;quot;&amp;gt; refactoring for everyone http://www.ibm.com/developerworks/library/os-ecref/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Encapsulating Fields===&lt;br /&gt;
Generally its not a good practice to expose the class attributes through public interface. Thus, Encapsulating such fields will make such fields as private or protected as appropriate and generate getters and setters for the associated field.&lt;br /&gt;
&lt;br /&gt;
===Changing Method Signature===&lt;br /&gt;
Here we change the change the parameters, visibility, and return type of a method.&lt;br /&gt;
&lt;br /&gt;
== Other Refactorings ==&lt;br /&gt;
&lt;br /&gt;
There are a multitude of refactorings.  Those that are included with RubyMine&amp;lt;ref name=&amp;quot;reffour&amp;quot;&amp;gt;RubyMine :: Ruby and Ruby on Rails IDE with smart code completion, syntax highlighting and refactoring http://www.jetbrains.com/ruby/features/ruby_ide.html#Refactorings&amp;lt;/ref&amp;gt; include:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename refactoring&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Method&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Module&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Superclass&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Constant&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Field&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Parameter&lt;br /&gt;
&amp;lt;li&amp;gt;Inline Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Pull Up Members&lt;br /&gt;
&amp;lt;li&amp;gt;Push Down Members&lt;br /&gt;
&amp;lt;li&amp;gt;Override Method&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Martin Fowler has online resources for additional refactoring definitions which can be found here http://martinfowler.com/bliki/refactoring.html&amp;lt;ref name=&amp;quot;reffive&amp;quot;&amp;gt;MF Blicki: refactoring http://martinfowler.com/bliki/refactoring.html&amp;lt;/ref&amp;gt; and here http://refactoring.com/catalog/&amp;lt;ref name=&amp;quot;refsix&amp;quot;&amp;gt;Alpha list of refactorings http://refactoring.com/catalog/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Refactoring support in popular IDE(s)==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;font-size: 90%; text-align: center; width: auto;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! IDE&lt;br /&gt;
! Language(s)&lt;br /&gt;
! Refactoring Support&lt;br /&gt;
! Automated Refactoring?&lt;br /&gt;
! Number of Refactoring support&lt;br /&gt;
! Support for Pattern&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
! Borland Delphi&lt;br /&gt;
! Object Oriented Pascal&lt;br /&gt;
! Rename refactoring, Refactor driven “Find References”, Introduce Variable refactoring, Introduce Field refactoring, Inline Variable refactoring, Change Parameters refactoring, Safe Delete refactoring, Push Members Up / Down refactoring, Pull Members Up refactoring, Extract Superclass refactoring, Extract Interface refactoring, Move Members refactoring, Declare variable refactoring, Declare field refactoring, Extract method refactoring, Find unit/import namespace refactoring, Refactor driven “Find in Files”, Extract to resource string refactoring&amp;lt;ref name=&amp;quot;borlandrefactorings&amp;gt;Leveraging What You Have: 10 Top Things Added to Delphi Since Delphi 7 http://edn.embarcadero.com/article/37416&amp;lt;/ref&amp;gt;&lt;br /&gt;
! Yes&lt;br /&gt;
! 17&lt;br /&gt;
! Declare Variable&amp;lt;ref name=&amp;quot;borlanddecvar&amp;quot;&amp;gt;Increased Productivity with Refactoring, Unit Testing, Help Insight, Error Insight, and Sync Edit in Borland Delphi 2005 http://edn.embarcadero.com/article/33278&amp;lt;/ref&amp;gt;&lt;br /&gt;
!&lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
procedure TWinForm1.btnOpen_Click(sender: System.Object;&lt;br /&gt;
  e: System.EventArgs);&lt;br /&gt;
begin&lt;br /&gt;
  if (OpenFileDialog1.ShowDialog =&lt;br /&gt;
      System.Windows.Forms.DialogResult.OK) then&lt;br /&gt;
  begin&lt;br /&gt;
    Assign(f,OpenFileDialog1.FileName);&lt;br /&gt;
    Reset(f);&lt;br /&gt;
    try&lt;br /&gt;
    finally&lt;br /&gt;
      CloseFile(f);&lt;br /&gt;
    end;&lt;br /&gt;
  end;&lt;br /&gt;
end;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
---- After Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
procedure TWinForm1.btnOpen_Click(sender: System.Object;&lt;br /&gt;
  e: System.EventArgs);&lt;br /&gt;
var&lt;br /&gt;
  f: TextFile;&lt;br /&gt;
begin&lt;br /&gt;
  if (OpenFileDialog1.ShowDialog =&lt;br /&gt;
      System.Windows.Forms.DialogResult.OK) then&lt;br /&gt;
  begin&lt;br /&gt;
    Assign(f,OpenFileDialog1.FileName);&lt;br /&gt;
    Reset(f);&lt;br /&gt;
    try&lt;br /&gt;
    finally&lt;br /&gt;
      CloseFile(f);&lt;br /&gt;
    end;&lt;br /&gt;
  end;&lt;br /&gt;
end;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Eclipse &amp;lt;ref name='refeclipse'&amp;gt;Eclipse Refactoring Actions http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-menu-refactor.htm &amp;lt;/ref&amp;gt;&lt;br /&gt;
! C, C++, Java&lt;br /&gt;
! Rename selected Elements, Move selected elements, Change Method Signature, Extraction, Convert Anonymous Class to Nested, Convert Local Variable to Field, Extract Super class and Interface, push down, pull up, Introduce Indirection, Encapsulate Field, Migrate JAR File, Create &amp;amp; Apply Refatoring Scripts&lt;br /&gt;
! Yes&lt;br /&gt;
! 27&lt;br /&gt;
! Introduce Factory&lt;br /&gt;
! &lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
int x= p * 5; 	&lt;br /&gt;
p.x;&lt;br /&gt;
---- After Refactoring&lt;br /&gt;
int x= getFoo(p); (Method Extraction) &lt;br /&gt;
p.getX() (Encapsulate Field)&lt;br /&gt;
|-&lt;br /&gt;
! Kdevelop&lt;br /&gt;
! C, C++&lt;br /&gt;
! Several&amp;lt;ref name=&amp;quot;kdeveloprefactorings&amp;quot;&amp;gt;Kdevelop4: Now with refactoring! http://zwabel.wordpress.com/2008/11/05/kdevelop4-now-with-refactoring/&amp;lt;/ref&amp;gt;. Project wide search/replace and local search/replace.&lt;br /&gt;
! Yes but very limited.&lt;br /&gt;
! 2&lt;br /&gt;
! Rename Class &lt;br /&gt;
! Right click on class name and select Rename&lt;br /&gt;
|-&lt;br /&gt;
! NetBeans &amp;lt;ref name=&amp;quot;refnetbeans&amp;quot;&amp;gt;Refactoring in NetBeans 4.1 http://java.sun.com/developer/technicalArticles/tools/refactoring/&amp;lt;/ref&amp;gt;&lt;br /&gt;
! Java&lt;br /&gt;
! Renaming fields, methods, classes, or packages, Encapsulating fields, Changing method parameters, Moving classes, &lt;br /&gt;
! Yes but very limited &lt;br /&gt;
! 4&lt;br /&gt;
! No&lt;br /&gt;
! &lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Foo{&lt;br /&gt;
  public int n;&lt;br /&gt;
  public int Compute(int val);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
---- After Refactoring (Encapsulating field)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pubic class Foo{&lt;br /&gt;
  private int n;&lt;br /&gt;
  public int getN();&lt;br /&gt;
  public void setN(int val);&lt;br /&gt;
  public int Compute(int arg);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Padre&lt;br /&gt;
! Perl&lt;br /&gt;
! Lexically Rename Variable, Introduce Temporary Variable&amp;lt;ref name=&amp;quot;padrerefactorings&amp;quot; &amp;gt;How to do it in Padre http://padre.perlide.org/howto.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
! Yes&lt;br /&gt;
! Unknown&lt;br /&gt;
! &lt;br /&gt;
! Right click on item to refactor and select refactoring choice from the context menu&lt;br /&gt;
|-&lt;br /&gt;
! RubyMine&lt;br /&gt;
! Ruby&lt;br /&gt;
! Safe Delete, Rename Refactorings, Push Members Down, Pull Members Up, Move Refactorings, Introduce Variable, Introduce Parameter, Introduce Field, Introduce Constant, Inline, Extract Superclass, Extract Module, Extract Partial, Extract Method, Copy / Clone.&lt;br /&gt;
! Yes&lt;br /&gt;
! 11&lt;br /&gt;
! Introduce Temporary&lt;br /&gt;
!&lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
c = a * b + 5&lt;br /&gt;
d = 2 * a * b&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
---- After Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
t = a * b&lt;br /&gt;
c = t + 5&lt;br /&gt;
d = 2 * t&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Visual Studio &amp;lt;ref name=&amp;quot;refvstudio&amp;quot;&amp;gt;7 Refactoring Methods in Visual Studio 2010 http://p2p.wrox.com/content/articles/7-refactoring-methods-visual-studio-2010 &amp;lt;/ref&amp;gt;&lt;br /&gt;
! C, C++, Java, C#&lt;br /&gt;
! Extract Method, Encapsulate Field, Extract Interface, Rename, Promote Variable to Parameter(Changing method signature), Generate Method Stub(Used for testing purposes)&lt;br /&gt;
! Yes&lt;br /&gt;
! 7&lt;br /&gt;
! No&lt;br /&gt;
! Promoting Variable to Parameter&lt;br /&gt;
---- Before Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB();&lt;br /&gt;
}&lt;br /&gt;
public void MethodB()&lt;br /&gt;
{&lt;br /&gt;
    string output = &amp;quot;Test String&amp;quot;;&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
---- After Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB(&amp;quot;Test String&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
public void MethodB(string output)&lt;br /&gt;
{&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Refactoring to Patterns==&lt;br /&gt;
Refactoring to Patterns is the process of improving the design of existing code -- with patterns, the classic solutions to recurring design problems. This is still a young area of research and currently IDEs hardly provide any support for Automated Design Pattern Refactoring. &lt;br /&gt;
A lot of work is currently in progress in this fairly young research topic. Using automated refactorings to move towards, to, or away from a pattern is completely different from using a tool to generate pattern code. Pattern code generators provide an excellent way to over-engineer your code but They provide code does not include testing. By contrast, refactoring lets you discover small design improvements you can safely make to go towards, to, or away from a pattern implementation.  &amp;lt;ref name=&amp;quot;refactor&amp;quot;&amp;gt;Introduction to Refactoring to patterns http://www.informit.com/articles/article.aspx?p=360842&amp;amp;seqNum=11&amp;lt;/ref&amp;gt;. The refactoring support in an IDE attracted the application developers who used to code in editors to move to IDE. &lt;br /&gt;
&lt;br /&gt;
As refactoring tools continue to implement low-level refactorings, like Extract Method, Extract Class , and Pull Up Method , it becomes easier to transform designs by executing sequences of automated refactorings. This has important implications for pattern-directed refactorings because the mechanics for these refactorings are composed of low-level refactorings. In the future, we can hope to see more and more low level refactoring support such that tools could suggest the refactorings that could help in improving the design of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54715</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54715"/>
		<updated>2011-11-03T03:23:14Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Refactoring to Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; As people make changes to the code to realize their short term goals without fully understanding the design of code, the code loses its structure.  The refactoring work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape. &amp;lt;ref name=&amp;quot;reftwo&amp;quot;&amp;gt; Why should you Refactor http://sourcemaking.com/refactoring/why-should-you-refactor &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Fully autonomous factoring doesn't appear to exist at this time in the IDE(s) described below.  However there are papers &amp;lt;i&amp;gt;Inducing Evolution-Robust Pointcuts&amp;lt;/i&amp;gt; &amp;lt;Ref name=&amp;quot;refseven&amp;quot;&amp;gt;Inducing Evolution-Robust Pointcuts, Braem, M.&amp;lt;/ref&amp;gt; and &amp;lt;i&amp;gt;Automatic Refactoring of Erlang Programs&amp;lt;/i&amp;gt;&amp;lt;ref name=&amp;quot;refeight&amp;quot;&amp;gt;Automatic Refactoring of Erlang Programs http://www.ece.cmu.edu/~aavgerin/papers/PPDP09.pdf&amp;lt;/ref&amp;gt; that point the way to the future of refactoring that can be fully automated.  In the context of this wiki article, automatic refactoring means automated refactoring under programmer control and guidance.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common Refactoring Techniques==&lt;br /&gt;
===Extraction Refactoring=== &lt;br /&gt;
There are several refactoring techniques related to extraction: Extract method, Extract local variables, extract constants. The first method &amp;quot;Extract method will create a new method from code you've selected. Extract Local Variable refactoring takes an expression that is being used repeatedly and assigns it to a local variable. Extract constant refactoring is to select a static, constant expression, which the refactoring will convert to a static final constant. This is useful for removing hard-coded numbers and strings from your code&lt;br /&gt;
&lt;br /&gt;
===Inline Refactoring=== &lt;br /&gt;
This type refactoring is the reverse of local variable extraction, in which we remove a local variable and use the value of the variable(typically an expression) in the place where the variable is used. This can be marginally more efficient than using a temporary variable and, by making the code terser, makes it either easier to read or more cryptic, depending on your point of view&amp;lt;ref name=&amp;quot;refthree&amp;quot;&amp;gt; refactoring for everyone http://www.ibm.com/developerworks/library/os-ecref/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Encapsulating Fields===&lt;br /&gt;
Generally its not a good practice to expose the class attributes through public interface. Thus, Encapsulating such fields will make such fields as private or protected as appropriate and generate getters and setters for the associated field.&lt;br /&gt;
&lt;br /&gt;
===Changing Method Signature===&lt;br /&gt;
Here we change the change the parameters, visibility, and return type of a method.&lt;br /&gt;
&lt;br /&gt;
== Other Refactorings ==&lt;br /&gt;
&lt;br /&gt;
There are a multitude of refactorings.  Those that are included with RubyMine&amp;lt;ref name=&amp;quot;reffour&amp;quot;&amp;gt;RubyMine :: Ruby and Ruby on Rails IDE with smart code completion, syntax highlighting and refactoring http://www.jetbrains.com/ruby/features/ruby_ide.html#Refactorings&amp;lt;/ref&amp;gt; include:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename refactoring&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Method&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Module&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Superclass&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Constant&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Field&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Parameter&lt;br /&gt;
&amp;lt;li&amp;gt;Inline Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Pull Up Members&lt;br /&gt;
&amp;lt;li&amp;gt;Push Down Members&lt;br /&gt;
&amp;lt;li&amp;gt;Override Method&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Martin Fowler has online resources for additional refactoring definitions which can be found here http://martinfowler.com/bliki/refactoring.html&amp;lt;ref name=&amp;quot;reffive&amp;quot;&amp;gt;MF Blicki: refactoring http://martinfowler.com/bliki/refactoring.html&amp;lt;/ref&amp;gt; and here http://refactoring.com/catalog/&amp;lt;ref name=&amp;quot;refsix&amp;quot;&amp;gt;Alpha list of refactorings http://refactoring.com/catalog/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Refactoring support in popular IDE(s)==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;font-size: 90%; text-align: center; width: auto;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! IDE&lt;br /&gt;
! Language(s)&lt;br /&gt;
! Refactoring Support&lt;br /&gt;
! Automated Refactoring?&lt;br /&gt;
! Number of Refactoring support&lt;br /&gt;
! Support for Pattern&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
! Borland Delphi&lt;br /&gt;
! Object Oriented Pascal&lt;br /&gt;
! Rename refactoring, Refactor driven “Find References”, Introduce Variable refactoring, Introduce Field refactoring, Inline Variable refactoring, Change Parameters refactoring, Safe Delete refactoring, Push Members Up / Down refactoring, Pull Members Up refactoring, Extract Superclass refactoring, Extract Interface refactoring, Move Members refactoring, Declare variable refactoring, Declare field refactoring, Extract method refactoring, Find unit/import namespace refactoring, Refactor driven “Find in Files”, Extract to resource string refactoring&amp;lt;ref name=&amp;quot;borlandrefactorings&amp;gt;Leveraging What You Have: 10 Top Things Added to Delphi Since Delphi 7 http://edn.embarcadero.com/article/37416&amp;lt;/ref&amp;gt;&lt;br /&gt;
! Yes&lt;br /&gt;
! 17&lt;br /&gt;
! Declare Variable&amp;lt;ref name=&amp;quot;borlanddecvar&amp;quot;&amp;gt;Increased Productivity with Refactoring, Unit Testing, Help Insight, Error Insight, and Sync Edit in Borland Delphi 2005 http://edn.embarcadero.com/article/33278&amp;lt;/ref&amp;gt;&lt;br /&gt;
!&lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
procedure TWinForm1.btnOpen_Click(sender: System.Object;&lt;br /&gt;
  e: System.EventArgs);&lt;br /&gt;
begin&lt;br /&gt;
  if (OpenFileDialog1.ShowDialog =&lt;br /&gt;
      System.Windows.Forms.DialogResult.OK) then&lt;br /&gt;
  begin&lt;br /&gt;
    Assign(f,OpenFileDialog1.FileName);&lt;br /&gt;
    Reset(f);&lt;br /&gt;
    try&lt;br /&gt;
    finally&lt;br /&gt;
      CloseFile(f);&lt;br /&gt;
    end;&lt;br /&gt;
  end;&lt;br /&gt;
end;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
---- After Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
procedure TWinForm1.btnOpen_Click(sender: System.Object;&lt;br /&gt;
  e: System.EventArgs);&lt;br /&gt;
var&lt;br /&gt;
  f: TextFile;&lt;br /&gt;
begin&lt;br /&gt;
  if (OpenFileDialog1.ShowDialog =&lt;br /&gt;
      System.Windows.Forms.DialogResult.OK) then&lt;br /&gt;
  begin&lt;br /&gt;
    Assign(f,OpenFileDialog1.FileName);&lt;br /&gt;
    Reset(f);&lt;br /&gt;
    try&lt;br /&gt;
    finally&lt;br /&gt;
      CloseFile(f);&lt;br /&gt;
    end;&lt;br /&gt;
  end;&lt;br /&gt;
end;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Eclipse &amp;lt;ref name='refeclipse'&amp;gt;Eclipse Refactoring Actions http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-menu-refactor.htm &amp;lt;/ref&amp;gt;&lt;br /&gt;
! C, C++, Java&lt;br /&gt;
! Rename selected Elements, Move selected elements, Change Method Signature, Extraction, Convert Anonymous Class to Nested, Convert Local Variable to Field, Extract Super class and Interface, push down, pull up, Introduce Indirection, Encapsulate Field, Migrate JAR File, Create &amp;amp; Apply Refatoring Scripts&lt;br /&gt;
! Yes&lt;br /&gt;
! 27&lt;br /&gt;
! Introduce Factory&lt;br /&gt;
! &lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
int x= p * 5; 	&lt;br /&gt;
p.x;&lt;br /&gt;
---- After Refactoring&lt;br /&gt;
int x= getFoo(p); (Method Extraction) &lt;br /&gt;
p.getX() (Encapsulate Field)&lt;br /&gt;
|-&lt;br /&gt;
! Kdevelop&lt;br /&gt;
! C, C++&lt;br /&gt;
! Several&amp;lt;ref name=&amp;quot;kdeveloprefactorings&amp;quot;&amp;gt;Kdevelop4: Now with refactoring! http://zwabel.wordpress.com/2008/11/05/kdevelop4-now-with-refactoring/&amp;lt;/ref&amp;gt;. Project wide search/replace and local search/replace.&lt;br /&gt;
! Yes but very limited.&lt;br /&gt;
! 2&lt;br /&gt;
! Rename Class &lt;br /&gt;
! Right click on class name and select Rename&lt;br /&gt;
|-&lt;br /&gt;
! NetBeans &amp;lt;ref name=&amp;quot;refnetbeans&amp;quot;&amp;gt;Refactoring in NetBeans 4.1 http://java.sun.com/developer/technicalArticles/tools/refactoring/&amp;lt;/ref&amp;gt;&lt;br /&gt;
! Java&lt;br /&gt;
! Renaming fields, methods, classes, or packages, Encapsulating fields, Changing method parameters, Moving classes, &lt;br /&gt;
! Yes but very limited &lt;br /&gt;
! 4&lt;br /&gt;
! No&lt;br /&gt;
! &lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Foo{&lt;br /&gt;
  public int n;&lt;br /&gt;
  public int Compute(int val);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
---- After Refactoring (Encapsulating field)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pubic class Foo{&lt;br /&gt;
  private int n;&lt;br /&gt;
  public int getN();&lt;br /&gt;
  public void setN(int val);&lt;br /&gt;
  public int Compute(int arg);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Padre&lt;br /&gt;
! Perl&lt;br /&gt;
! Lexically Rename Variable, Introduce Temporary Variable&amp;lt;ref name=&amp;quot;padrerefactorings&amp;quot; &amp;gt;How to do it in Padre http://padre.perlide.org/howto.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
! Yes&lt;br /&gt;
! Unknown&lt;br /&gt;
! &lt;br /&gt;
! Right click on item to refactor and select refactoring choice from the context menu&lt;br /&gt;
|-&lt;br /&gt;
! RubyMine&lt;br /&gt;
! Ruby&lt;br /&gt;
! No&lt;br /&gt;
! Yes&lt;br /&gt;
! 11&lt;br /&gt;
! Introduce Temporary&lt;br /&gt;
!&lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
c = a * b + 5&lt;br /&gt;
d = 2 * a * b&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
---- After Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
t = a * b&lt;br /&gt;
c = t + 5&lt;br /&gt;
d = 2 * t&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Visual Studio &amp;lt;ref name=&amp;quot;refvstudio&amp;quot;&amp;gt;7 Refactoring Methods in Visual Studio 2010 http://p2p.wrox.com/content/articles/7-refactoring-methods-visual-studio-2010 &amp;lt;/ref&amp;gt;&lt;br /&gt;
! C, C++, Java, C#&lt;br /&gt;
! Extract Method, Encapsulate Field, Extract Interface, Rename, Promote Variable to Parameter(Changing method signature), Generate Method Stub(Used for testing purposes)&lt;br /&gt;
! Yes&lt;br /&gt;
! 7&lt;br /&gt;
! No&lt;br /&gt;
! Promoting Variable to Parameter&lt;br /&gt;
---- Before Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB();&lt;br /&gt;
}&lt;br /&gt;
public void MethodB()&lt;br /&gt;
{&lt;br /&gt;
    string output = &amp;quot;Test String&amp;quot;;&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
---- After Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB(&amp;quot;Test String&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
public void MethodB(string output)&lt;br /&gt;
{&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Refactoring to Patterns==&lt;br /&gt;
Refactoring to Patterns is the process of improving the design of existing code -- with patterns, the classic solutions to recurring design problems. This is still a young area of research and currently IDEs hardly provide any support for Automated Design Pattern Refactoring. &lt;br /&gt;
A lot of work is currently in progress in this fairly young research topic. Using automated refactorings to move towards, to, or away from a pattern is completely different from using a tool to generate pattern code. Pattern code generators provide an excellent way to over-engineer your code but They provide code does not include testing. By contrast, refactoring lets you discover small design improvements you can safely make to go towards, to, or away from a pattern implementation.  &amp;lt;ref name=&amp;quot;refactor&amp;quot;&amp;gt;Introduction to Refactoring to patterns http://www.informit.com/articles/article.aspx?p=360842&amp;amp;seqNum=11&amp;lt;/ref&amp;gt;. The refactoring support in an IDE attracted the application developers who used to code in editors to move to IDE. &lt;br /&gt;
&lt;br /&gt;
As refactoring tools continue to implement low-level refactorings, like Extract Method, Extract Class , and Pull Up Method , it becomes easier to transform designs by executing sequences of automated refactorings. This has important implications for pattern-directed refactorings because the mechanics for these refactorings are composed of low-level refactorings. In the future, we can hope to see more and more low level refactoring support such that tools could suggest the refactorings that could help in improving the design of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54714</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54714"/>
		<updated>2011-11-03T03:17:52Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; As people make changes to the code to realize their short term goals without fully understanding the design of code, the code loses its structure.  The refactoring work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape. &amp;lt;ref name=&amp;quot;reftwo&amp;quot;&amp;gt; Why should you Refactor http://sourcemaking.com/refactoring/why-should-you-refactor &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Fully autonomous factoring doesn't appear to exist at this time in the IDE(s) described below.  However there are papers &amp;lt;i&amp;gt;Inducing Evolution-Robust Pointcuts&amp;lt;/i&amp;gt; &amp;lt;Ref name=&amp;quot;refseven&amp;quot;&amp;gt;Inducing Evolution-Robust Pointcuts, Braem, M.&amp;lt;/ref&amp;gt; and &amp;lt;i&amp;gt;Automatic Refactoring of Erlang Programs&amp;lt;/i&amp;gt;&amp;lt;ref name=&amp;quot;refeight&amp;quot;&amp;gt;Automatic Refactoring of Erlang Programs http://www.ece.cmu.edu/~aavgerin/papers/PPDP09.pdf&amp;lt;/ref&amp;gt; that point the way to the future of refactoring that can be fully automated.  In the context of this wiki article, automatic refactoring means automated refactoring under programmer control and guidance.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common Refactoring Techniques==&lt;br /&gt;
===Extraction Refactoring=== &lt;br /&gt;
There are several refactoring techniques related to extraction: Extract method, Extract local variables, extract constants. The first method &amp;quot;Extract method will create a new method from code you've selected. Extract Local Variable refactoring takes an expression that is being used repeatedly and assigns it to a local variable. Extract constant refactoring is to select a static, constant expression, which the refactoring will convert to a static final constant. This is useful for removing hard-coded numbers and strings from your code&lt;br /&gt;
&lt;br /&gt;
===Inline Refactoring=== &lt;br /&gt;
This type refactoring is the reverse of local variable extraction, in which we remove a local variable and use the value of the variable(typically an expression) in the place where the variable is used. This can be marginally more efficient than using a temporary variable and, by making the code terser, makes it either easier to read or more cryptic, depending on your point of view&amp;lt;ref name=&amp;quot;refthree&amp;quot;&amp;gt; refactoring for everyone http://www.ibm.com/developerworks/library/os-ecref/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Encapsulating Fields===&lt;br /&gt;
Generally its not a good practice to expose the class attributes through public interface. Thus, Encapsulating such fields will make such fields as private or protected as appropriate and generate getters and setters for the associated field.&lt;br /&gt;
&lt;br /&gt;
===Changing Method Signature===&lt;br /&gt;
Here we change the change the parameters, visibility, and return type of a method.&lt;br /&gt;
&lt;br /&gt;
== Other Refactorings ==&lt;br /&gt;
&lt;br /&gt;
There are a multitude of refactorings.  Those that are included with RubyMine&amp;lt;ref name=&amp;quot;reffour&amp;quot;&amp;gt;RubyMine :: Ruby and Ruby on Rails IDE with smart code completion, syntax highlighting and refactoring http://www.jetbrains.com/ruby/features/ruby_ide.html#Refactorings&amp;lt;/ref&amp;gt; include:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename refactoring&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Method&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Module&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Superclass&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Constant&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Field&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Parameter&lt;br /&gt;
&amp;lt;li&amp;gt;Inline Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Pull Up Members&lt;br /&gt;
&amp;lt;li&amp;gt;Push Down Members&lt;br /&gt;
&amp;lt;li&amp;gt;Override Method&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Martin Fowler has online resources for additional refactoring definitions which can be found here http://martinfowler.com/bliki/refactoring.html&amp;lt;ref name=&amp;quot;reffive&amp;quot;&amp;gt;MF Blicki: refactoring http://martinfowler.com/bliki/refactoring.html&amp;lt;/ref&amp;gt; and here http://refactoring.com/catalog/&amp;lt;ref name=&amp;quot;refsix&amp;quot;&amp;gt;Alpha list of refactorings http://refactoring.com/catalog/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Refactoring support in popular IDE(s)==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;font-size: 90%; text-align: center; width: auto;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! IDE&lt;br /&gt;
! Language(s)&lt;br /&gt;
! Refactoring Support&lt;br /&gt;
! Automated Refactoring?&lt;br /&gt;
! Number of Refactoring support&lt;br /&gt;
! Support for Pattern&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
! Borland Delphi&lt;br /&gt;
! Object Oriented Pascal&lt;br /&gt;
! Rename refactoring, Refactor driven “Find References”, Introduce Variable refactoring, Introduce Field refactoring, Inline Variable refactoring, Change Parameters refactoring, Safe Delete refactoring, Push Members Up / Down refactoring, Pull Members Up refactoring, Extract Superclass refactoring, Extract Interface refactoring, Move Members refactoring, Declare variable refactoring, Declare field refactoring, Extract method refactoring, Find unit/import namespace refactoring, Refactor driven “Find in Files”, Extract to resource string refactoring&amp;lt;ref name=&amp;quot;borlandrefactorings&amp;gt;Leveraging What You Have: 10 Top Things Added to Delphi Since Delphi 7 http://edn.embarcadero.com/article/37416&amp;lt;/ref&amp;gt;&lt;br /&gt;
! Yes&lt;br /&gt;
! 17&lt;br /&gt;
! Declare Variable&amp;lt;ref name=&amp;quot;borlanddecvar&amp;quot;&amp;gt;Increased Productivity with Refactoring, Unit Testing, Help Insight, Error Insight, and Sync Edit in Borland Delphi 2005 http://edn.embarcadero.com/article/33278&amp;lt;/ref&amp;gt;&lt;br /&gt;
!&lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
procedure TWinForm1.btnOpen_Click(sender: System.Object;&lt;br /&gt;
  e: System.EventArgs);&lt;br /&gt;
begin&lt;br /&gt;
  if (OpenFileDialog1.ShowDialog =&lt;br /&gt;
      System.Windows.Forms.DialogResult.OK) then&lt;br /&gt;
  begin&lt;br /&gt;
    Assign(f,OpenFileDialog1.FileName);&lt;br /&gt;
    Reset(f);&lt;br /&gt;
    try&lt;br /&gt;
    finally&lt;br /&gt;
      CloseFile(f);&lt;br /&gt;
    end;&lt;br /&gt;
  end;&lt;br /&gt;
end;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
---- After Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
procedure TWinForm1.btnOpen_Click(sender: System.Object;&lt;br /&gt;
  e: System.EventArgs);&lt;br /&gt;
var&lt;br /&gt;
  f: TextFile;&lt;br /&gt;
begin&lt;br /&gt;
  if (OpenFileDialog1.ShowDialog =&lt;br /&gt;
      System.Windows.Forms.DialogResult.OK) then&lt;br /&gt;
  begin&lt;br /&gt;
    Assign(f,OpenFileDialog1.FileName);&lt;br /&gt;
    Reset(f);&lt;br /&gt;
    try&lt;br /&gt;
    finally&lt;br /&gt;
      CloseFile(f);&lt;br /&gt;
    end;&lt;br /&gt;
  end;&lt;br /&gt;
end;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Eclipse &amp;lt;ref name='refeclipse'&amp;gt;Eclipse Refactoring Actions http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-menu-refactor.htm &amp;lt;/ref&amp;gt;&lt;br /&gt;
! C, C++, Java&lt;br /&gt;
! Rename selected Elements, Move selected elements, Change Method Signature, Extraction, Convert Anonymous Class to Nested, Convert Local Variable to Field, Extract Super class and Interface, push down, pull up, Introduce Indirection, Encapsulate Field, Migrate JAR File, Create &amp;amp; Apply Refatoring Scripts&lt;br /&gt;
! Yes&lt;br /&gt;
! 27&lt;br /&gt;
! Introduce Factory&lt;br /&gt;
! &lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
int x= p * 5; 	&lt;br /&gt;
p.x;&lt;br /&gt;
---- After Refactoring&lt;br /&gt;
int x= getFoo(p); (Method Extraction) &lt;br /&gt;
p.getX() (Encapsulate Field)&lt;br /&gt;
|-&lt;br /&gt;
! Kdevelop&lt;br /&gt;
! C, C++&lt;br /&gt;
! Several&amp;lt;ref name=&amp;quot;kdeveloprefactorings&amp;quot;&amp;gt;Kdevelop4: Now with refactoring! http://zwabel.wordpress.com/2008/11/05/kdevelop4-now-with-refactoring/&amp;lt;/ref&amp;gt;. Project wide search/replace and local search/replace.&lt;br /&gt;
! Yes but very limited.&lt;br /&gt;
! 2&lt;br /&gt;
! Rename Class &lt;br /&gt;
! Right click on class name and select Rename&lt;br /&gt;
|-&lt;br /&gt;
! NetBeans &amp;lt;ref name=&amp;quot;refnetbeans&amp;quot;&amp;gt;Refactoring in NetBeans 4.1 http://java.sun.com/developer/technicalArticles/tools/refactoring/&amp;lt;/ref&amp;gt;&lt;br /&gt;
! Java&lt;br /&gt;
! Renaming fields, methods, classes, or packages, Encapsulating fields, Changing method parameters, Moving classes, &lt;br /&gt;
! Yes but very limited &lt;br /&gt;
! 4&lt;br /&gt;
! No&lt;br /&gt;
! &lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Foo{&lt;br /&gt;
  public int n;&lt;br /&gt;
  public int Compute(int val);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
---- After Refactoring (Encapsulating field)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pubic class Foo{&lt;br /&gt;
  private int n;&lt;br /&gt;
  public int getN();&lt;br /&gt;
  public void setN(int val);&lt;br /&gt;
  public int Compute(int arg);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Padre&lt;br /&gt;
! Perl&lt;br /&gt;
! Lexically Rename Variable, Introduce Temporary Variable&amp;lt;ref name=&amp;quot;padrerefactorings&amp;quot; &amp;gt;How to do it in Padre http://padre.perlide.org/howto.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
! Yes&lt;br /&gt;
! Unknown&lt;br /&gt;
! &lt;br /&gt;
! Right click on item to refactor and select refactoring choice from the context menu&lt;br /&gt;
|-&lt;br /&gt;
! RubyMine&lt;br /&gt;
! Ruby&lt;br /&gt;
! No&lt;br /&gt;
! Yes&lt;br /&gt;
! 11&lt;br /&gt;
! Introduce Temporary&lt;br /&gt;
!&lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
c = a * b + 5&lt;br /&gt;
d = 2 * a * b&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
---- After Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
t = a * b&lt;br /&gt;
c = t + 5&lt;br /&gt;
d = 2 * t&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Visual Studio &amp;lt;ref name=&amp;quot;refvstudio&amp;quot;&amp;gt;7 Refactoring Methods in Visual Studio 2010 http://p2p.wrox.com/content/articles/7-refactoring-methods-visual-studio-2010 &amp;lt;/ref&amp;gt;&lt;br /&gt;
! C, C++, Java, C#&lt;br /&gt;
! Extract Method, Encapsulate Field, Extract Interface, Rename, Promote Variable to Parameter(Changing method signature), Generate Method Stub(Used for testing purposes)&lt;br /&gt;
! Yes&lt;br /&gt;
! 7&lt;br /&gt;
! No&lt;br /&gt;
! Promoting Variable to Parameter&lt;br /&gt;
---- Before Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB();&lt;br /&gt;
}&lt;br /&gt;
public void MethodB()&lt;br /&gt;
{&lt;br /&gt;
    string output = &amp;quot;Test String&amp;quot;;&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
---- After Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB(&amp;quot;Test String&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
public void MethodB(string output)&lt;br /&gt;
{&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring to Patterns===&lt;br /&gt;
Refactoring to Patterns is the process of improving the design of existing code -- with patterns, the classic solutions to recurring design problems. This is still a young area of research and currently IDEs hardly provide any support for Automated Design Pattern Refactoring. &lt;br /&gt;
A lot of work is currently in progress in this fairly young research topic. Using automated refactorings to move towards, to, or away from a pattern is completely different from using a tool to generate pattern code. &amp;lt;ref name=&amp;quot;refactor&amp;quot;&amp;gt;Introduction to Refactoring to patterns http://www.informit.com/articles/article.aspx?p=360842&amp;amp;seqNum=11&amp;lt;/ref&amp;gt;. The refactoring support in an IDE attracted the application developers who used to code in editors to move to IDE. &lt;br /&gt;
&lt;br /&gt;
As refactoring tools continue to implement low-level refactorings, like Extract Method, Extract Class , and Pull Up Method , it becomes easier to transform designs by executing sequences of automated refactorings. This has important implications for pattern-directed refactorings because the mechanics for these refactorings are composed of low-level refactorings.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54608</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54608"/>
		<updated>2011-11-01T23:43:27Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Refactoring support in popular IDE(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; As people make changes to the code to realize their short term goals without fully understanding the design of code, the code loses its structure.  The refactoring work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape. &amp;lt;ref name=&amp;quot;reftwo&amp;quot;&amp;gt; Why should you Refactor http://sourcemaking.com/refactoring/why-should-you-refactor &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Fully autonomous factoring doesn't appear to exist at this time in the IDE(s) described below.  However there are papers &amp;lt;i&amp;gt;Inducing Evolution-Robust Pointcuts&amp;lt;/i&amp;gt; &amp;lt;Ref name=&amp;quot;refseven&amp;quot;&amp;gt;Inducing Evolution-Robust Pointcuts, Braem, M.&amp;lt;/ref&amp;gt; and &amp;lt;i&amp;gt;Automatic Refactoring of Erlang Programs&amp;lt;/i&amp;gt;&amp;lt;ref name=&amp;quot;refeight&amp;quot;&amp;gt;Automatic Refactoring of Erlang Programs http://www.ece.cmu.edu/~aavgerin/papers/PPDP09.pdf&amp;lt;/ref&amp;gt; that point the way to the future of refactoring that can be fully automated.  In the context of this wiki article, automatic refactoring means automated refactoring under programmer control and guidance.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common Refactoring Techniques==&lt;br /&gt;
===Extraction Refactoring=== &lt;br /&gt;
There are several refactoring techniques related to extraction: Extract method, Extract local variables, extract constants. The first method &amp;quot;Extract method will create a new method from code you've selected. Extract Local Variable refactoring takes an expression that is being used repeatedly and assigns it to a local variable. Extract constant refactoring is to select a static, constant expression, which the refactoring will convert to a static final constant. This is useful for removing hard-coded numbers and strings from your code&lt;br /&gt;
&lt;br /&gt;
===Inline Refactoring=== &lt;br /&gt;
This type refactoring is the reverse of local variable extraction, in which we remove a local variable and use the value of the variable(typically an expression) in the place where the variable is used. This can be marginally more efficient than using a temporary variable and, by making the code terser, makes it either easier to read or more cryptic, depending on your point of view&amp;lt;ref name=&amp;quot;refthree&amp;quot;&amp;gt; refactoring for everyone http://www.ibm.com/developerworks/library/os-ecref/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Encapsulating Fields===&lt;br /&gt;
Generally its not a good practice to expose the class attributes through public interface. Thus, Encapsulating such fields will make such fields as private or protected as appropriate and generate getters and setters for the associated field.&lt;br /&gt;
&lt;br /&gt;
===Changing Method Signature===&lt;br /&gt;
Here we change the change the parameters, visibility, and return type of a method.&lt;br /&gt;
&lt;br /&gt;
== Other Refactorings ==&lt;br /&gt;
&lt;br /&gt;
There are a multitude of refactorings.  Those that are included with RubyMine&amp;lt;ref name=&amp;quot;reffour&amp;quot;&amp;gt;RubyMine :: Ruby and Ruby on Rails IDE with smart code completion, syntax highlighting and refactoring http://www.jetbrains.com/ruby/features/ruby_ide.html#Refactorings&amp;lt;/ref&amp;gt; include:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename refactoring&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Method&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Module&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Superclass&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Constant&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Field&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Parameter&lt;br /&gt;
&amp;lt;li&amp;gt;Inline Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Pull Uo Members&lt;br /&gt;
&amp;lt;li&amp;gt;Push Down Members&lt;br /&gt;
&amp;lt;li&amp;gt;Override Method&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Martin Fowler has online resources for additional refactoring definitions which can be found here http://martinfowler.com/bliki/refactoring.html&amp;lt;ref name=&amp;quot;reffive&amp;quot;&amp;gt;MF Blicki: refactoring http://martinfowler.com/bliki/refactoring.html&amp;lt;/ref&amp;gt; and here http://refactoring.com/catalog/&amp;lt;ref name=&amp;quot;refsix&amp;quot;&amp;gt;Alpha list of refactorings http://refactoring.com/catalog/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Refactoring support in popular IDE(s)==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;font-size: 90%; text-align: center; width: auto;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! IDE&lt;br /&gt;
! Refactoring Support&lt;br /&gt;
! Automated Refactoring?&lt;br /&gt;
! Number of Refactoring support&lt;br /&gt;
! Support for Pattern&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
! Borland Delphi&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Eclipse &amp;lt;ref name='refeclipse'&amp;gt;Eclipse Refactoring Actions http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-menu-refactor.htm &amp;lt;/ref&amp;gt;&lt;br /&gt;
! Rename selected Elements, Move selected elements, Change Method Signature, Extraction, Convert Anonymous Class to Nested, Convert Local Variable to Field, Extract Super class and Interface, push down, pull up, Introduce Indirection, Encapsulate Field, Migrate JAR File, Create &amp;amp; Apply Refatoring Scripts&lt;br /&gt;
! Yes&lt;br /&gt;
! 27&lt;br /&gt;
! Introduce Factory&lt;br /&gt;
! &lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
int x= p * 5; 	&lt;br /&gt;
p.x;&lt;br /&gt;
---- After Refactoring&lt;br /&gt;
int x= getFoo(p); (Method Extraction) &lt;br /&gt;
p.getX() (Encapsulate Field)&lt;br /&gt;
|-&lt;br /&gt;
! Kdevelop&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! NetBeans &amp;lt;ref name=&amp;quot;refnetbeans&amp;quot;&amp;gt;Refactoring in NetBeans 4.1 http://java.sun.com/developer/technicalArticles/tools/refactoring/&amp;lt;/ref&amp;gt;&lt;br /&gt;
! Renaming fields, methods, classes, or packages, Encapsulating fields, Changing method parameters, Moving classes, &lt;br /&gt;
! Yes but very limited &lt;br /&gt;
! 4&lt;br /&gt;
! No&lt;br /&gt;
! &lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Foo{&lt;br /&gt;
  public int n;&lt;br /&gt;
  public int Compute(int val);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
---- After Refactoring (Encapsulating field)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pubic class Foo{&lt;br /&gt;
  private int n;&lt;br /&gt;
  public int getN();&lt;br /&gt;
  public void setN(int val);&lt;br /&gt;
  public int Compute(int arg);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Padre&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! RubyMine&lt;br /&gt;
! No&lt;br /&gt;
! Yes&lt;br /&gt;
! 11&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Visual Studio &amp;lt;ref name=&amp;quot;refvstudio&amp;quot;&amp;gt;7 Refactoring Methods in Visual Studio 2010 http://p2p.wrox.com/content/articles/7-refactoring-methods-visual-studio-2010 &amp;lt;/ref&amp;gt;&lt;br /&gt;
! Extract Method, Encapsulate Field, Extract Interface, Rename, Promote Variable to Parameter(Changing method signature), Generate Method Stub(Used for testing purposes)&lt;br /&gt;
! Yes&lt;br /&gt;
! 7&lt;br /&gt;
! No&lt;br /&gt;
! Promoting Variable to Parameter&lt;br /&gt;
---- Before Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB();&lt;br /&gt;
}&lt;br /&gt;
public void MethodB()&lt;br /&gt;
{&lt;br /&gt;
    string output = &amp;quot;Test String&amp;quot;;&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
---- After Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB(&amp;quot;Test String&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
public void MethodB(string output)&lt;br /&gt;
{&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring in NetBeans===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54606</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54606"/>
		<updated>2011-11-01T23:42:51Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Refactoring support in popular IDE(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; As people make changes to the code to realize their short term goals without fully understanding the design of code, the code loses its structure.  The refactoring work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape. &amp;lt;ref name=&amp;quot;reftwo&amp;quot;&amp;gt; Why should you Refactor http://sourcemaking.com/refactoring/why-should-you-refactor &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Fully autonomous factoring doesn't appear to exist at this time in the IDE(s) described below.  However there are papers &amp;lt;i&amp;gt;Inducing Evolution-Robust Pointcuts&amp;lt;/i&amp;gt; &amp;lt;Ref name=&amp;quot;refseven&amp;quot;&amp;gt;Inducing Evolution-Robust Pointcuts, Braem, M.&amp;lt;/ref&amp;gt; and &amp;lt;i&amp;gt;Automatic Refactoring of Erlang Programs&amp;lt;/i&amp;gt;&amp;lt;ref name=&amp;quot;refeight&amp;quot;&amp;gt;Automatic Refactoring of Erlang Programs http://www.ece.cmu.edu/~aavgerin/papers/PPDP09.pdf&amp;lt;/ref&amp;gt; that point the way to the future of refactoring that can be fully automated.  In the context of this wiki article, automatic refactoring means automated refactoring under programmer control and guidance.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common Refactoring Techniques==&lt;br /&gt;
===Extraction Refactoring=== &lt;br /&gt;
There are several refactoring techniques related to extraction: Extract method, Extract local variables, extract constants. The first method &amp;quot;Extract method will create a new method from code you've selected. Extract Local Variable refactoring takes an expression that is being used repeatedly and assigns it to a local variable. Extract constant refactoring is to select a static, constant expression, which the refactoring will convert to a static final constant. This is useful for removing hard-coded numbers and strings from your code&lt;br /&gt;
&lt;br /&gt;
===Inline Refactoring=== &lt;br /&gt;
This type refactoring is the reverse of local variable extraction, in which we remove a local variable and use the value of the variable(typically an expression) in the place where the variable is used. This can be marginally more efficient than using a temporary variable and, by making the code terser, makes it either easier to read or more cryptic, depending on your point of view&amp;lt;ref name=&amp;quot;refthree&amp;quot;&amp;gt; refactoring for everyone http://www.ibm.com/developerworks/library/os-ecref/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Encapsulating Fields===&lt;br /&gt;
Generally its not a good practice to expose the class attributes through public interface. Thus, Encapsulating such fields will make such fields as private or protected as appropriate and generate getters and setters for the associated field.&lt;br /&gt;
&lt;br /&gt;
===Changing Method Signature===&lt;br /&gt;
Here we change the change the parameters, visibility, and return type of a method.&lt;br /&gt;
&lt;br /&gt;
== Other Refactorings ==&lt;br /&gt;
&lt;br /&gt;
There are a multitude of refactorings.  Those that are included with RubyMine&amp;lt;ref name=&amp;quot;reffour&amp;quot;&amp;gt;RubyMine :: Ruby and Ruby on Rails IDE with smart code completion, syntax highlighting and refactoring http://www.jetbrains.com/ruby/features/ruby_ide.html#Refactorings&amp;lt;/ref&amp;gt; include:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename refactoring&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Method&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Module&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Superclass&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Constant&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Field&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Parameter&lt;br /&gt;
&amp;lt;li&amp;gt;Inline Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Pull Uo Members&lt;br /&gt;
&amp;lt;li&amp;gt;Push Down Members&lt;br /&gt;
&amp;lt;li&amp;gt;Override Method&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Martin Fowler has online resources for additional refactoring definitions which can be found here http://martinfowler.com/bliki/refactoring.html&amp;lt;ref name=&amp;quot;reffive&amp;quot;&amp;gt;MF Blicki: refactoring http://martinfowler.com/bliki/refactoring.html&amp;lt;/ref&amp;gt; and here http://refactoring.com/catalog/&amp;lt;ref name=&amp;quot;refsix&amp;quot;&amp;gt;Alpha list of refactorings http://refactoring.com/catalog/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Refactoring support in popular IDE(s)==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;font-size: 90%; text-align: center; width: auto;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! IDE&lt;br /&gt;
! Refactoring Support&lt;br /&gt;
! Automated Refactoring?&lt;br /&gt;
! Number of Refactoring support&lt;br /&gt;
! Support for Pattern&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
! Borland Delphi&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Eclipse &amp;lt;ref name='refeclipse'&amp;gt;Eclipse Refactoring Actions http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-menu-refactor.htm &amp;lt;/ref&amp;gt;&lt;br /&gt;
! Rename selected Elements, Move selected elements, Change Method Signature, Extraction, Convert Anonymous Class to Nested, Convert Local Variable to Field, Extract Super class and Interface, push down, pull up, Introduce Indirection, Encapsulate Field, Migrate JAR File, Create &amp;amp; Apply Refatoring Scripts&lt;br /&gt;
! Yes&lt;br /&gt;
! 27&lt;br /&gt;
! Introduce Factory&lt;br /&gt;
! &lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
int x= p * 5; 	&lt;br /&gt;
p.x;&lt;br /&gt;
---- After Refactoring&lt;br /&gt;
int x= getFoo(p); (Method Extraction) &lt;br /&gt;
p.getX() (Encapsulate Field)&lt;br /&gt;
|-&lt;br /&gt;
! Kdevelop&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! NetBeans &amp;lt;ref name=&amp;quot;refnetbeans&amp;quot;&amp;gt;Refactoring in NetBeans 4.1 http://java.sun.com/developer/technicalArticles/tools/refactoring/&amp;lt;/ref&amp;gt;&lt;br /&gt;
! Renaming fields, methods, classes, or packages, Encapsulating fields, Changing method parameters, Moving classes, &lt;br /&gt;
! Yes but very limited &lt;br /&gt;
! 4&lt;br /&gt;
! No&lt;br /&gt;
! &lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Foo&lt;br /&gt;
{&lt;br /&gt;
  public int n;&lt;br /&gt;
  public int Compute(int val);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
---- After Refactoring (Encapsulating field)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pubic class Foo&lt;br /&gt;
{&lt;br /&gt;
  private int n;&lt;br /&gt;
  public int getN();&lt;br /&gt;
  public void setN(int val);&lt;br /&gt;
  public int Compute(int arg);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Padre&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! RubyMine&lt;br /&gt;
! No&lt;br /&gt;
! Yes&lt;br /&gt;
! 11&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Visual Studio &amp;lt;ref name=&amp;quot;refvstudio&amp;quot;&amp;gt;7 Refactoring Methods in Visual Studio 2010 http://p2p.wrox.com/content/articles/7-refactoring-methods-visual-studio-2010 &amp;lt;/ref&amp;gt;&lt;br /&gt;
! Extract Method, Encapsulate Field, Extract Interface, Rename, Promote Variable to Parameter(Changing method signature), Generate Method Stub(Used for testing purposes)&lt;br /&gt;
! Yes&lt;br /&gt;
! 7&lt;br /&gt;
! No&lt;br /&gt;
! Promoting Variable to Parameter&lt;br /&gt;
---- Before Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB();&lt;br /&gt;
}&lt;br /&gt;
public void MethodB()&lt;br /&gt;
{&lt;br /&gt;
    string output = &amp;quot;Test String&amp;quot;;&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
---- After Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB(&amp;quot;Test String&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
public void MethodB(string output)&lt;br /&gt;
{&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring in NetBeans===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54601</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54601"/>
		<updated>2011-11-01T23:39:10Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Refactoring support in popular IDE(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; As people make changes to the code to realize their short term goals without fully understanding the design of code, the code loses its structure.  The refactoring work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape. &amp;lt;ref name=&amp;quot;reftwo&amp;quot;&amp;gt; Why should you Refactor http://sourcemaking.com/refactoring/why-should-you-refactor &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Fully autonomous factoring doesn't appear to exist at this time in the IDE(s) described below.  However there are papers &amp;lt;i&amp;gt;Inducing Evolution-Robust Pointcuts&amp;lt;/i&amp;gt; &amp;lt;Ref name=&amp;quot;refseven&amp;quot;&amp;gt;Inducing Evolution-Robust Pointcuts, Braem, M.&amp;lt;/ref&amp;gt; and &amp;lt;i&amp;gt;Automatic Refactoring of Erlang Programs&amp;lt;/i&amp;gt;&amp;lt;ref name=&amp;quot;refeight&amp;quot;&amp;gt;Automatic Refactoring of Erlang Programs http://www.ece.cmu.edu/~aavgerin/papers/PPDP09.pdf&amp;lt;/ref&amp;gt; that point the way to the future of refactoring that can be fully automated.  In the context of this wiki article, automatic refactoring means automated refactoring under programmer control and guidance.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common Refactoring Techniques==&lt;br /&gt;
===Extraction Refactoring=== &lt;br /&gt;
There are several refactoring techniques related to extraction: Extract method, Extract local variables, extract constants. The first method &amp;quot;Extract method will create a new method from code you've selected. Extract Local Variable refactoring takes an expression that is being used repeatedly and assigns it to a local variable. Extract constant refactoring is to select a static, constant expression, which the refactoring will convert to a static final constant. This is useful for removing hard-coded numbers and strings from your code&lt;br /&gt;
&lt;br /&gt;
===Inline Refactoring=== &lt;br /&gt;
This type refactoring is the reverse of local variable extraction, in which we remove a local variable and use the value of the variable(typically an expression) in the place where the variable is used. This can be marginally more efficient than using a temporary variable and, by making the code terser, makes it either easier to read or more cryptic, depending on your point of view&amp;lt;ref name=&amp;quot;refthree&amp;quot;&amp;gt; refactoring for everyone http://www.ibm.com/developerworks/library/os-ecref/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Encapsulating Fields===&lt;br /&gt;
Generally its not a good practice to expose the class attributes through public interface. Thus, Encapsulating such fields will make such fields as private or protected as appropriate and generate getters and setters for the associated field.&lt;br /&gt;
&lt;br /&gt;
===Changing Method Signature===&lt;br /&gt;
Here we change the change the parameters, visibility, and return type of a method.&lt;br /&gt;
&lt;br /&gt;
== Other Refactorings ==&lt;br /&gt;
&lt;br /&gt;
There are a multitude of refactorings.  Those that are included with RubyMine&amp;lt;ref name=&amp;quot;reffour&amp;quot;&amp;gt;RubyMine :: Ruby and Ruby on Rails IDE with smart code completion, syntax highlighting and refactoring http://www.jetbrains.com/ruby/features/ruby_ide.html#Refactorings&amp;lt;/ref&amp;gt; include:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename refactoring&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Method&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Module&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Superclass&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Constant&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Field&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Parameter&lt;br /&gt;
&amp;lt;li&amp;gt;Inline Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Pull Uo Members&lt;br /&gt;
&amp;lt;li&amp;gt;Push Down Members&lt;br /&gt;
&amp;lt;li&amp;gt;Override Method&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Martin Fowler has online resources for additional refactoring definitions which can be found here http://martinfowler.com/bliki/refactoring.html&amp;lt;ref name=&amp;quot;reffive&amp;quot;&amp;gt;MF Blicki: refactoring http://martinfowler.com/bliki/refactoring.html&amp;lt;/ref&amp;gt; and here http://refactoring.com/catalog/&amp;lt;ref name=&amp;quot;refsix&amp;quot;&amp;gt;Alpha list of refactorings http://refactoring.com/catalog/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Refactoring support in popular IDE(s)==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;font-size: 90%; text-align: center; width: auto;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! IDE&lt;br /&gt;
! Refactoring Support&lt;br /&gt;
! Automated Refactoring?&lt;br /&gt;
! Number of Refactoring support&lt;br /&gt;
! Support for Pattern&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
! Borland Delphi&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Eclipse &amp;lt;ref name='refeclipse'&amp;gt;Eclipse Refactoring Actions http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-menu-refactor.htm &amp;lt;/ref&amp;gt;&lt;br /&gt;
! Rename selected Elements, Move selected elements, Change Method Signature, Extraction, Convert Anonymous Class to Nested, Convert Local Variable to Field, Extract Super class and Interface, push down, pull up, Introduce Indirection, Encapsulate Field, Migrate JAR File, Create &amp;amp; Apply Refatoring Scripts&lt;br /&gt;
! Yes&lt;br /&gt;
! 27&lt;br /&gt;
! Introduce Factory&lt;br /&gt;
! &lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
int x= p * 5; 	&lt;br /&gt;
p.x;&lt;br /&gt;
---- After Refactoring&lt;br /&gt;
int x= getFoo(p); (Method Extraction) &lt;br /&gt;
p.getX() (Encapsulate Field)&lt;br /&gt;
|-&lt;br /&gt;
! Kdevelop&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! NetBeans &amp;lt;ref name=&amp;quot;refnetbeans&amp;quot;&amp;gt;Refactoring in NetBeans 4.1 http://java.sun.com/developer/technicalArticles/tools/refactoring/&amp;lt;/ref&amp;gt;&lt;br /&gt;
! Renaming fields, methods, classes, or packages, Encapsulating fields, Changing method parameters, Moving classes, &lt;br /&gt;
! Yes but very limited &lt;br /&gt;
! 4&lt;br /&gt;
! No&lt;br /&gt;
! &lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
public class Foo&lt;br /&gt;
{&lt;br /&gt;
  public int n;&lt;br /&gt;
  public int Compute(int val);&lt;br /&gt;
}&lt;br /&gt;
---- After Refactoring (Encapsulating field)&lt;br /&gt;
pubic class Foo&lt;br /&gt;
{&lt;br /&gt;
  private int n;&lt;br /&gt;
  public int getN();&lt;br /&gt;
  public void setN(int val);&lt;br /&gt;
  public int Compute(int arg);&lt;br /&gt;
}&lt;br /&gt;
|-&lt;br /&gt;
! Padre&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! RubyMine&lt;br /&gt;
! No&lt;br /&gt;
! Yes&lt;br /&gt;
! 11&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Visual Studio &amp;lt;ref name=&amp;quot;refvstudio&amp;quot;&amp;gt;7 Refactoring Methods in Visual Studio 2010 http://p2p.wrox.com/content/articles/7-refactoring-methods-visual-studio-2010 &amp;lt;/ref&amp;gt;&lt;br /&gt;
! Extract Method, Encapsulate Field, Extract Interface, Rename, Promote Variable to Parameter(Changing method signature), Generate Method Stub(Used for testing purposes)&lt;br /&gt;
! Yes&lt;br /&gt;
! 7&lt;br /&gt;
! No&lt;br /&gt;
! Promoting Variable to Parameter&lt;br /&gt;
---- Before Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB();&lt;br /&gt;
}&lt;br /&gt;
public void MethodB()&lt;br /&gt;
{&lt;br /&gt;
    string output = &amp;quot;Test String&amp;quot;;&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
---- After Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB(&amp;quot;Test String&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
public void MethodB(string output)&lt;br /&gt;
{&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring in NetBeans===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54600</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54600"/>
		<updated>2011-11-01T23:32:49Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Refactoring support in popular IDE(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; As people make changes to the code to realize their short term goals without fully understanding the design of code, the code loses its structure.  The refactoring work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape. &amp;lt;ref name=&amp;quot;reftwo&amp;quot;&amp;gt; Why should you Refactor http://sourcemaking.com/refactoring/why-should-you-refactor &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Fully autonomous factoring doesn't appear to exist at this time in the IDE(s) described below.  However there are papers &amp;lt;i&amp;gt;Inducing Evolution-Robust Pointcuts&amp;lt;/i&amp;gt; &amp;lt;Ref name=&amp;quot;refseven&amp;quot;&amp;gt;Inducing Evolution-Robust Pointcuts, Braem, M.&amp;lt;/ref&amp;gt; and &amp;lt;i&amp;gt;Automatic Refactoring of Erlang Programs&amp;lt;/i&amp;gt;&amp;lt;ref name=&amp;quot;refeight&amp;quot;&amp;gt;Automatic Refactoring of Erlang Programs http://www.ece.cmu.edu/~aavgerin/papers/PPDP09.pdf&amp;lt;/ref&amp;gt; that point the way to the future of refactoring that can be fully automated.  In the context of this wiki article, automatic refactoring means automated refactoring under programmer control and guidance.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common Refactoring Techniques==&lt;br /&gt;
===Extraction Refactoring=== &lt;br /&gt;
There are several refactoring techniques related to extraction: Extract method, Extract local variables, extract constants. The first method &amp;quot;Extract method will create a new method from code you've selected. Extract Local Variable refactoring takes an expression that is being used repeatedly and assigns it to a local variable. Extract constant refactoring is to select a static, constant expression, which the refactoring will convert to a static final constant. This is useful for removing hard-coded numbers and strings from your code&lt;br /&gt;
&lt;br /&gt;
===Inline Refactoring=== &lt;br /&gt;
This type refactoring is the reverse of local variable extraction, in which we remove a local variable and use the value of the variable(typically an expression) in the place where the variable is used. This can be marginally more efficient than using a temporary variable and, by making the code terser, makes it either easier to read or more cryptic, depending on your point of view&amp;lt;ref name=&amp;quot;refthree&amp;quot;&amp;gt; refactoring for everyone http://www.ibm.com/developerworks/library/os-ecref/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Encapsulating Fields===&lt;br /&gt;
Generally its not a good practice to expose the class attributes through public interface. Thus, Encapsulating such fields will make such fields as private or protected as appropriate and generate getters and setters for the associated field.&lt;br /&gt;
&lt;br /&gt;
===Changing Method Signature===&lt;br /&gt;
Here we change the change the parameters, visibility, and return type of a method.&lt;br /&gt;
&lt;br /&gt;
== Other Refactorings ==&lt;br /&gt;
&lt;br /&gt;
There are a multitude of refactorings.  Those that are included with RubyMine&amp;lt;ref name=&amp;quot;reffour&amp;quot;&amp;gt;RubyMine :: Ruby and Ruby on Rails IDE with smart code completion, syntax highlighting and refactoring http://www.jetbrains.com/ruby/features/ruby_ide.html#Refactorings&amp;lt;/ref&amp;gt; include:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename refactoring&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Method&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Module&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Superclass&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Constant&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Field&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Parameter&lt;br /&gt;
&amp;lt;li&amp;gt;Inline Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Pull Uo Members&lt;br /&gt;
&amp;lt;li&amp;gt;Push Down Members&lt;br /&gt;
&amp;lt;li&amp;gt;Override Method&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Martin Fowler has online resources for additional refactoring definitions which can be found here http://martinfowler.com/bliki/refactoring.html&amp;lt;ref name=&amp;quot;reffive&amp;quot;&amp;gt;MF Blicki: refactoring http://martinfowler.com/bliki/refactoring.html&amp;lt;/ref&amp;gt; and here http://refactoring.com/catalog/&amp;lt;ref name=&amp;quot;refsix&amp;quot;&amp;gt;Alpha list of refactorings http://refactoring.com/catalog/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Refactoring support in popular IDE(s)==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;font-size: 90%; text-align: center; width: auto;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! IDE&lt;br /&gt;
! Refactoring Support&lt;br /&gt;
! Automated Refactoring?&lt;br /&gt;
! Number of Refactoring support&lt;br /&gt;
! Support for Pattern&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
! Borland Delphi&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Eclipse &amp;lt;ref name='refeclipse'&amp;gt;Eclipse Refactoring Actions http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-menu-refactor.htm &amp;lt;/ref&amp;gt;&lt;br /&gt;
! Rename selected Elements, Move selected elements, Change Method Signature, Extraction, Convert Anonymous Class to Nested, Convert Local Variable to Field, Extract Super class and Interface, push down, pull up, Introduce Indirection, Encapsulate Field, Migrate JAR File, Create &amp;amp; Apply Refatoring Scripts&lt;br /&gt;
! Yes&lt;br /&gt;
! 27&lt;br /&gt;
! Introduce Factory&lt;br /&gt;
! &lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
int x= p * 5; 	&lt;br /&gt;
p.x;&lt;br /&gt;
---- After Refactoring&lt;br /&gt;
int x= getFoo(p); (Method Extraction) &lt;br /&gt;
p.getX() (Encapsulate Field)&lt;br /&gt;
|-&lt;br /&gt;
! Kdevelop&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! NetBeans &amp;lt;ref name=&amp;quot;refnetbeans&amp;quot;&amp;gt;Refactoring in NetBeans 4.1 http://java.sun.com/developer/technicalArticles/tools/refactoring/&amp;lt;/ref&amp;gt;&lt;br /&gt;
! Renaming fields, methods, classes, or packages, Encapsulating fields, Changing method parameters, Moving classes, &lt;br /&gt;
! Yes but very limited &lt;br /&gt;
! 4&lt;br /&gt;
! No&lt;br /&gt;
! &lt;br /&gt;
|-&lt;br /&gt;
! Padre&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! RubyMine&lt;br /&gt;
! No&lt;br /&gt;
! Yes&lt;br /&gt;
! 11&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Visual Studio &amp;lt;ref name=&amp;quot;refvstudio&amp;quot;&amp;gt;7 Refactoring Methods in Visual Studio 2010 http://p2p.wrox.com/content/articles/7-refactoring-methods-visual-studio-2010 &amp;lt;/ref&amp;gt;&lt;br /&gt;
! Extract Method, Encapsulate Field, Extract Interface, Rename, Promote Variable to Parameter(Changing method signature), Generate Method Stub(Used for testing purposes)&lt;br /&gt;
! Yes&lt;br /&gt;
! 7&lt;br /&gt;
! No&lt;br /&gt;
! Promoting Variable to Parameter&lt;br /&gt;
---- Before Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB();&lt;br /&gt;
}&lt;br /&gt;
public void MethodB()&lt;br /&gt;
{&lt;br /&gt;
    string output = &amp;quot;Test String&amp;quot;;&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
---- After Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB(&amp;quot;Test String&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
public void MethodB(string output)&lt;br /&gt;
{&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring in NetBeans===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54596</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54596"/>
		<updated>2011-11-01T23:22:31Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Refactoring support in popular IDE(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; As people make changes to the code to realize their short term goals without fully understanding the design of code, the code loses its structure.  The refactoring work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape. &amp;lt;ref name=&amp;quot;reftwo&amp;quot;&amp;gt; Why should you Refactor http://sourcemaking.com/refactoring/why-should-you-refactor &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Fully autonomous factoring doesn't appear to exist at this time in the IDE(s) described below.  However there are papers &amp;lt;i&amp;gt;Inducing Evolution-Robust Pointcuts&amp;lt;/i&amp;gt; &amp;lt;Ref name=&amp;quot;refseven&amp;quot;&amp;gt;Inducing Evolution-Robust Pointcuts, Braem, M.&amp;lt;/ref&amp;gt; and &amp;lt;i&amp;gt;Automatic Refactoring of Erlang Programs&amp;lt;/i&amp;gt;&amp;lt;ref name=&amp;quot;refeight&amp;quot;&amp;gt;Automatic Refactoring of Erlang Programs http://www.ece.cmu.edu/~aavgerin/papers/PPDP09.pdf&amp;lt;/ref&amp;gt; that point the way to the future of refactoring that can be fully automated.  In the context of this wiki article, automatic refactoring means automated refactoring under programmer control and guidance.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common Refactoring Techniques==&lt;br /&gt;
===Extraction Refactoring=== &lt;br /&gt;
There are several refactoring techniques related to extraction: Extract method, Extract local variables, extract constants. The first method &amp;quot;Extract method will create a new method from code you've selected. Extract Local Variable refactoring takes an expression that is being used repeatedly and assigns it to a local variable. Extract constant refactoring is to select a static, constant expression, which the refactoring will convert to a static final constant. This is useful for removing hard-coded numbers and strings from your code&lt;br /&gt;
&lt;br /&gt;
===Inline Refactoring=== &lt;br /&gt;
This type refactoring is the reverse of local variable extraction, in which we remove a local variable and use the value of the variable(typically an expression) in the place where the variable is used. This can be marginally more efficient than using a temporary variable and, by making the code terser, makes it either easier to read or more cryptic, depending on your point of view&amp;lt;ref name=&amp;quot;refthree&amp;quot;&amp;gt; refactoring for everyone http://www.ibm.com/developerworks/library/os-ecref/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Encapsulating Fields===&lt;br /&gt;
Generally its not a good practice to expose the class attributes through public interface. Thus, Encapsulating such fields will make such fields as private or protected as appropriate and generate getters and setters for the associated field.&lt;br /&gt;
&lt;br /&gt;
===Changing Method Signature===&lt;br /&gt;
Here we change the change the parameters, visibility, and return type of a method.&lt;br /&gt;
&lt;br /&gt;
== Other Refactorings ==&lt;br /&gt;
&lt;br /&gt;
There are a multitude of refactorings.  Those that are included with RubyMine&amp;lt;ref name=&amp;quot;reffour&amp;quot;&amp;gt;RubyMine :: Ruby and Ruby on Rails IDE with smart code completion, syntax highlighting and refactoring http://www.jetbrains.com/ruby/features/ruby_ide.html#Refactorings&amp;lt;/ref&amp;gt; include:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename refactoring&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Method&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Module&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Superclass&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Constant&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Field&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Parameter&lt;br /&gt;
&amp;lt;li&amp;gt;Inline Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Pull Uo Members&lt;br /&gt;
&amp;lt;li&amp;gt;Push Down Members&lt;br /&gt;
&amp;lt;li&amp;gt;Override Method&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Martin Fowler has online resources for additional refactoring definitions which can be found here http://martinfowler.com/bliki/refactoring.html&amp;lt;ref name=&amp;quot;reffive&amp;quot;&amp;gt;MF Blicki: refactoring http://martinfowler.com/bliki/refactoring.html&amp;lt;/ref&amp;gt; and here http://refactoring.com/catalog/&amp;lt;ref name=&amp;quot;refsix&amp;quot;&amp;gt;Alpha list of refactorings http://refactoring.com/catalog/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Refactoring support in popular IDE(s)==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;font-size: 90%; text-align: center; width: auto;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! IDE&lt;br /&gt;
! Refactoring Support&lt;br /&gt;
! Automated Refactoring?&lt;br /&gt;
! Number of Refactoring support&lt;br /&gt;
! Support for Pattern&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
! Borland Delphi&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Eclipse &amp;lt;ref name='refeclipse'&amp;gt;Eclipse Refactoring Actions http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-menu-refactor.htm &amp;lt;/ref&amp;gt;&lt;br /&gt;
! Rename selected Elements, Move selected elements, Change Method Signature, Extraction, Convert Anonymous Class to Nested, Convert Local Variable to Field, Extract Super class and Interface, push down, pull up, Introduce Indirection, Encapsulate Field, Migrate JAR File, Create &amp;amp; Apply Refatoring Scripts&lt;br /&gt;
! Yes&lt;br /&gt;
! 27&lt;br /&gt;
! Introduce Factory&lt;br /&gt;
! &lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
int x= p * 5; 	&lt;br /&gt;
p.x;&lt;br /&gt;
---- After Refactoring&lt;br /&gt;
int x= getFoo(p); (Method Extraction) &lt;br /&gt;
p.getX() (Encapsulate Field)&lt;br /&gt;
|-&lt;br /&gt;
! Kdevelop&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! NetBeans&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Padre&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! RubyMine&lt;br /&gt;
! No&lt;br /&gt;
! Yes&lt;br /&gt;
! 11&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Visual Studio &amp;lt;ref name=&amp;quot;refvstudio&amp;quot;&amp;gt;7 Refactoring Methods in Visual Studio 2010 http://p2p.wrox.com/content/articles/7-refactoring-methods-visual-studio-2010 &amp;lt;/ref&amp;gt;&lt;br /&gt;
! Extract Method, Encapsulate Field, Extract Interface, Rename, Promote Variable to Parameter(Changing method signature), Generate Method Stub(Used for testing purposes)&lt;br /&gt;
! Yes&lt;br /&gt;
! 7&lt;br /&gt;
! No&lt;br /&gt;
! Promoting Variable to Parameter&lt;br /&gt;
---- Before Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB();&lt;br /&gt;
}&lt;br /&gt;
public void MethodB()&lt;br /&gt;
{&lt;br /&gt;
    string output = &amp;quot;Test String&amp;quot;;&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
---- After Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB(&amp;quot;Test String&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
public void MethodB(string output)&lt;br /&gt;
{&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring in NetBeans===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54594</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54594"/>
		<updated>2011-11-01T23:21:27Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Refactoring support in popular IDE(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; As people make changes to the code to realize their short term goals without fully understanding the design of code, the code loses its structure.  The refactoring work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape. &amp;lt;ref name=&amp;quot;reftwo&amp;quot;&amp;gt; Why should you Refactor http://sourcemaking.com/refactoring/why-should-you-refactor &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Fully autonomous factoring doesn't appear to exist at this time in the IDE(s) described below.  However there are papers &amp;lt;i&amp;gt;Inducing Evolution-Robust Pointcuts&amp;lt;/i&amp;gt; &amp;lt;Ref name=&amp;quot;refseven&amp;quot;&amp;gt;Inducing Evolution-Robust Pointcuts, Braem, M.&amp;lt;/ref&amp;gt; and &amp;lt;i&amp;gt;Automatic Refactoring of Erlang Programs&amp;lt;/i&amp;gt;&amp;lt;ref name=&amp;quot;refeight&amp;quot;&amp;gt;Automatic Refactoring of Erlang Programs http://www.ece.cmu.edu/~aavgerin/papers/PPDP09.pdf&amp;lt;/ref&amp;gt; that point the way to the future of refactoring that can be fully automated.  In the context of this wiki article, automatic refactoring means automated refactoring under programmer control and guidance.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common Refactoring Techniques==&lt;br /&gt;
===Extraction Refactoring=== &lt;br /&gt;
There are several refactoring techniques related to extraction: Extract method, Extract local variables, extract constants. The first method &amp;quot;Extract method will create a new method from code you've selected. Extract Local Variable refactoring takes an expression that is being used repeatedly and assigns it to a local variable. Extract constant refactoring is to select a static, constant expression, which the refactoring will convert to a static final constant. This is useful for removing hard-coded numbers and strings from your code&lt;br /&gt;
&lt;br /&gt;
===Inline Refactoring=== &lt;br /&gt;
This type refactoring is the reverse of local variable extraction, in which we remove a local variable and use the value of the variable(typically an expression) in the place where the variable is used. This can be marginally more efficient than using a temporary variable and, by making the code terser, makes it either easier to read or more cryptic, depending on your point of view&amp;lt;ref name=&amp;quot;refthree&amp;quot;&amp;gt; refactoring for everyone http://www.ibm.com/developerworks/library/os-ecref/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Encapsulating Fields===&lt;br /&gt;
Generally its not a good practice to expose the class attributes through public interface. Thus, Encapsulating such fields will make such fields as private or protected as appropriate and generate getters and setters for the associated field.&lt;br /&gt;
&lt;br /&gt;
===Changing Method Signature===&lt;br /&gt;
Here we change the change the parameters, visibility, and return type of a method.&lt;br /&gt;
&lt;br /&gt;
== Other Refactorings ==&lt;br /&gt;
&lt;br /&gt;
There are a multitude of refactorings.  Those that are included with RubyMine&amp;lt;ref name=&amp;quot;reffour&amp;quot;&amp;gt;RubyMine :: Ruby and Ruby on Rails IDE with smart code completion, syntax highlighting and refactoring http://www.jetbrains.com/ruby/features/ruby_ide.html#Refactorings&amp;lt;/ref&amp;gt; include:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename refactoring&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Method&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Module&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Superclass&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Constant&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Field&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Parameter&lt;br /&gt;
&amp;lt;li&amp;gt;Inline Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Pull Uo Members&lt;br /&gt;
&amp;lt;li&amp;gt;Push Down Members&lt;br /&gt;
&amp;lt;li&amp;gt;Override Method&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Martin Fowler has online resources for additional refactoring definitions which can be found here http://martinfowler.com/bliki/refactoring.html&amp;lt;ref name=&amp;quot;reffive&amp;quot;&amp;gt;MF Blicki: refactoring http://martinfowler.com/bliki/refactoring.html&amp;lt;/ref&amp;gt; and here http://refactoring.com/catalog/&amp;lt;ref name=&amp;quot;refsix&amp;quot;&amp;gt;Alpha list of refactorings http://refactoring.com/catalog/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Refactoring support in popular IDE(s)==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;font-size: 90%; text-align: center; width: auto;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! IDE&lt;br /&gt;
! Refactoring Support&lt;br /&gt;
! Automated Refactoring?&lt;br /&gt;
! Number of Refactoring support&lt;br /&gt;
! Support for Pattern&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
! Borland Delphi&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Eclipse &amp;lt;ref name='refeclipse'&amp;gt;Eclipse Refactoring Actions http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-menu-refactor.htm &amp;lt;/ref&amp;gt;&lt;br /&gt;
! Rename selected Elements, Move selected elements, Change Method Signature, Extraction, Convert Anonymous Class to Nested, Convert Local Variable to Field, Extract Super class and Interface, push down, pull up, Introduce Indirection, Encapsulate Field, Migrate JAR File, Create &amp;amp; Apply Refatoring Scripts&lt;br /&gt;
! Yes&lt;br /&gt;
! 27&lt;br /&gt;
! Introduce Factory&lt;br /&gt;
! &lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
int x= p * 5; 	&lt;br /&gt;
p.x;&lt;br /&gt;
---- After Refactoring&lt;br /&gt;
int x= getFoo(p); (Method Extraction) &lt;br /&gt;
p.getX() (Encapsulate Field)&lt;br /&gt;
|-&lt;br /&gt;
! Kdevelop&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! NetBeans&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Padre&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! RubyMine&lt;br /&gt;
! No&lt;br /&gt;
! Yes&lt;br /&gt;
! 11&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Visual Studio &amp;lt;ref name=&amp;quot;refvstudio&amp;quot;&amp;gt;7 Refactoring Methods in Visual Studio 2010 http://p2p.wrox.com/content/articles/7-refactoring-methods-visual-studio-2010 &amp;lt;/ref&amp;gt;&lt;br /&gt;
! Extract Method, Encapsulate Field, Extract Interface, Rename, Promote Variable to Parameter(Changing method signature), Generate Method Stub(Used for testing purposes)&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
! Promoting Variable to Parameter&lt;br /&gt;
---- Before Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB();&lt;br /&gt;
}&lt;br /&gt;
public void MethodB()&lt;br /&gt;
{&lt;br /&gt;
    string output = &amp;quot;Test String&amp;quot;;&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
---- After Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB(&amp;quot;Test String&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
public void MethodB(string output)&lt;br /&gt;
{&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring in NetBeans===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54593</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54593"/>
		<updated>2011-11-01T23:21:09Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Refactoring support in popular IDE(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; As people make changes to the code to realize their short term goals without fully understanding the design of code, the code loses its structure.  The refactoring work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape. &amp;lt;ref name=&amp;quot;reftwo&amp;quot;&amp;gt; Why should you Refactor http://sourcemaking.com/refactoring/why-should-you-refactor &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Fully autonomous factoring doesn't appear to exist at this time in the IDE(s) described below.  However there are papers &amp;lt;i&amp;gt;Inducing Evolution-Robust Pointcuts&amp;lt;/i&amp;gt; &amp;lt;Ref name=&amp;quot;refseven&amp;quot;&amp;gt;Inducing Evolution-Robust Pointcuts, Braem, M.&amp;lt;/ref&amp;gt; and &amp;lt;i&amp;gt;Automatic Refactoring of Erlang Programs&amp;lt;/i&amp;gt;&amp;lt;ref name=&amp;quot;refeight&amp;quot;&amp;gt;Automatic Refactoring of Erlang Programs http://www.ece.cmu.edu/~aavgerin/papers/PPDP09.pdf&amp;lt;/ref&amp;gt; that point the way to the future of refactoring that can be fully automated.  In the context of this wiki article, automatic refactoring means automated refactoring under programmer control and guidance.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common Refactoring Techniques==&lt;br /&gt;
===Extraction Refactoring=== &lt;br /&gt;
There are several refactoring techniques related to extraction: Extract method, Extract local variables, extract constants. The first method &amp;quot;Extract method will create a new method from code you've selected. Extract Local Variable refactoring takes an expression that is being used repeatedly and assigns it to a local variable. Extract constant refactoring is to select a static, constant expression, which the refactoring will convert to a static final constant. This is useful for removing hard-coded numbers and strings from your code&lt;br /&gt;
&lt;br /&gt;
===Inline Refactoring=== &lt;br /&gt;
This type refactoring is the reverse of local variable extraction, in which we remove a local variable and use the value of the variable(typically an expression) in the place where the variable is used. This can be marginally more efficient than using a temporary variable and, by making the code terser, makes it either easier to read or more cryptic, depending on your point of view&amp;lt;ref name=&amp;quot;refthree&amp;quot;&amp;gt; refactoring for everyone http://www.ibm.com/developerworks/library/os-ecref/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Encapsulating Fields===&lt;br /&gt;
Generally its not a good practice to expose the class attributes through public interface. Thus, Encapsulating such fields will make such fields as private or protected as appropriate and generate getters and setters for the associated field.&lt;br /&gt;
&lt;br /&gt;
===Changing Method Signature===&lt;br /&gt;
Here we change the change the parameters, visibility, and return type of a method.&lt;br /&gt;
&lt;br /&gt;
== Other Refactorings ==&lt;br /&gt;
&lt;br /&gt;
There are a multitude of refactorings.  Those that are included with RubyMine&amp;lt;ref name=&amp;quot;reffour&amp;quot;&amp;gt;RubyMine :: Ruby and Ruby on Rails IDE with smart code completion, syntax highlighting and refactoring http://www.jetbrains.com/ruby/features/ruby_ide.html#Refactorings&amp;lt;/ref&amp;gt; include:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename refactoring&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Method&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Module&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Superclass&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Constant&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Field&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Parameter&lt;br /&gt;
&amp;lt;li&amp;gt;Inline Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Pull Uo Members&lt;br /&gt;
&amp;lt;li&amp;gt;Push Down Members&lt;br /&gt;
&amp;lt;li&amp;gt;Override Method&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Martin Fowler has online resources for additional refactoring definitions which can be found here http://martinfowler.com/bliki/refactoring.html&amp;lt;ref name=&amp;quot;reffive&amp;quot;&amp;gt;MF Blicki: refactoring http://martinfowler.com/bliki/refactoring.html&amp;lt;/ref&amp;gt; and here http://refactoring.com/catalog/&amp;lt;ref name=&amp;quot;refsix&amp;quot;&amp;gt;Alpha list of refactorings http://refactoring.com/catalog/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Refactoring support in popular IDE(s)==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;font-size: 90%; text-align: center; width: auto;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! IDE&lt;br /&gt;
! Refactoring Support&lt;br /&gt;
! Automated Refactoring?&lt;br /&gt;
! Number of Refactoring support&lt;br /&gt;
! Support for Pattern&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
! Borland Delphi&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Eclipse &amp;lt;ref name='refeclipse'&amp;gt;Eclipse Refactoring Actions http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-menu-refactor.htm &amp;lt;/ref&amp;gt;&lt;br /&gt;
! Rename selected Elements, Move selected elements, Change Method Signature, Extraction, Convert Anonymous Class to Nested, Convert Local Variable to Field, Extract Super class and Interface, push down, pull up, Introduce Indirection, Encapsulate Field, Migrate JAR File, Create &amp;amp; Apply Refatoring Scripts&lt;br /&gt;
! Yes&lt;br /&gt;
! 27&lt;br /&gt;
! Introduce Factory&lt;br /&gt;
!&lt;br /&gt;
! &lt;br /&gt;
---- Before Refactoring&lt;br /&gt;
int x= p * 5; 	&lt;br /&gt;
p.x;&lt;br /&gt;
---- After Refactoring&lt;br /&gt;
int x= getFoo(p); (Method Extraction) &lt;br /&gt;
p.getX() (Encapsulate Field)&lt;br /&gt;
|-&lt;br /&gt;
! Kdevelop&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! NetBeans&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Padre&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! RubyMine&lt;br /&gt;
! No&lt;br /&gt;
! Yes&lt;br /&gt;
! 11&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Visual Studio &amp;lt;ref name=&amp;quot;refvstudio&amp;quot;&amp;gt;7 Refactoring Methods in Visual Studio 2010 http://p2p.wrox.com/content/articles/7-refactoring-methods-visual-studio-2010 &amp;lt;/ref&amp;gt;&lt;br /&gt;
! Extract Method, Encapsulate Field, Extract Interface, Rename, Promote Variable to Parameter(Changing method signature), Generate Method Stub(Used for testing purposes)&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
! Promoting Variable to Parameter&lt;br /&gt;
---- Before Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB();&lt;br /&gt;
}&lt;br /&gt;
public void MethodB()&lt;br /&gt;
{&lt;br /&gt;
    string output = &amp;quot;Test String&amp;quot;;&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
---- After Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB(&amp;quot;Test String&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
public void MethodB(string output)&lt;br /&gt;
{&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring in NetBeans===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54592</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54592"/>
		<updated>2011-11-01T23:19:14Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Refactoring support in popular IDE(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; As people make changes to the code to realize their short term goals without fully understanding the design of code, the code loses its structure.  The refactoring work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape. &amp;lt;ref name=&amp;quot;reftwo&amp;quot;&amp;gt; Why should you Refactor http://sourcemaking.com/refactoring/why-should-you-refactor &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Fully autonomous factoring doesn't appear to exist at this time in the IDE(s) described below.  However there are papers &amp;lt;i&amp;gt;Inducing Evolution-Robust Pointcuts&amp;lt;/i&amp;gt; &amp;lt;Ref name=&amp;quot;refseven&amp;quot;&amp;gt;Inducing Evolution-Robust Pointcuts, Braem, M.&amp;lt;/ref&amp;gt; and &amp;lt;i&amp;gt;Automatic Refactoring of Erlang Programs&amp;lt;/i&amp;gt;&amp;lt;ref name=&amp;quot;refeight&amp;quot;&amp;gt;Automatic Refactoring of Erlang Programs http://www.ece.cmu.edu/~aavgerin/papers/PPDP09.pdf&amp;lt;/ref&amp;gt; that point the way to the future of refactoring that can be fully automated.  In the context of this wiki article, automatic refactoring means automated refactoring under programmer control and guidance.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common Refactoring Techniques==&lt;br /&gt;
===Extraction Refactoring=== &lt;br /&gt;
There are several refactoring techniques related to extraction: Extract method, Extract local variables, extract constants. The first method &amp;quot;Extract method will create a new method from code you've selected. Extract Local Variable refactoring takes an expression that is being used repeatedly and assigns it to a local variable. Extract constant refactoring is to select a static, constant expression, which the refactoring will convert to a static final constant. This is useful for removing hard-coded numbers and strings from your code&lt;br /&gt;
&lt;br /&gt;
===Inline Refactoring=== &lt;br /&gt;
This type refactoring is the reverse of local variable extraction, in which we remove a local variable and use the value of the variable(typically an expression) in the place where the variable is used. This can be marginally more efficient than using a temporary variable and, by making the code terser, makes it either easier to read or more cryptic, depending on your point of view&amp;lt;ref name=&amp;quot;refthree&amp;quot;&amp;gt; refactoring for everyone http://www.ibm.com/developerworks/library/os-ecref/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Encapsulating Fields===&lt;br /&gt;
Generally its not a good practice to expose the class attributes through public interface. Thus, Encapsulating such fields will make such fields as private or protected as appropriate and generate getters and setters for the associated field.&lt;br /&gt;
&lt;br /&gt;
===Changing Method Signature===&lt;br /&gt;
Here we change the change the parameters, visibility, and return type of a method.&lt;br /&gt;
&lt;br /&gt;
== Other Refactorings ==&lt;br /&gt;
&lt;br /&gt;
There are a multitude of refactorings.  Those that are included with RubyMine&amp;lt;ref name=&amp;quot;reffour&amp;quot;&amp;gt;RubyMine :: Ruby and Ruby on Rails IDE with smart code completion, syntax highlighting and refactoring http://www.jetbrains.com/ruby/features/ruby_ide.html#Refactorings&amp;lt;/ref&amp;gt; include:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename refactoring&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Method&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Module&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Superclass&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Constant&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Field&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Parameter&lt;br /&gt;
&amp;lt;li&amp;gt;Inline Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Pull Uo Members&lt;br /&gt;
&amp;lt;li&amp;gt;Push Down Members&lt;br /&gt;
&amp;lt;li&amp;gt;Override Method&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Martin Fowler has online resources for additional refactoring definitions which can be found here http://martinfowler.com/bliki/refactoring.html&amp;lt;ref name=&amp;quot;reffive&amp;quot;&amp;gt;MF Blicki: refactoring http://martinfowler.com/bliki/refactoring.html&amp;lt;/ref&amp;gt; and here http://refactoring.com/catalog/&amp;lt;ref name=&amp;quot;refsix&amp;quot;&amp;gt;Alpha list of refactorings http://refactoring.com/catalog/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Refactoring support in popular IDE(s)==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;font-size: 90%; text-align: center; width: auto;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! IDE&lt;br /&gt;
! Refactoring Support&lt;br /&gt;
! Automated Refactoring?&lt;br /&gt;
! Number of Refactoring support&lt;br /&gt;
! Support for Pattern&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
! Borland Delphi&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Eclipse &amp;lt;ref name='refeclipse'&amp;gt;Eclipse Refactoring Actions http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-menu-refactor.htm &amp;lt;/ref&amp;gt;&lt;br /&gt;
! Rename selected Elements, Move selected elements, Change Method Signature, Extraction, Convert Anonymous Class to Nested, Convert Local Variable to Field, Extract Super class and Interface, push down, pull up, Introduce Indirection, Encapsulate Field, Migrate JAR File, Create &amp;amp; Apply Refatoring Scripts&lt;br /&gt;
! Yes&lt;br /&gt;
! 27&lt;br /&gt;
! Introduce Factory, &lt;br /&gt;
! int x= p * 5; 	&amp;gt; 	int x= getFoo(p); (Method Extraction) , p.x; 	&amp;gt; 	p.getX() (Encapsulate Field)&lt;br /&gt;
|-&lt;br /&gt;
! Kdevelop&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! NetBeans&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Padre&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! RubyMine&lt;br /&gt;
! No&lt;br /&gt;
! Yes&lt;br /&gt;
! 11&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Visual Studio &amp;lt;ref name=&amp;quot;refvstudio&amp;quot;&amp;gt;7 Refactoring Methods in Visual Studio 2010 http://p2p.wrox.com/content/articles/7-refactoring-methods-visual-studio-2010 &amp;lt;/ref&amp;gt;&lt;br /&gt;
! Extract Method, Encapsulate Field, Extract Interface, Rename, Promote Variable to Parameter(Changing method signature), Generate Method Stub(Used for testing purposes)&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
! Promoting Variable to Parameter&lt;br /&gt;
---- Before Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB();&lt;br /&gt;
}&lt;br /&gt;
public void MethodB()&lt;br /&gt;
{&lt;br /&gt;
    string output = &amp;quot;Test String&amp;quot;;&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
---- After Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB(&amp;quot;Test String&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
public void MethodB(string output)&lt;br /&gt;
{&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring in NetBeans===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54591</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54591"/>
		<updated>2011-11-01T23:17:40Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Refactoring support in popular IDE(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; As people make changes to the code to realize their short term goals without fully understanding the design of code, the code loses its structure.  The refactoring work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape. &amp;lt;ref name=&amp;quot;reftwo&amp;quot;&amp;gt; Why should you Refactor http://sourcemaking.com/refactoring/why-should-you-refactor &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Fully autonomous factoring doesn't appear to exist at this time in the IDE(s) described below.  However there are papers &amp;lt;i&amp;gt;Inducing Evolution-Robust Pointcuts&amp;lt;/i&amp;gt; &amp;lt;Ref name=&amp;quot;refseven&amp;quot;&amp;gt;Inducing Evolution-Robust Pointcuts, Braem, M.&amp;lt;/ref&amp;gt; and &amp;lt;i&amp;gt;Automatic Refactoring of Erlang Programs&amp;lt;/i&amp;gt;&amp;lt;ref name=&amp;quot;refeight&amp;quot;&amp;gt;Automatic Refactoring of Erlang Programs http://www.ece.cmu.edu/~aavgerin/papers/PPDP09.pdf&amp;lt;/ref&amp;gt; that point the way to the future of refactoring that can be fully automated.  In the context of this wiki article, automatic refactoring means automated refactoring under programmer control and guidance.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common Refactoring Techniques==&lt;br /&gt;
===Extraction Refactoring=== &lt;br /&gt;
There are several refactoring techniques related to extraction: Extract method, Extract local variables, extract constants. The first method &amp;quot;Extract method will create a new method from code you've selected. Extract Local Variable refactoring takes an expression that is being used repeatedly and assigns it to a local variable. Extract constant refactoring is to select a static, constant expression, which the refactoring will convert to a static final constant. This is useful for removing hard-coded numbers and strings from your code&lt;br /&gt;
&lt;br /&gt;
===Inline Refactoring=== &lt;br /&gt;
This type refactoring is the reverse of local variable extraction, in which we remove a local variable and use the value of the variable(typically an expression) in the place where the variable is used. This can be marginally more efficient than using a temporary variable and, by making the code terser, makes it either easier to read or more cryptic, depending on your point of view&amp;lt;ref name=&amp;quot;refthree&amp;quot;&amp;gt; refactoring for everyone http://www.ibm.com/developerworks/library/os-ecref/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Encapsulating Fields===&lt;br /&gt;
Generally its not a good practice to expose the class attributes through public interface. Thus, Encapsulating such fields will make such fields as private or protected as appropriate and generate getters and setters for the associated field.&lt;br /&gt;
&lt;br /&gt;
===Changing Method Signature===&lt;br /&gt;
Here we change the change the parameters, visibility, and return type of a method.&lt;br /&gt;
&lt;br /&gt;
== Other Refactorings ==&lt;br /&gt;
&lt;br /&gt;
There are a multitude of refactorings.  Those that are included with RubyMine&amp;lt;ref name=&amp;quot;reffour&amp;quot;&amp;gt;RubyMine :: Ruby and Ruby on Rails IDE with smart code completion, syntax highlighting and refactoring http://www.jetbrains.com/ruby/features/ruby_ide.html#Refactorings&amp;lt;/ref&amp;gt; include:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename refactoring&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Method&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Module&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Superclass&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Constant&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Field&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Parameter&lt;br /&gt;
&amp;lt;li&amp;gt;Inline Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Pull Uo Members&lt;br /&gt;
&amp;lt;li&amp;gt;Push Down Members&lt;br /&gt;
&amp;lt;li&amp;gt;Override Method&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Martin Fowler has online resources for additional refactoring definitions which can be found here http://martinfowler.com/bliki/refactoring.html&amp;lt;ref name=&amp;quot;reffive&amp;quot;&amp;gt;MF Blicki: refactoring http://martinfowler.com/bliki/refactoring.html&amp;lt;/ref&amp;gt; and here http://refactoring.com/catalog/&amp;lt;ref name=&amp;quot;refsix&amp;quot;&amp;gt;Alpha list of refactorings http://refactoring.com/catalog/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Refactoring support in popular IDE(s)==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;font-size: 90%; text-align: center; width: auto;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! IDE&lt;br /&gt;
! Refactoring Support&lt;br /&gt;
! Automated Refactoring?&lt;br /&gt;
! Number of Refactoring support&lt;br /&gt;
! Support for Pattern&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
! Borland Delphi&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Eclipse &amp;lt;ref name='refeclipse'&amp;gt;Eclipse Refactoring Actions http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-menu-refactor.htm &amp;lt;/ref&amp;gt;&lt;br /&gt;
! Rename selected Elements, Move selected elements, Change Method Signature, Extraction, Convert Anonymous Class to Nested, Convert Local Variable to Field, Extract Super class and Interface, push down, pull up, Introduce Indirection, Encapsulate Field, Migrate JAR File, Create &amp;amp; Apply Refatoring Scripts&lt;br /&gt;
!&lt;br /&gt;
! Yes&lt;br /&gt;
! Introduce Factory, &lt;br /&gt;
! int x= p * 5; 	&amp;gt; 	int x= getFoo(p); (Method Extraction) , p.x; 	&amp;gt; 	p.getX() (Encapsulate Field)&lt;br /&gt;
|-&lt;br /&gt;
! Kdevelop&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! NetBeans&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Padre&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! RubyMine&lt;br /&gt;
! No&lt;br /&gt;
! Yes&lt;br /&gt;
! 11&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Visual Studio &amp;lt;ref name=&amp;quot;refvstudio&amp;quot;&amp;gt;7 Refactoring Methods in Visual Studio 2010 http://p2p.wrox.com/content/articles/7-refactoring-methods-visual-studio-2010 &amp;lt;/ref&amp;gt;&lt;br /&gt;
! Extract Method, Encapsulate Field, Extract Interface, Rename, Promote Variable to Parameter(Changing method signature), Generate Method Stub(Used for testing purposes)&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
! Promoting Variable to Parameter&lt;br /&gt;
---- Before Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB();&lt;br /&gt;
}&lt;br /&gt;
public void MethodB()&lt;br /&gt;
{&lt;br /&gt;
    string output = &amp;quot;Test String&amp;quot;;&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
---- After Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB(&amp;quot;Test String&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
public void MethodB(string output)&lt;br /&gt;
{&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring in NetBeans===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54590</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54590"/>
		<updated>2011-11-01T23:16:15Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Refactoring support in popular IDE(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; As people make changes to the code to realize their short term goals without fully understanding the design of code, the code loses its structure.  The refactoring work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape. &amp;lt;ref name=&amp;quot;reftwo&amp;quot;&amp;gt; Why should you Refactor http://sourcemaking.com/refactoring/why-should-you-refactor &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Fully autonomous factoring doesn't appear to exist at this time in the IDE(s) described below.  However there are papers &amp;lt;i&amp;gt;Inducing Evolution-Robust Pointcuts&amp;lt;/i&amp;gt; &amp;lt;Ref name=&amp;quot;refseven&amp;quot;&amp;gt;Inducing Evolution-Robust Pointcuts, Braem, M.&amp;lt;/ref&amp;gt; and &amp;lt;i&amp;gt;Automatic Refactoring of Erlang Programs&amp;lt;/i&amp;gt;&amp;lt;ref name=&amp;quot;refeight&amp;quot;&amp;gt;Automatic Refactoring of Erlang Programs http://www.ece.cmu.edu/~aavgerin/papers/PPDP09.pdf&amp;lt;/ref&amp;gt; that point the way to the future of refactoring that can be fully automated.  In the context of this wiki article, automatic refactoring means automated refactoring under programmer control and guidance.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common Refactoring Techniques==&lt;br /&gt;
===Extraction Refactoring=== &lt;br /&gt;
There are several refactoring techniques related to extraction: Extract method, Extract local variables, extract constants. The first method &amp;quot;Extract method will create a new method from code you've selected. Extract Local Variable refactoring takes an expression that is being used repeatedly and assigns it to a local variable. Extract constant refactoring is to select a static, constant expression, which the refactoring will convert to a static final constant. This is useful for removing hard-coded numbers and strings from your code&lt;br /&gt;
&lt;br /&gt;
===Inline Refactoring=== &lt;br /&gt;
This type refactoring is the reverse of local variable extraction, in which we remove a local variable and use the value of the variable(typically an expression) in the place where the variable is used. This can be marginally more efficient than using a temporary variable and, by making the code terser, makes it either easier to read or more cryptic, depending on your point of view&amp;lt;ref name=&amp;quot;refthree&amp;quot;&amp;gt; refactoring for everyone http://www.ibm.com/developerworks/library/os-ecref/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Encapsulating Fields===&lt;br /&gt;
Generally its not a good practice to expose the class attributes through public interface. Thus, Encapsulating such fields will make such fields as private or protected as appropriate and generate getters and setters for the associated field.&lt;br /&gt;
&lt;br /&gt;
===Changing Method Signature===&lt;br /&gt;
Here we change the change the parameters, visibility, and return type of a method.&lt;br /&gt;
&lt;br /&gt;
== Other Refactorings ==&lt;br /&gt;
&lt;br /&gt;
There are a multitude of refactorings.  Those that are included with RubyMine&amp;lt;ref name=&amp;quot;reffour&amp;quot;&amp;gt;RubyMine :: Ruby and Ruby on Rails IDE with smart code completion, syntax highlighting and refactoring http://www.jetbrains.com/ruby/features/ruby_ide.html#Refactorings&amp;lt;/ref&amp;gt; include:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename refactoring&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Method&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Module&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Superclass&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Constant&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Field&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Parameter&lt;br /&gt;
&amp;lt;li&amp;gt;Inline Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Pull Uo Members&lt;br /&gt;
&amp;lt;li&amp;gt;Push Down Members&lt;br /&gt;
&amp;lt;li&amp;gt;Override Method&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Martin Fowler has online resources for additional refactoring definitions which can be found here http://martinfowler.com/bliki/refactoring.html&amp;lt;ref name=&amp;quot;reffive&amp;quot;&amp;gt;MF Blicki: refactoring http://martinfowler.com/bliki/refactoring.html&amp;lt;/ref&amp;gt; and here http://refactoring.com/catalog/&amp;lt;ref name=&amp;quot;refsix&amp;quot;&amp;gt;Alpha list of refactorings http://refactoring.com/catalog/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Refactoring support in popular IDE(s)==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;font-size: 90%; text-align: center; width: auto;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! IDE&lt;br /&gt;
! Refactoring Support&lt;br /&gt;
! Automated Refactoring?&lt;br /&gt;
! Number of Refactoring support&lt;br /&gt;
! Support for Pattern&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
! Borland Delphi&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Eclipse &amp;lt;ref name='refeclipse'&amp;gt;Eclipse Refactoring Actions http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-menu-refactor.htm &amp;lt;/ref&amp;gt;&lt;br /&gt;
! Rename selected Elements, Move selected elements, Change Method Signature, Extraction, Convert Anonymous Class to Nested, Convert Local Variable to Field, Extract Super class and Interface, push down, pull up, Introduce Indirection, Encapsulate Field, Migrate JAR File, Create &amp;amp; Apply Refatoring Scripts&lt;br /&gt;
!&lt;br /&gt;
! Yes&lt;br /&gt;
! Introduce Factory, &lt;br /&gt;
! int x= p * 5; 	&amp;gt; 	int x= getFoo(p); (Method Extraction) , p.x; 	&amp;gt; 	p.getX() (Encapsulate Field)&lt;br /&gt;
|-&lt;br /&gt;
! Kdevelop&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! NetBeans&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Padre&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! RubyMine&lt;br /&gt;
! No&lt;br /&gt;
! Yes&lt;br /&gt;
! 11&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Visual Studio&lt;br /&gt;
! Extract Method, Encapsulate Field, Extract Interface, Rename, Promote Variable to Parameter(Changing method signature), Generate Method Stub(Used for testing purposes)&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
! Promoting Variable to Parameter&lt;br /&gt;
---- Before Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB();&lt;br /&gt;
}&lt;br /&gt;
public void MethodB()&lt;br /&gt;
{&lt;br /&gt;
    string output = &amp;quot;Test String&amp;quot;;&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
---- After Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB(&amp;quot;Test String&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
public void MethodB(string output)&lt;br /&gt;
{&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring in NetBeans===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54589</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54589"/>
		<updated>2011-11-01T23:15:12Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Refactoring support in popular IDE(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; As people make changes to the code to realize their short term goals without fully understanding the design of code, the code loses its structure.  The refactoring work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape. &amp;lt;ref name=&amp;quot;reftwo&amp;quot;&amp;gt; Why should you Refactor http://sourcemaking.com/refactoring/why-should-you-refactor &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Fully autonomous factoring doesn't appear to exist at this time in the IDE(s) described below.  However there are papers &amp;lt;i&amp;gt;Inducing Evolution-Robust Pointcuts&amp;lt;/i&amp;gt; &amp;lt;Ref name=&amp;quot;refseven&amp;quot;&amp;gt;Inducing Evolution-Robust Pointcuts, Braem, M.&amp;lt;/ref&amp;gt; and &amp;lt;i&amp;gt;Automatic Refactoring of Erlang Programs&amp;lt;/i&amp;gt;&amp;lt;ref name=&amp;quot;refeight&amp;quot;&amp;gt;Automatic Refactoring of Erlang Programs http://www.ece.cmu.edu/~aavgerin/papers/PPDP09.pdf&amp;lt;/ref&amp;gt; that point the way to the future of refactoring that can be fully automated.  In the context of this wiki article, automatic refactoring means automated refactoring under programmer control and guidance.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common Refactoring Techniques==&lt;br /&gt;
===Extraction Refactoring=== &lt;br /&gt;
There are several refactoring techniques related to extraction: Extract method, Extract local variables, extract constants. The first method &amp;quot;Extract method will create a new method from code you've selected. Extract Local Variable refactoring takes an expression that is being used repeatedly and assigns it to a local variable. Extract constant refactoring is to select a static, constant expression, which the refactoring will convert to a static final constant. This is useful for removing hard-coded numbers and strings from your code&lt;br /&gt;
&lt;br /&gt;
===Inline Refactoring=== &lt;br /&gt;
This type refactoring is the reverse of local variable extraction, in which we remove a local variable and use the value of the variable(typically an expression) in the place where the variable is used. This can be marginally more efficient than using a temporary variable and, by making the code terser, makes it either easier to read or more cryptic, depending on your point of view&amp;lt;ref name=&amp;quot;refthree&amp;quot;&amp;gt; refactoring for everyone http://www.ibm.com/developerworks/library/os-ecref/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Encapsulating Fields===&lt;br /&gt;
Generally its not a good practice to expose the class attributes through public interface. Thus, Encapsulating such fields will make such fields as private or protected as appropriate and generate getters and setters for the associated field.&lt;br /&gt;
&lt;br /&gt;
===Changing Method Signature===&lt;br /&gt;
Here we change the change the parameters, visibility, and return type of a method.&lt;br /&gt;
&lt;br /&gt;
== Other Refactorings ==&lt;br /&gt;
&lt;br /&gt;
There are a multitude of refactorings.  Those that are included with RubyMine&amp;lt;ref name=&amp;quot;reffour&amp;quot;&amp;gt;RubyMine :: Ruby and Ruby on Rails IDE with smart code completion, syntax highlighting and refactoring http://www.jetbrains.com/ruby/features/ruby_ide.html#Refactorings&amp;lt;/ref&amp;gt; include:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename refactoring&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Method&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Module&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Superclass&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Constant&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Field&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Parameter&lt;br /&gt;
&amp;lt;li&amp;gt;Inline Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Pull Uo Members&lt;br /&gt;
&amp;lt;li&amp;gt;Push Down Members&lt;br /&gt;
&amp;lt;li&amp;gt;Override Method&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Martin Fowler has online resources for additional refactoring definitions which can be found here http://martinfowler.com/bliki/refactoring.html&amp;lt;ref name=&amp;quot;reffive&amp;quot;&amp;gt;MF Blicki: refactoring http://martinfowler.com/bliki/refactoring.html&amp;lt;/ref&amp;gt; and here http://refactoring.com/catalog/&amp;lt;ref name=&amp;quot;refsix&amp;quot;&amp;gt;Alpha list of refactorings http://refactoring.com/catalog/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Refactoring support in popular IDE(s)==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;font-size: 90%; text-align: center; width: auto;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! IDE&lt;br /&gt;
! Refactoring Support&lt;br /&gt;
! Automated Refactoring?&lt;br /&gt;
! Number of Refactoring support&lt;br /&gt;
! Support for Pattern&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
! Borland Delphi&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Eclipse &amp;lt;ref name='refeclipse'&amp;gt;http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-menu-refactor.htm &amp;lt;/ref&amp;gt;&lt;br /&gt;
! Rename selected Elements, Move selected elements, Change Method Signature, Extraction, Convert Anonymous Class to Nested, Convert Local Variable to Field, Extract Super class and Interface, push down, pull up, Introduce Indirection, Encapsulate Field, Migrate JAR File, Create &amp;amp; Apply Refatoring Scripts&lt;br /&gt;
!&lt;br /&gt;
! Yes&lt;br /&gt;
! Introduce Factory, &lt;br /&gt;
! int x= p * 5; 	&amp;gt; 	int x= getFoo(p); (Method Extraction) , p.x; 	&amp;gt; 	p.getX() (Encapsulate Field)&lt;br /&gt;
|-&lt;br /&gt;
! Kdevelop&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! NetBeans&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Padre&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! RubyMine&lt;br /&gt;
! No&lt;br /&gt;
! Yes&lt;br /&gt;
! 11&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Visual Studio&lt;br /&gt;
! Extract Method, Encapsulate Field, Extract Interface, Rename, Promote Variable to Parameter(Changing method signature), Generate Method Stub(Used for testing purposes)&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
! Promoting Variable to Parameter&lt;br /&gt;
---- Before Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB();&lt;br /&gt;
}&lt;br /&gt;
public void MethodB()&lt;br /&gt;
{&lt;br /&gt;
    string output = &amp;quot;Test String&amp;quot;;&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
---- After Refactoring &lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB(&amp;quot;Test String&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
public void MethodB(string output)&lt;br /&gt;
{&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring in NetBeans===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54588</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54588"/>
		<updated>2011-11-01T23:11:22Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Refactoring support in popular IDE(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; As people make changes to the code to realize their short term goals without fully understanding the design of code, the code loses its structure.  The refactoring work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape. &amp;lt;ref name=&amp;quot;reftwo&amp;quot;&amp;gt; Why should you Refactor http://sourcemaking.com/refactoring/why-should-you-refactor &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Fully autonomous factoring doesn't appear to exist at this time in the IDE(s) described below.  However there are papers &amp;lt;i&amp;gt;Inducing Evolution-Robust Pointcuts&amp;lt;/i&amp;gt; &amp;lt;Ref name=&amp;quot;refseven&amp;quot;&amp;gt;Inducing Evolution-Robust Pointcuts, Braem, M.&amp;lt;/ref&amp;gt; and &amp;lt;i&amp;gt;Automatic Refactoring of Erlang Programs&amp;lt;/i&amp;gt;&amp;lt;ref name=&amp;quot;refeight&amp;quot;&amp;gt;Automatic Refactoring of Erlang Programs http://www.ece.cmu.edu/~aavgerin/papers/PPDP09.pdf&amp;lt;/ref&amp;gt; that point the way to the future of refactoring that can be fully automated.  In the context of this wiki article, automatic refactoring means automated refactoring under programmer control and guidance.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common Refactoring Techniques==&lt;br /&gt;
===Extraction Refactoring=== &lt;br /&gt;
There are several refactoring techniques related to extraction: Extract method, Extract local variables, extract constants. The first method &amp;quot;Extract method will create a new method from code you've selected. Extract Local Variable refactoring takes an expression that is being used repeatedly and assigns it to a local variable. Extract constant refactoring is to select a static, constant expression, which the refactoring will convert to a static final constant. This is useful for removing hard-coded numbers and strings from your code&lt;br /&gt;
&lt;br /&gt;
===Inline Refactoring=== &lt;br /&gt;
This type refactoring is the reverse of local variable extraction, in which we remove a local variable and use the value of the variable(typically an expression) in the place where the variable is used. This can be marginally more efficient than using a temporary variable and, by making the code terser, makes it either easier to read or more cryptic, depending on your point of view&amp;lt;ref name=&amp;quot;refthree&amp;quot;&amp;gt; refactoring for everyone http://www.ibm.com/developerworks/library/os-ecref/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Encapsulating Fields===&lt;br /&gt;
Generally its not a good practice to expose the class attributes through public interface. Thus, Encapsulating such fields will make such fields as private or protected as appropriate and generate getters and setters for the associated field.&lt;br /&gt;
&lt;br /&gt;
===Changing Method Signature===&lt;br /&gt;
Here we change the change the parameters, visibility, and return type of a method.&lt;br /&gt;
&lt;br /&gt;
== Other Refactorings ==&lt;br /&gt;
&lt;br /&gt;
There are a multitude of refactorings.  Those that are included with RubyMine&amp;lt;ref name=&amp;quot;reffour&amp;quot;&amp;gt;RubyMine :: Ruby and Ruby on Rails IDE with smart code completion, syntax highlighting and refactoring http://www.jetbrains.com/ruby/features/ruby_ide.html#Refactorings&amp;lt;/ref&amp;gt; include:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename refactoring&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Method&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Module&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Superclass&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Constant&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Field&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Parameter&lt;br /&gt;
&amp;lt;li&amp;gt;Inline Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Pull Uo Members&lt;br /&gt;
&amp;lt;li&amp;gt;Push Down Members&lt;br /&gt;
&amp;lt;li&amp;gt;Override Method&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Martin Fowler has online resources for additional refactoring definitions which can be found here http://martinfowler.com/bliki/refactoring.html&amp;lt;ref name=&amp;quot;reffive&amp;quot;&amp;gt;MF Blicki: refactoring http://martinfowler.com/bliki/refactoring.html&amp;lt;/ref&amp;gt; and here http://refactoring.com/catalog/&amp;lt;ref name=&amp;quot;refsix&amp;quot;&amp;gt;Alpha list of refactorings http://refactoring.com/catalog/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Refactoring support in popular IDE(s)==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;font-size: 90%; text-align: center; width: auto;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! IDE&lt;br /&gt;
! Refactoring Support&lt;br /&gt;
! Automated Refactoring?&lt;br /&gt;
! Support for Pattern&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
! Borland Delphi&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Eclipse&lt;br /&gt;
! Rename selected Elements, Move selected elements, Change Method Signature, Extraction, Convert Anonymous Class to Nested, Convert Local Variable to Field, Extract Super class and Interface, push down, pull up, Introduce Indirection, Encapsulate Field, Migrate JAR File, Create &amp;amp; Apply Refatoring Scripts&lt;br /&gt;
! Yes&lt;br /&gt;
! Introduce Factory, &lt;br /&gt;
! int x= p * 5; 	&amp;gt; 	int x= getFoo(p); (Method Extraction) , p.x; 	&amp;gt; 	p.getX() (Encapsulate Field)&lt;br /&gt;
|-&lt;br /&gt;
! Kdevelop&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! NetBeans&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Padre&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! RubyMine&lt;br /&gt;
! No&lt;br /&gt;
! Yes&lt;br /&gt;
! 11&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Visual Studio&lt;br /&gt;
! Extract Method, Encapsulate Field, Extract Interface, Rename, Promote Variable to Parameter(Changing method signature), Generate Method Stub(Used for testing purposes)&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
! Promoting Variable to Parameter&lt;br /&gt;
---- Before Refactoring ----&lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB();&lt;br /&gt;
}&lt;br /&gt;
public void MethodB()&lt;br /&gt;
{&lt;br /&gt;
    string output = &amp;quot;Test String&amp;quot;;&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
---- After Refactoring ----&lt;br /&gt;
public void MethodA()&lt;br /&gt;
{&lt;br /&gt;
    MethodB(&amp;quot;Test String&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
public void MethodB(string output)&lt;br /&gt;
{&lt;br /&gt;
    MessageBox.Show( output);&lt;br /&gt;
}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring in NetBeans===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54587</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54587"/>
		<updated>2011-11-01T22:58:06Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Refactoring support in popular IDE(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; As people make changes to the code to realize their short term goals without fully understanding the design of code, the code loses its structure.  The refactoring work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape. &amp;lt;ref name=&amp;quot;reftwo&amp;quot;&amp;gt; Why should you Refactor http://sourcemaking.com/refactoring/why-should-you-refactor &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Fully autonomous factoring doesn't appear to exist at this time in the IDE(s) described below.  However there are papers &amp;lt;i&amp;gt;Inducing Evolution-Robust Pointcuts&amp;lt;/i&amp;gt; &amp;lt;Ref name=&amp;quot;refseven&amp;quot;&amp;gt;Inducing Evolution-Robust Pointcuts, Braem, M.&amp;lt;/ref&amp;gt; and &amp;lt;i&amp;gt;Automatic Refactoring of Erlang Programs&amp;lt;/i&amp;gt;&amp;lt;ref name=&amp;quot;refeight&amp;quot;&amp;gt;Automatic Refactoring of Erlang Programs http://www.ece.cmu.edu/~aavgerin/papers/PPDP09.pdf&amp;lt;/ref&amp;gt; that point the way to the future of refactoring that can be fully automated.  In the context of this wiki article, automatic refactoring means automated refactoring under programmer control and guidance.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common Refactoring Techniques==&lt;br /&gt;
===Extraction Refactoring=== &lt;br /&gt;
There are several refactoring techniques related to extraction: Extract method, Extract local variables, extract constants. The first method &amp;quot;Extract method will create a new method from code you've selected. Extract Local Variable refactoring takes an expression that is being used repeatedly and assigns it to a local variable. Extract constant refactoring is to select a static, constant expression, which the refactoring will convert to a static final constant. This is useful for removing hard-coded numbers and strings from your code&lt;br /&gt;
&lt;br /&gt;
===Inline Refactoring=== &lt;br /&gt;
This type refactoring is the reverse of local variable extraction, in which we remove a local variable and use the value of the variable(typically an expression) in the place where the variable is used. This can be marginally more efficient than using a temporary variable and, by making the code terser, makes it either easier to read or more cryptic, depending on your point of view&amp;lt;ref name=&amp;quot;refthree&amp;quot;&amp;gt; refactoring for everyone http://www.ibm.com/developerworks/library/os-ecref/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Encapsulating Fields===&lt;br /&gt;
Generally its not a good practice to expose the class attributes through public interface. Thus, Encapsulating such fields will make such fields as private or protected as appropriate and generate getters and setters for the associated field.&lt;br /&gt;
&lt;br /&gt;
===Changing Method Signature===&lt;br /&gt;
Here we change the change the parameters, visibility, and return type of a method.&lt;br /&gt;
&lt;br /&gt;
== Other Refactorings ==&lt;br /&gt;
&lt;br /&gt;
There are a multitude of refactorings.  Those that are included with RubyMine&amp;lt;ref name=&amp;quot;reffour&amp;quot;&amp;gt;RubyMine :: Ruby and Ruby on Rails IDE with smart code completion, syntax highlighting and refactoring http://www.jetbrains.com/ruby/features/ruby_ide.html#Refactorings&amp;lt;/ref&amp;gt; include:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename refactoring&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Method&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Module&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Superclass&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Constant&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Field&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Parameter&lt;br /&gt;
&amp;lt;li&amp;gt;Inline Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Pull Uo Members&lt;br /&gt;
&amp;lt;li&amp;gt;Push Down Members&lt;br /&gt;
&amp;lt;li&amp;gt;Override Method&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Martin Fowler has online resources for additional refactoring definitions which can be found here http://martinfowler.com/bliki/refactoring.html&amp;lt;ref name=&amp;quot;reffive&amp;quot;&amp;gt;MF Blicki: refactoring http://martinfowler.com/bliki/refactoring.html&amp;lt;/ref&amp;gt; and here http://refactoring.com/catalog/&amp;lt;ref name=&amp;quot;refsix&amp;quot;&amp;gt;Alpha list of refactorings http://refactoring.com/catalog/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Refactoring support in popular IDE(s)==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;font-size: 90%; text-align: center; width: auto;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! IDE&lt;br /&gt;
! Refactoring Support&lt;br /&gt;
! Automated Refactoring?&lt;br /&gt;
! Support for Pattern&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
! Borland Delphi&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Eclipse&lt;br /&gt;
! Rename selected Elements, Move selected elements, Change Method Signature, Extraction, Convert Anonymous Class to Nested, Convert Local Variable to Field, Extract Super class and Interface, push down, pull up, Introduce Indirection, Encapsulate Field, Migrate JAR File, Create &amp;amp; Apply Refatoring Scripts&lt;br /&gt;
! Yes&lt;br /&gt;
! Introduce Factory, &lt;br /&gt;
! int x= p * 5; 	&amp;gt; 	int x= getFoo(p); (Method Extraction) , p.x; 	&amp;gt; 	p.getX() (Encapsulate Field)&lt;br /&gt;
|-&lt;br /&gt;
! Kdevelop&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! NetBeans&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Padre&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! RubyMine&lt;br /&gt;
! No&lt;br /&gt;
! Yes&lt;br /&gt;
! 11&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Visual Studio&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring in NetBeans===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54586</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54586"/>
		<updated>2011-11-01T22:57:32Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Refactoring support in popular IDE(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; As people make changes to the code to realize their short term goals without fully understanding the design of code, the code loses its structure.  The refactoring work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape. &amp;lt;ref name=&amp;quot;reftwo&amp;quot;&amp;gt; Why should you Refactor http://sourcemaking.com/refactoring/why-should-you-refactor &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Fully autonomous factoring doesn't appear to exist at this time in the IDE(s) described below.  However there are papers &amp;lt;i&amp;gt;Inducing Evolution-Robust Pointcuts&amp;lt;/i&amp;gt; &amp;lt;Ref name=&amp;quot;refseven&amp;quot;&amp;gt;Inducing Evolution-Robust Pointcuts, Braem, M.&amp;lt;/ref&amp;gt; and &amp;lt;i&amp;gt;Automatic Refactoring of Erlang Programs&amp;lt;/i&amp;gt;&amp;lt;ref name=&amp;quot;refeight&amp;quot;&amp;gt;Automatic Refactoring of Erlang Programs http://www.ece.cmu.edu/~aavgerin/papers/PPDP09.pdf&amp;lt;/ref&amp;gt; that point the way to the future of refactoring that can be fully automated.  In the context of this wiki article, automatic refactoring means automated refactoring under programmer control and guidance.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common Refactoring Techniques==&lt;br /&gt;
===Extraction Refactoring=== &lt;br /&gt;
There are several refactoring techniques related to extraction: Extract method, Extract local variables, extract constants. The first method &amp;quot;Extract method will create a new method from code you've selected. Extract Local Variable refactoring takes an expression that is being used repeatedly and assigns it to a local variable. Extract constant refactoring is to select a static, constant expression, which the refactoring will convert to a static final constant. This is useful for removing hard-coded numbers and strings from your code&lt;br /&gt;
&lt;br /&gt;
===Inline Refactoring=== &lt;br /&gt;
This type refactoring is the reverse of local variable extraction, in which we remove a local variable and use the value of the variable(typically an expression) in the place where the variable is used. This can be marginally more efficient than using a temporary variable and, by making the code terser, makes it either easier to read or more cryptic, depending on your point of view&amp;lt;ref name=&amp;quot;refthree&amp;quot;&amp;gt; refactoring for everyone http://www.ibm.com/developerworks/library/os-ecref/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Encapsulating Fields===&lt;br /&gt;
Generally its not a good practice to expose the class attributes through public interface. Thus, Encapsulating such fields will make such fields as private or protected as appropriate and generate getters and setters for the associated field.&lt;br /&gt;
&lt;br /&gt;
===Changing Method Signature===&lt;br /&gt;
Here we change the change the parameters, visibility, and return type of a method.&lt;br /&gt;
&lt;br /&gt;
== Other Refactorings ==&lt;br /&gt;
&lt;br /&gt;
There are a multitude of refactorings.  Those that are included with RubyMine&amp;lt;ref name=&amp;quot;reffour&amp;quot;&amp;gt;RubyMine :: Ruby and Ruby on Rails IDE with smart code completion, syntax highlighting and refactoring http://www.jetbrains.com/ruby/features/ruby_ide.html#Refactorings&amp;lt;/ref&amp;gt; include:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename refactoring&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Method&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Module&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Superclass&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Constant&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Field&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Parameter&lt;br /&gt;
&amp;lt;li&amp;gt;Inline Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Pull Uo Members&lt;br /&gt;
&amp;lt;li&amp;gt;Push Down Members&lt;br /&gt;
&amp;lt;li&amp;gt;Override Method&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Martin Fowler has online resources for additional refactoring definitions which can be found here http://martinfowler.com/bliki/refactoring.html&amp;lt;ref name=&amp;quot;reffive&amp;quot;&amp;gt;MF Blicki: refactoring http://martinfowler.com/bliki/refactoring.html&amp;lt;/ref&amp;gt; and here http://refactoring.com/catalog/&amp;lt;ref name=&amp;quot;refsix&amp;quot;&amp;gt;Alpha list of refactorings http://refactoring.com/catalog/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Refactoring support in popular IDE(s)==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;font-size: 90%; text-align: center; width: auto;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! IDE&lt;br /&gt;
! Refactoring Support&lt;br /&gt;
! Automated Refactoring?&lt;br /&gt;
! Support for Pattern&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
! Borland Delphi&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Eclipse&lt;br /&gt;
! Rename selected Elements, Move selected elements, Change Method Signature, Extraction, Convert Anonymous Class to Nested, Convert Local Variable to Field, Extract Super class and Interface, push down, pull up, Introduce Indirection, Encapsulate Field, Migrate JAR File, Create &amp;amp; Apply Refatoring Scripts&lt;br /&gt;
! &lt;br /&gt;
! Introduce Factory, &lt;br /&gt;
! int x= p * 5; 	&amp;gt; 	int x= getFoo(p); (Method Extraction) , p.x; 	&amp;gt; 	p.getX() (Encapsulate Field)&lt;br /&gt;
|-&lt;br /&gt;
! Kdevelop&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! NetBeans&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Padre&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! RubyMine&lt;br /&gt;
! No&lt;br /&gt;
! Yes&lt;br /&gt;
! 11&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Visual Studio&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring in NetBeans===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54585</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54585"/>
		<updated>2011-11-01T22:56:14Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Refactoring support in popular IDE(s) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; As people make changes to the code to realize their short term goals without fully understanding the design of code, the code loses its structure.  The refactoring work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape. &amp;lt;ref name=&amp;quot;reftwo&amp;quot;&amp;gt; Why should you Refactor http://sourcemaking.com/refactoring/why-should-you-refactor &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
Fully autonomous factoring doesn't appear to exist at this time in the IDE(s) described below.  However there are papers &amp;lt;i&amp;gt;Inducing Evolution-Robust Pointcuts&amp;lt;/i&amp;gt; &amp;lt;Ref name=&amp;quot;refseven&amp;quot;&amp;gt;Inducing Evolution-Robust Pointcuts, Braem, M.&amp;lt;/ref&amp;gt; and &amp;lt;i&amp;gt;Automatic Refactoring of Erlang Programs&amp;lt;/i&amp;gt;&amp;lt;ref name=&amp;quot;refeight&amp;quot;&amp;gt;Automatic Refactoring of Erlang Programs http://www.ece.cmu.edu/~aavgerin/papers/PPDP09.pdf&amp;lt;/ref&amp;gt; that point the way to the future of refactoring that can be fully automated.  In the context of this wiki article, automatic refactoring means automated refactoring under programmer control and guidance.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common Refactoring Techniques==&lt;br /&gt;
===Extraction Refactoring=== &lt;br /&gt;
There are several refactoring techniques related to extraction: Extract method, Extract local variables, extract constants. The first method &amp;quot;Extract method will create a new method from code you've selected. Extract Local Variable refactoring takes an expression that is being used repeatedly and assigns it to a local variable. Extract constant refactoring is to select a static, constant expression, which the refactoring will convert to a static final constant. This is useful for removing hard-coded numbers and strings from your code&lt;br /&gt;
&lt;br /&gt;
===Inline Refactoring=== &lt;br /&gt;
This type refactoring is the reverse of local variable extraction, in which we remove a local variable and use the value of the variable(typically an expression) in the place where the variable is used. This can be marginally more efficient than using a temporary variable and, by making the code terser, makes it either easier to read or more cryptic, depending on your point of view&amp;lt;ref name=&amp;quot;refthree&amp;quot;&amp;gt; refactoring for everyone http://www.ibm.com/developerworks/library/os-ecref/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Encapsulating Fields===&lt;br /&gt;
Generally its not a good practice to expose the class attributes through public interface. Thus, Encapsulating such fields will make such fields as private or protected as appropriate and generate getters and setters for the associated field.&lt;br /&gt;
&lt;br /&gt;
===Changing Method Signature===&lt;br /&gt;
Here we change the change the parameters, visibility, and return type of a method.&lt;br /&gt;
&lt;br /&gt;
== Other Refactorings ==&lt;br /&gt;
&lt;br /&gt;
There are a multitude of refactorings.  Those that are included with RubyMine&amp;lt;ref name=&amp;quot;reffour&amp;quot;&amp;gt;RubyMine :: Ruby and Ruby on Rails IDE with smart code completion, syntax highlighting and refactoring http://www.jetbrains.com/ruby/features/ruby_ide.html#Refactorings&amp;lt;/ref&amp;gt; include:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Rename refactoring&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Method&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Module&lt;br /&gt;
&amp;lt;li&amp;gt;Extract Superclass&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Constant&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Field&lt;br /&gt;
&amp;lt;li&amp;gt;Introduce Parameter&lt;br /&gt;
&amp;lt;li&amp;gt;Inline Variable&lt;br /&gt;
&amp;lt;li&amp;gt;Pull Uo Members&lt;br /&gt;
&amp;lt;li&amp;gt;Push Down Members&lt;br /&gt;
&amp;lt;li&amp;gt;Override Method&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Martin Fowler has online resources for additional refactoring definitions which can be found here http://martinfowler.com/bliki/refactoring.html&amp;lt;ref name=&amp;quot;reffive&amp;quot;&amp;gt;MF Blicki: refactoring http://martinfowler.com/bliki/refactoring.html&amp;lt;/ref&amp;gt; and here http://refactoring.com/catalog/&amp;lt;ref name=&amp;quot;refsix&amp;quot;&amp;gt;Alpha list of refactorings http://refactoring.com/catalog/&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Refactoring support in popular IDE(s)==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;font-size: 90%; text-align: center; width: auto;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! IDE&lt;br /&gt;
! Refactoring Support&lt;br /&gt;
! Automated Refactoring?&lt;br /&gt;
! Support for Pattern&lt;br /&gt;
! Example&lt;br /&gt;
|-&lt;br /&gt;
! Borland Delphi&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Eclipse&lt;br /&gt;
! Rename selected Elements, Move selected elements, Change Method Signature, Extraction, Convert Anonymous Class to Nested, Convert Local Variable to Field, Extract Super class and Interface, push down, pull up, Introduce Indirection, Encapsulate Field, Migrate JAR File, Create &amp;amp; Apply Refatoring Scripts&lt;br /&gt;
!&lt;br /&gt;
! Introduce Factory, &lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Kdevelop&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! NetBeans&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Padre&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! RubyMine&lt;br /&gt;
! No&lt;br /&gt;
! Yes&lt;br /&gt;
! 11&lt;br /&gt;
!&lt;br /&gt;
|-&lt;br /&gt;
! Visual Studio&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
!&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Refactoring in NetBeans===&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54402</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54402"/>
		<updated>2011-10-30T18:29:07Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; As people make changes to the code to realize their short term goals without fully understanding the design of code, the code loses its structure.  The refactoring work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape. &amp;lt;ref name=&amp;quot;reftwo&amp;quot;&amp;gt; Why should you Refactor http://sourcemaking.com/refactoring/why-should-you-refactor &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common Refactoring Techniques==&lt;br /&gt;
===Extraction Refactoring=== &lt;br /&gt;
There are several refactoring techniques related to extraction: Extract method, Extract local variables, extract constants. The first method &amp;quot;Extract method will create a new method from code you've selected. Extract Local Variable refactoring takes an expression that is being used repeatedly and assigns it to a local variable. Extract constant refactoring is to select a static, constant expression, which the refactoring will convert to a static final constant. This is useful for removing hard-coded numbers and strings from your code&lt;br /&gt;
&lt;br /&gt;
===Inline Refactoring=== &lt;br /&gt;
This type refactoring is the reverse of local variable extraction, in which we remove a local variable and use the value of the variable(typically an expression) in the place where the variable is used. This can be marginally more efficient than using a temporary variable and, by making the code terser, makes it either easier to read or more cryptic, depending on your point of view&amp;lt;ref name=&amp;quot;refthree&amp;quot;&amp;gt; refactoring for everyone http://www.ibm.com/developerworks/library/os-ecref/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Encapsulating Fields===&lt;br /&gt;
Generally its not a good practice to expose the class attributes through public interface. Thus, Encapsulating such fields will make such fields as private or protected as appropriate and generate getters and setters for the associated field.&lt;br /&gt;
&lt;br /&gt;
===Changing Method Signature===&lt;br /&gt;
Here we change the change the parameters, visibility, and return type of a method. &lt;br /&gt;
&lt;br /&gt;
==Refactoring support in popular IDEs==&lt;br /&gt;
=== Refactoring in NetBeans===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54401</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54401"/>
		<updated>2011-10-30T18:28:11Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; As people make changes to the code to realize their short term goals without fully understanding the design of code, the code loses its structure.  The refactoring work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape. &amp;lt;ref name=&amp;quot;reftwo&amp;quot;&amp;gt; Why should you Refactor http://sourcemaking.com/refactoring/why-should-you-refactor &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common Refactoring Techniques==&lt;br /&gt;
===Extraction Refactoring=== &lt;br /&gt;
There are several refactoring techniques related to extraction: Extract method, Extract local variables, extract constants. The first method &amp;quot;Extract method will create a new method from code you've selected. Extract Local Variable refactoring takes an expression that is being used repeatedly and assigns it to a local variable. Extract constant refactoring is to select a static, constant expression, which the refactoring will convert to a static final constant. This is useful for removing hard-coded numbers and strings from your code&lt;br /&gt;
&lt;br /&gt;
===Inline Refactoring=== &lt;br /&gt;
This type refactoring is the reverse of local variable extraction, in which we remove a local variable and use the value of the variable(typically an expression) in the place where the variable is used. This can be marginally more efficient than using a temporary variable and, by making the code terser, makes it either easier to read or more cryptic, depending on your point of view&amp;lt;ref name=refactoring for everyone http://www.ibm.com/developerworks/library/os-ecref/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Encapsulating Fields===&lt;br /&gt;
Generally its not a good practice to expose the class attributes through public interface. Thus, Encapsulating such fields will make such fields as private or protected as appropriate and generate getters and setters for the associated field.&lt;br /&gt;
&lt;br /&gt;
===Changing Method Signature===&lt;br /&gt;
Here we change the change the parameters, visibility, and return type of a method. &lt;br /&gt;
&lt;br /&gt;
==Refactoring support in popular IDEs==&lt;br /&gt;
=== Refactoring in NetBeans===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54400</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54400"/>
		<updated>2011-10-30T17:15:13Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; As people make changes to the code to realize their short term goals without fully understanding the design of code, the code loses its structure.  The refactoring work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape. &amp;lt;ref name=&amp;quot;reftwo&amp;quot;&amp;gt; Why should you Refactor http://sourcemaking.com/refactoring/why-should-you-refactor &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common Refactoring Techniques==&lt;br /&gt;
===Extraction Refactoring=== &lt;br /&gt;
There are several refactoring techniques related to extraction: Extract method, Extract local variables, extract constants. The first method &amp;quot;Extract method will create a new method from code you've selected. Extract Local Variable refactoring takes an expression that is being used repeatedly and assigns it to a local variable. Extract constant refactoring is to select a static, constant expression, which the refactoring will convert to a static final constant. This is useful for removing hard-coded numbers and strings from your code&lt;br /&gt;
&lt;br /&gt;
===Inline Refactoring=== &lt;br /&gt;
This type refactoring is the reverse of local variable extraction, in which we remove a local variable and use the value of the variable(typically an expression) in the place where the variable is used. This can be marginally more efficient than using a temporary variable and, by making the code terser, makes it either easier to read or more cryptic, depending on your point of view&lt;br /&gt;
&lt;br /&gt;
===Encapsulating Fields===&lt;br /&gt;
Generally its not a good practice to expose the class attributes through public interface. Thus, Encapsulating such fields will make such fields as private or protected as appropriate and generate getters and setters for the associated field.&lt;br /&gt;
&lt;br /&gt;
===Changing Method Signature===&lt;br /&gt;
Here we change the change the parameters, visibility, and return type of a method. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54399</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54399"/>
		<updated>2011-10-30T16:55:05Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; As people make changes to the code to realize their short term goals without fully understanding the design of code, the code loses its structure.  The refactoring work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape. &amp;lt;ref name=&amp;quot;reftwo&amp;quot;&amp;gt; Why should you Refactor http://sourcemaking.com/refactoring/why-should-you-refactor &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54397</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54397"/>
		<updated>2011-10-30T16:48:29Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt; Work is done to remove bits that aren’t really in the right place. Loss of the structure of code has a cumulative effect. The harder it is to see the design in the code, the harder it is to preserve it, and the more rapidly it decays. Regular refactoring helps code retain its shape&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54394</id>
		<title>CSC/ECE 517 Fall 2011/ch5 5d he</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch5_5d_he&amp;diff=54394"/>
		<updated>2011-10-30T16:38:05Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Automatic Refactoring'''&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Refactoring is a technique for restructuring an existing code, altering its internal structure without changing its external behavior. Its done as a series of small transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.&amp;lt;ref name=&amp;quot;refone&amp;quot;&amp;gt; Refactoring Home Page http://refactoring.com/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=51125</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h hs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=51125"/>
		<updated>2011-09-26T02:36:40Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Advantages of getters and getters as variable references(properties) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
== What are getters and setters ? ==&lt;br /&gt;
''' &lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide getter and setter methods to access/modify object data. When writing new classes, it's a good idea to pay attention to the issue of access control. Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. Because of this naming convention, accessor methods are more often referred to as getter methods. This is a good programming practice, since the data fields are not directly accessible outside the class. Thus 'Getters' and 'Setters' allow us to effectively protect your data. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Syntactic Notation ==&lt;br /&gt;
'''&lt;br /&gt;
There 2 common syntax for getters and setters available in programming languages: &lt;br /&gt;
&lt;br /&gt;
Method Call:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
value = ObjectName.getAttribute();&lt;br /&gt;
&lt;br /&gt;
ObjectName.setAttribute(val); &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above notation a getter is the same as any other instance method call. Its common for the getters and setters to be defined as public methods. &lt;br /&gt;
&lt;br /&gt;
Instance Variables:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectName.Field = Value;&lt;br /&gt;
&lt;br /&gt;
Value = ObjetName.Field;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this notation getters and setters looks like a accessing a class field. In most languages, internally this would invoke a method which would behave very similar to the getter method call described above. This syntactic notation offers a convenience of using intuitive syntax of getting or setting a variable.   &lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and setters as method calls ==&lt;br /&gt;
'''&lt;br /&gt;
For each variable, a get method will return its value and a set method will set the value. Here are the advantages of using getter and setter as method calls: &lt;br /&gt;
* [http://java.about.com/od/workingwithobjects/a/accessormutator.htm Encapsulate] the data from accidental / inadvertent modification. The private member variable is not part of the public interface of your class; only the public getter and setter methods are, and you are free to change their implementations without changing the public interface of your class&lt;br /&gt;
* If we decide that some action should be taken every time you change/access the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. For Instance, we can keep track of how many times a variable is accessed. &lt;br /&gt;
* Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== Advantages of getters and getters as variable references(properties) ==&lt;br /&gt;
'''&lt;br /&gt;
Properties are a robust way to handle object’s data. Properties support accessing the instance variables the same way as calling an instance method. A property communicates the idea of &amp;quot;I will make a value available to you, or accept a value from you.&amp;quot; It's not an implementation concept, it's an interface concept. Different languages follow specific syntax for adding a property to a class. Following are the advantages properties: &lt;br /&gt;
* The code is much [http://www.dotnetspider.com/tutorials/DotNet-Tutorial-273.aspx cleaner] when accessing a property when compared to Java or C++ which uses 2 separate methods for each instance variable. They are very useful in GUI programming which necessitates using a lot of fields for UI elements&lt;br /&gt;
* With properties we have [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx fine-grained] access control. For instance we can define a property as abstract thereby forcing the derived class to define that property. &lt;br /&gt;
* The main advantage of using properties is that if the internal implementation of getting or setting the property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class. This allows the interface of the object to stay the same even if the underlying implementation of getting and setting the property changes. &lt;br /&gt;
&lt;br /&gt;
Realizing the importance of getters and setters, popular IDEs like Eclipse, Visual studio has a built in mechanism to add getter and setter for a field or to create a property (in C#) for a given field.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== Examples Languages that use getters and setters as method calls: ==&lt;br /&gt;
'''&lt;br /&gt;
'''&lt;br /&gt;
===C++===&lt;br /&gt;
'''&lt;br /&gt;
'Getters' and 'Setters' allow you to effectively protect your data. This is a technique used greatly when creating classes in C++. The getters and setters are usually public and the variables are made private. The reason for it is the data members are not accessible outside the class. For each variable, a get method will return its value and a set method will set the value.The reason for not editing the methods directly is twofold. Firstly, if you decide that some action should be taken every time you change the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
  int x_value;&lt;br /&gt;
&lt;br /&gt;
  public:&lt;br /&gt;
  // Getter&lt;br /&gt;
  int getx_value()&lt;br /&gt;
  {&lt;br /&gt;
      return x;&lt;br /&gt;
  }&lt;br /&gt;
  // Setter&lt;br /&gt;
  void setx_value( int x )&lt;br /&gt;
  {&lt;br /&gt;
      x_value = x;&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
void main()&lt;br /&gt;
{ &lt;br /&gt;
    A a;&lt;br /&gt;
    a.setx_value(5);&lt;br /&gt;
    cout&amp;lt;&amp;lt;a.getx_value();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class BookStore&lt;br /&gt;
{ &lt;br /&gt;
  String title;&lt;br /&gt;
  public String getTitle()&lt;br /&gt;
  {&lt;br /&gt;
     return title;&lt;br /&gt;
  }&lt;br /&gt;
  // a setter method might check that the value that is being assigned to the variable is legal&lt;br /&gt;
  public void setTitle( String newTitle ) &lt;br /&gt;
  {&lt;br /&gt;
    if ( newTitle == null )   // Don't allow null strings as titles!&lt;br /&gt;
       title = &amp;quot;(Untitled)&amp;quot;;  // Use an appropriate default value instead.&lt;br /&gt;
    else&lt;br /&gt;
       title = newTitle;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
     BookStore obj;&lt;br /&gt;
     obj. setTitle(&amp;quot;&amp;quot;);&lt;br /&gt;
     System.out.println(obj.getTitle());&lt;br /&gt;
}&lt;br /&gt;
Output:&lt;br /&gt;
(Untitled)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
'''&lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide accessor methods to modify object data. [http://www.netalive.org/tinkering/serious-perl/#import_extend Perl] does not have private variables but we can still use the concept of getter, setter functions methods.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub setName &lt;br /&gt;
{&lt;br /&gt;
   my ( $self, $Name ) = @_;&lt;br /&gt;
   $self-&amp;gt;{_Name} = $Name;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
sub getName &lt;br /&gt;
{&lt;br /&gt;
   my( $self ) = @_;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== ColdFusion === &lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
If we want to override the getter and setter method, you just need to define those methods in your [http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ CFC] and ColdFusion will call our method instead of calling the implicit one.The implicit methods can also do some nice validation if you have given the ‘type’ for properties. For instance, if we define a property as numeric and try to provide a try to set a string as its value It will throw a nice error saying “The value cannot be converted to a numeric”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Component Person&lt;br /&gt;
{&lt;br /&gt;
   property name&lt;br /&gt;
   property age;&lt;br /&gt;
   property city;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;!--- Once an object is created we can directly call the setters and getters for the properties as ---&amp;gt;&lt;br /&gt;
&amp;lt;cfscript&amp;gt;&lt;br /&gt;
   person = new Person();&lt;br /&gt;
   person.setName(&amp;quot;Brad&amp;quot;);&lt;br /&gt;
   person.setAge(46);&lt;br /&gt;
&lt;br /&gt;
   writeOutput(&amp;quot;Name : #person.getName()#&amp;quot;);&lt;br /&gt;
   writeOutput(&amp;quot;Age : #person.getAge()#&amp;quot;); &lt;br /&gt;
&amp;lt;/cfscript&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples from Languages that use getters and setters as instance variable references:  ==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== C#: ===&lt;br /&gt;
'''&lt;br /&gt;
In [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx C#], properties are nothing but natural extension of data fields. The properties are an important features added in language level inside C#.yC# also supports static properties, which belongs to the class rather than to the objects of the class. The properties of a Base class can be inherited to a Derived class and can be overridden by polymorphism. They are very useful in GUI programming. The compiler generates the appropriate getter and setter methods when it parses the C# property syntax.In C#, data encapsulation is possible through either classes or structures. By using various access modifiers like private, public, protected, internal etc it is possible to control the accessibility of the class members.  Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. This is a good programming practice, since the data fields are not directly accessible out side the class. We must use the set/get methods to access the data fields.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;class MyClass&lt;br /&gt;
{&lt;br /&gt;
      private int x;&lt;br /&gt;
      public int X&lt;br /&gt;
      {&lt;br /&gt;
            get&lt;br /&gt;
           {&lt;br /&gt;
             return x;&lt;br /&gt;
           }&lt;br /&gt;
          set&lt;br /&gt;
          {&lt;br /&gt;
             x = value;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
//Invocation&lt;br /&gt;
MyClass mc = new MyClass();&lt;br /&gt;
mc.X = 10;                   // calls set accessor of the property X, and pass 10 as value of the standard field 'value'.&lt;br /&gt;
Console.WriteLine(mc.X);     // displays 10. Calls the get accessor of the property X.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
===Lua===&lt;br /&gt;
'''&lt;br /&gt;
Getter and Setter functions can be implemented in [http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Lua], which is similar to the properties concept in C#. This allows the functions to bind to a property that can be assigned and accessed as a value.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class 'Test'&lt;br /&gt;
  function  Test : getLength()&lt;br /&gt;
   return # self.value&lt;br /&gt;
  end&lt;br /&gt;
  function  Test : setLength(newLength)&lt;br /&gt;
    for  i = self.length, newLength do&lt;br /&gt;
        table.insert(self.value, false )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
test =  Test({1, 2, 3, 4})&lt;br /&gt;
print(test.length)&lt;br /&gt;
self.length = property( Test.getLength, Test.setLength )    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
===Ruby===&lt;br /&gt;
'''&lt;br /&gt;
Ruby simplifies the creation of getters and setters with a little metaprogramming and the methods attr, attr_reader, attr_writer, and attr_accessor, all from the Module class. By supplying the attr method, Ruby provides a way to acces the instances directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
    def initialize(lname, fname)&lt;br /&gt;
        @lname = lname&lt;br /&gt;
        @fname = fname&lt;br /&gt;
    end&lt;br /&gt;
attr_reader :lname // creates a getter method&lt;br /&gt;
    attr_writer :lname    // creates a setter method&lt;br /&gt;
    attr_accessor :fname // creates both getter and setter method&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x = Person.new(&amp;quot;ABC&amp;quot;, &amp;quot;XYZ&amp;quot;)&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
x.fname = &amp;quot;PQR&amp;quot;&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
===Php===&lt;br /&gt;
'''&lt;br /&gt;
An interesting aspect of php worth noting is that we can assign values to undefined variables. Because of the above limitation, [http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set PHP] engine provides two magic methods __get() and __set(). __get() is used when value from an undefined variable is to be read and __set() is used when a value is to be assigned to a undefined variable of a class.In the above example when email@domain.com is assigned to the undefined variable $email, the magic method __set() is called. To this __set() method the name of the variable is passed into $dt variable of __set() method and the value i.e. email@domain.com is passed to $vl variable of the __set() method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
class Customer&lt;br /&gt;
{&lt;br /&gt;
   public $name;&lt;br /&gt;
   private $data = array();&lt;br /&gt;
   public function __set($dt, $vl) &lt;br /&gt;
   {&lt;br /&gt;
      $this-&amp;gt;data[$dt] = $vl;&lt;br /&gt;
   }&lt;br /&gt;
   public function __get($dt) &lt;br /&gt;
   {&lt;br /&gt;
      return $this-&amp;gt;data[$dt];&lt;br /&gt;
   }&lt;br /&gt;
} &lt;br /&gt;
$c = new Customer();&lt;br /&gt;
$c-&amp;gt;name = “Sunil”; // $name is set because its public&lt;br /&gt;
$c-&amp;gt;email = “email@domain.com”; //assigning email@domain.com to the $email variable.&lt;br /&gt;
echo $c-&amp;gt;email;&lt;br /&gt;
?&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Objective C===&lt;br /&gt;
'''&lt;br /&gt;
In [http://www.touch-code-magazine.com/objective-c-properties/ Objective C] we can define a property using @property directive. @synthesize will create automatically for you a setter and a getter methods for the property which becomes accessible during the run time.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// public header file&lt;br /&gt;
@interface MyObject : NSObject&lt;br /&gt;
{&lt;br /&gt;
  NSString *make; &lt;br /&gt;
  NSString* model;&lt;br /&gt;
  NSNumber* vin;&lt;br /&gt;
}&lt;br /&gt;
@property (readonly, copy) NSString *language;&lt;br /&gt;
@property(readwrite, retain) NSString* make;&lt;br /&gt;
@property(readwrite, retain) NSString* model;&lt;br /&gt;
@property(readwrite, retain) NSNumber* vin;&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
#import &amp;quot;SimpleCar.h&amp;quot;&lt;br /&gt;
@implementation SimpleCar&lt;br /&gt;
@synthesize make, model, vin;&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Python ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DoubleIt(object):&lt;br /&gt;
   def _get_value(self):&lt;br /&gt;
       return self._value * 2&lt;br /&gt;
   def _set_value(self, value):&lt;br /&gt;
       self._value = value&lt;br /&gt;
   value = property(_get_value, _set_value)&lt;br /&gt;
&lt;br /&gt;
# Invocation &lt;br /&gt;
x = DoubleIt()&lt;br /&gt;
 &lt;br /&gt;
x.value = 10&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = 'foo'&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = [1,2,3]&lt;br /&gt;
print x.value&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above [http://stefaanlippens.net/python_property_trick python] code, the output is doubled since the getter multiplies the value by 2&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Javascript ===&lt;br /&gt;
'''&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 JavaScript] supports accessing getters and setters as variable as properties. Javascript originally used __defineGetter__ and __defineSetter__ syntax to define properties which is depricated as the language evolved. Object.defineProperty is currently used for creating a property. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function addDataProperty()&lt;br /&gt;
{&lt;br /&gt;
   var newLine = &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;;&lt;br /&gt;
   var obj = {};&lt;br /&gt;
  &lt;br /&gt;
   // Add a data property to the object.&lt;br /&gt;
   Object.defineProperty(obj, &amp;quot;newDataProperty&amp;quot;, &lt;br /&gt;
   {&lt;br /&gt;
       value: 101,&lt;br /&gt;
       writable: true,&lt;br /&gt;
       enumerable: true,&lt;br /&gt;
       configurable: true&lt;br /&gt;
   });&lt;br /&gt;
&lt;br /&gt;
   // Set the property value.&lt;br /&gt;
   obj.newDataProperty = 102;&lt;br /&gt;
   document.write(&amp;quot;Property value: &amp;quot; + obj.newDataProperty + newLine);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Scala ===&lt;br /&gt;
'''&lt;br /&gt;
[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Scala] has some unconventional ideas that provide a solid, well thought out, and an abbreviated syntax to access object properties. This getter code simply defines a method called “age” and returns the “_age” variable. Scala doesn’t require the return keyword. The setter method name is “age_=”. The underscore is a special character in Scala and in this case, allows for a space in the method name which essentially makes the name “age =”. The parentheses and contents dictate the value and type that needs to be passed in. The “:Unit” code is equivalent to returning void. The remaining code is setting the “_age” variable to “value”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person() {&lt;br /&gt;
// Private age variable, renamed to _age&lt;br /&gt;
private var _age = 0&lt;br /&gt;
var name = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Getter&lt;br /&gt;
def age = _age&lt;br /&gt;
&lt;br /&gt;
// Setter&lt;br /&gt;
def age_= (value:Int):Unit = _age = value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// We can invoke the setter as follows : &lt;br /&gt;
 can invoke the setter using the following: &lt;br /&gt;
person.age = 99&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
===Smalltalk===&lt;br /&gt;
'''&lt;br /&gt;
In [http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk] the names of getter methods are usually the same as the name of the instance variable. A colon is added to the end of setter method name e.g. colour:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     name                           &amp;quot;gets the value of name&amp;quot;&lt;br /&gt;
     name:aName              &amp;quot;sets name to the value of aName&amp;quot;&lt;br /&gt;
&lt;br /&gt;
     address                        &amp;quot;gets the value of address&amp;quot;&lt;br /&gt;
     address:anAddress     &amp;quot;sets anAddress to the value of anAddress&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Actionscript ===&lt;br /&gt;
'''&lt;br /&gt;
In [http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000171.html Flex] it is not usually necessary to create the wrapper getter and setting functions on an object because ActionScript supports properties. This means that you can usually just create public properties like:&lt;br /&gt;
public var firstName:String;&lt;br /&gt;
If the internal implementation of getting or setting the firstName property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class:&lt;br /&gt;
private var _firstName:String;&lt;br /&gt;
&lt;br /&gt;
Getting or setting the property would call the getter and setter functions instead of accessing the property directly&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public var firstName:String;&lt;br /&gt;
private var _firstName:String;&lt;br /&gt;
&lt;br /&gt;
public function get firstName():String {&lt;br /&gt;
   return _firstName;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public function set fullName(_firstName:String):void {&lt;br /&gt;
   this._firstName = _firstName;&lt;br /&gt;
}&lt;br /&gt;
// getters&lt;br /&gt;
var1 = obj.firstName;&lt;br /&gt;
var2 = obj['firstName'];&lt;br /&gt;
// setters&lt;br /&gt;
obj.firstName = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
obj['fullName'] = &amp;quot;Yes&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
==Getters and Setters from a different perspective==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
A fundamental precept of OO systems is that an object should not expose any of its implementation details. This way, you can change the implementation without changing the code that uses the object. It follows then that in OO systems you should avoid getter and setter functions since they mostly provide access to implementation details. For instance if you need change the return type of a getter method from int to long to accommodate the big numbers you need to change all the invocations of that getter method. This negates the concept of [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html information hiding]. The same issue arises when you need to change the accessed field’s type. You also have to change the getter’s return type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Solution:	 &lt;br /&gt;
Maintainability is inversely proportionate to the amount of data that moves between objects. Thus, its best to minimize data movement as much as possible. The idea is to focus on what you will do rather than how you will do it. Don't ask for the information you need to do the work; ask the object that has the information to do the work for you. Lets use an example to explain this better. While building user interfaces, we dont want UI builder class call methods like &amp;quot;GetAttributes()&amp;quot;. Classes can have methods like &amp;quot;DrawYourself()&amp;quot; and getters that returns an object that implements an interface. In our UI Construction example, GetIdentity() getter method can return an object that implements Identity Interface and this Interface includes the method &amp;quot;DrawYourself()&amp;quot;. This GetIdentity() call does not return a simple field but a complex object with a defined behavior and the internals of this object is kept hidden &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== When to Use Getters and Setters ? ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
1. When a getter returns an object that implements an Interface since the interface isolates the class that uses this interface from the implementing class. &lt;br /&gt;
2. Generic interfaces like Java Database Connectivity (JDBC) are unaware of how it will be used and in such cases getters are used to provide flexibility&lt;br /&gt;
&lt;br /&gt;
Programmers use getters and setters because of procedural language mindset. A useful design strategy to this end is to center our design in terms of use cases without getters and setters by thinking on the lines of communication or interaction between the objects with well defined behavior.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
'''&lt;br /&gt;
Getters and setters provide a convenient method to access the instance variables. A lot of new languages have come up with the support for accessing getters and setters as instance variable reference which improves the readability of the code. While such convenient mechanisms are available, it is important to use the getters and setters wisely with the goal of minimizing the data movement between the objects. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== References ==&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx Understanding properties in C#]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html why getters and setters are evil ]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set php5 OOPS tutorial]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://stefaanlippens.net/python_property_trick python-hiding attribute getters and setters behind standard attribute access]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 Object.defineProperty Function (JavaScript)]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Getters and Setters in Scala]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ ColdFusion 9 : Implicit/Generated CFC Methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000171.html Using getters and setters]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.touch-code-magazine.com/objective-c-properties/ Objective C properties]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Properties in Lua]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.netalive.org/tinkering/serious-perl/#import_extend Perl ]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Classes#Instance_Variables Ruby]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://java.about.com/od/workingwithobjects/a/accessormutator.htm Accessors and Mutators]&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=51123</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h hs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=51123"/>
		<updated>2011-09-26T02:34:51Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Advantages of getters and getters as variable references(properties) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
== What are getters and setters ? ==&lt;br /&gt;
''' &lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide getter and setter methods to access/modify object data. When writing new classes, it's a good idea to pay attention to the issue of access control. Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. Because of this naming convention, accessor methods are more often referred to as getter methods. This is a good programming practice, since the data fields are not directly accessible outside the class. Thus 'Getters' and 'Setters' allow us to effectively protect your data. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Syntactic Notation ==&lt;br /&gt;
'''&lt;br /&gt;
There 2 common syntax for getters and setters available in programming languages: &lt;br /&gt;
&lt;br /&gt;
Method Call:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
value = ObjectName.getAttribute();&lt;br /&gt;
&lt;br /&gt;
ObjectName.setAttribute(val); &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above notation a getter is the same as any other instance method call. Its common for the getters and setters to be defined as public methods. &lt;br /&gt;
&lt;br /&gt;
Instance Variables:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectName.Field = Value;&lt;br /&gt;
&lt;br /&gt;
Value = ObjetName.Field;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this notation getters and setters looks like a accessing a class field. In most languages, internally this would invoke a method which would behave very similar to the getter method call described above. This syntactic notation offers a convenience of using intuitive syntax of getting or setting a variable.   &lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and setters as method calls ==&lt;br /&gt;
'''&lt;br /&gt;
For each variable, a get method will return its value and a set method will set the value. Here are the advantages of using getter and setter as method calls: &lt;br /&gt;
* [http://java.about.com/od/workingwithobjects/a/accessormutator.htm Encapsulate] the data from accidental / inadvertent modification. The private member variable is not part of the public interface of your class; only the public getter and setter methods are, and you are free to change their implementations without changing the public interface of your class&lt;br /&gt;
* If we decide that some action should be taken every time you change/access the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. For Instance, we can keep track of how many times a variable is accessed. &lt;br /&gt;
* Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== Advantages of getters and getters as variable references(properties) ==&lt;br /&gt;
'''&lt;br /&gt;
Properties are a robust way to handle object’s data. Properties support accessing the instance variables the same way as calling an instance method. A property communicates the idea of &amp;quot;I will make a value available to you, or accept a value from you.&amp;quot; It's not an implementation concept, it's an interface concept. Different languages follow specific syntax for adding a property to a class. Following are the advantages properties: &lt;br /&gt;
* The code is much cleaner when accessing a property when compared to Java or C++ which uses 2 separate methods for each instance variable. They are very useful in GUI programming which necessitates using a lot of fields for UI elements&lt;br /&gt;
* With properties we have [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx fine-grained] access control. For instance we can define a property as abstract thereby forcing the derived class to define that property. &lt;br /&gt;
* The main advantage of using properties is that if the internal implementation of getting or setting the property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class. This allows the interface of the object to stay the same even if the underlying implementation of getting and setting the property changes. &lt;br /&gt;
&lt;br /&gt;
Realizing the importance of getters and setters, popular IDEs like Eclipse, Visual studio has a built in mechanism to add getter and setter for a field or to create a property (in C#) for a given field.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== Examples Languages that use getters and setters as method calls: ==&lt;br /&gt;
'''&lt;br /&gt;
'''&lt;br /&gt;
===C++===&lt;br /&gt;
'''&lt;br /&gt;
'Getters' and 'Setters' allow you to effectively protect your data. This is a technique used greatly when creating classes in C++. The getters and setters are usually public and the variables are made private. The reason for it is the data members are not accessible outside the class. For each variable, a get method will return its value and a set method will set the value.The reason for not editing the methods directly is twofold. Firstly, if you decide that some action should be taken every time you change the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
  int x_value;&lt;br /&gt;
&lt;br /&gt;
  public:&lt;br /&gt;
  // Getter&lt;br /&gt;
  int getx_value()&lt;br /&gt;
  {&lt;br /&gt;
      return x;&lt;br /&gt;
  }&lt;br /&gt;
  // Setter&lt;br /&gt;
  void setx_value( int x )&lt;br /&gt;
  {&lt;br /&gt;
      x_value = x;&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
void main()&lt;br /&gt;
{ &lt;br /&gt;
    A a;&lt;br /&gt;
    a.setx_value(5);&lt;br /&gt;
    cout&amp;lt;&amp;lt;a.getx_value();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class BookStore&lt;br /&gt;
{ &lt;br /&gt;
  String title;&lt;br /&gt;
  public String getTitle()&lt;br /&gt;
  {&lt;br /&gt;
     return title;&lt;br /&gt;
  }&lt;br /&gt;
  // a setter method might check that the value that is being assigned to the variable is legal&lt;br /&gt;
  public void setTitle( String newTitle ) &lt;br /&gt;
  {&lt;br /&gt;
    if ( newTitle == null )   // Don't allow null strings as titles!&lt;br /&gt;
       title = &amp;quot;(Untitled)&amp;quot;;  // Use an appropriate default value instead.&lt;br /&gt;
    else&lt;br /&gt;
       title = newTitle;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
     BookStore obj;&lt;br /&gt;
     obj. setTitle(&amp;quot;&amp;quot;);&lt;br /&gt;
     System.out.println(obj.getTitle());&lt;br /&gt;
}&lt;br /&gt;
Output:&lt;br /&gt;
(Untitled)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
'''&lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide accessor methods to modify object data. [http://www.netalive.org/tinkering/serious-perl/#import_extend Perl] does not have private variables but we can still use the concept of getter, setter functions methods.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub setName &lt;br /&gt;
{&lt;br /&gt;
   my ( $self, $Name ) = @_;&lt;br /&gt;
   $self-&amp;gt;{_Name} = $Name;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
sub getName &lt;br /&gt;
{&lt;br /&gt;
   my( $self ) = @_;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== ColdFusion === &lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
If we want to override the getter and setter method, you just need to define those methods in your [http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ CFC] and ColdFusion will call our method instead of calling the implicit one.The implicit methods can also do some nice validation if you have given the ‘type’ for properties. For instance, if we define a property as numeric and try to provide a try to set a string as its value It will throw a nice error saying “The value cannot be converted to a numeric”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Component Person&lt;br /&gt;
{&lt;br /&gt;
   property name&lt;br /&gt;
   property age;&lt;br /&gt;
   property city;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;!--- Once an object is created we can directly call the setters and getters for the properties as ---&amp;gt;&lt;br /&gt;
&amp;lt;cfscript&amp;gt;&lt;br /&gt;
   person = new Person();&lt;br /&gt;
   person.setName(&amp;quot;Brad&amp;quot;);&lt;br /&gt;
   person.setAge(46);&lt;br /&gt;
&lt;br /&gt;
   writeOutput(&amp;quot;Name : #person.getName()#&amp;quot;);&lt;br /&gt;
   writeOutput(&amp;quot;Age : #person.getAge()#&amp;quot;); &lt;br /&gt;
&amp;lt;/cfscript&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples from Languages that use getters and setters as instance variable references:  ==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== C#: ===&lt;br /&gt;
'''&lt;br /&gt;
In [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx C#], properties are nothing but natural extension of data fields. The properties are an important features added in language level inside C#.yC# also supports static properties, which belongs to the class rather than to the objects of the class. The properties of a Base class can be inherited to a Derived class and can be overridden by polymorphism. They are very useful in GUI programming. The compiler generates the appropriate getter and setter methods when it parses the C# property syntax.In C#, data encapsulation is possible through either classes or structures. By using various access modifiers like private, public, protected, internal etc it is possible to control the accessibility of the class members.  Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. This is a good programming practice, since the data fields are not directly accessible out side the class. We must use the set/get methods to access the data fields.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;class MyClass&lt;br /&gt;
{&lt;br /&gt;
      private int x;&lt;br /&gt;
      public int X&lt;br /&gt;
      {&lt;br /&gt;
            get&lt;br /&gt;
           {&lt;br /&gt;
             return x;&lt;br /&gt;
           }&lt;br /&gt;
          set&lt;br /&gt;
          {&lt;br /&gt;
             x = value;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
//Invocation&lt;br /&gt;
MyClass mc = new MyClass();&lt;br /&gt;
mc.X = 10;                   // calls set accessor of the property X, and pass 10 as value of the standard field 'value'.&lt;br /&gt;
Console.WriteLine(mc.X);     // displays 10. Calls the get accessor of the property X.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
===Lua===&lt;br /&gt;
'''&lt;br /&gt;
Getter and Setter functions can be implemented in [http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Lua], which is similar to the properties concept in C#. This allows the functions to bind to a property that can be assigned and accessed as a value.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class 'Test'&lt;br /&gt;
  function  Test : getLength()&lt;br /&gt;
   return # self.value&lt;br /&gt;
  end&lt;br /&gt;
  function  Test : setLength(newLength)&lt;br /&gt;
    for  i = self.length, newLength do&lt;br /&gt;
        table.insert(self.value, false )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
test =  Test({1, 2, 3, 4})&lt;br /&gt;
print(test.length)&lt;br /&gt;
self.length = property( Test.getLength, Test.setLength )    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
===Ruby===&lt;br /&gt;
'''&lt;br /&gt;
Ruby simplifies the creation of getters and setters with a little metaprogramming and the methods attr, attr_reader, attr_writer, and attr_accessor, all from the Module class. By supplying the attr method, Ruby provides a way to acces the instances directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
    def initialize(lname, fname)&lt;br /&gt;
        @lname = lname&lt;br /&gt;
        @fname = fname&lt;br /&gt;
    end&lt;br /&gt;
attr_reader :lname // creates a getter method&lt;br /&gt;
    attr_writer :lname    // creates a setter method&lt;br /&gt;
    attr_accessor :fname // creates both getter and setter method&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x = Person.new(&amp;quot;ABC&amp;quot;, &amp;quot;XYZ&amp;quot;)&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
x.fname = &amp;quot;PQR&amp;quot;&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
===Php===&lt;br /&gt;
'''&lt;br /&gt;
An interesting aspect of php worth noting is that we can assign values to undefined variables. Because of the above limitation, [http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set PHP] engine provides two magic methods __get() and __set(). __get() is used when value from an undefined variable is to be read and __set() is used when a value is to be assigned to a undefined variable of a class.In the above example when email@domain.com is assigned to the undefined variable $email, the magic method __set() is called. To this __set() method the name of the variable is passed into $dt variable of __set() method and the value i.e. email@domain.com is passed to $vl variable of the __set() method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
class Customer&lt;br /&gt;
{&lt;br /&gt;
   public $name;&lt;br /&gt;
   private $data = array();&lt;br /&gt;
   public function __set($dt, $vl) &lt;br /&gt;
   {&lt;br /&gt;
      $this-&amp;gt;data[$dt] = $vl;&lt;br /&gt;
   }&lt;br /&gt;
   public function __get($dt) &lt;br /&gt;
   {&lt;br /&gt;
      return $this-&amp;gt;data[$dt];&lt;br /&gt;
   }&lt;br /&gt;
} &lt;br /&gt;
$c = new Customer();&lt;br /&gt;
$c-&amp;gt;name = “Sunil”; // $name is set because its public&lt;br /&gt;
$c-&amp;gt;email = “email@domain.com”; //assigning email@domain.com to the $email variable.&lt;br /&gt;
echo $c-&amp;gt;email;&lt;br /&gt;
?&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Objective C===&lt;br /&gt;
'''&lt;br /&gt;
In [http://www.touch-code-magazine.com/objective-c-properties/ Objective C] we can define a property using @property directive. @synthesize will create automatically for you a setter and a getter methods for the property which becomes accessible during the run time.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// public header file&lt;br /&gt;
@interface MyObject : NSObject&lt;br /&gt;
{&lt;br /&gt;
  NSString *make; &lt;br /&gt;
  NSString* model;&lt;br /&gt;
  NSNumber* vin;&lt;br /&gt;
}&lt;br /&gt;
@property (readonly, copy) NSString *language;&lt;br /&gt;
@property(readwrite, retain) NSString* make;&lt;br /&gt;
@property(readwrite, retain) NSString* model;&lt;br /&gt;
@property(readwrite, retain) NSNumber* vin;&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
#import &amp;quot;SimpleCar.h&amp;quot;&lt;br /&gt;
@implementation SimpleCar&lt;br /&gt;
@synthesize make, model, vin;&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Python ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DoubleIt(object):&lt;br /&gt;
   def _get_value(self):&lt;br /&gt;
       return self._value * 2&lt;br /&gt;
   def _set_value(self, value):&lt;br /&gt;
       self._value = value&lt;br /&gt;
   value = property(_get_value, _set_value)&lt;br /&gt;
&lt;br /&gt;
# Invocation &lt;br /&gt;
x = DoubleIt()&lt;br /&gt;
 &lt;br /&gt;
x.value = 10&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = 'foo'&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = [1,2,3]&lt;br /&gt;
print x.value&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above [http://stefaanlippens.net/python_property_trick python] code, the output is doubled since the getter multiplies the value by 2&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Javascript ===&lt;br /&gt;
'''&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 JavaScript] supports accessing getters and setters as variable as properties. Javascript originally used __defineGetter__ and __defineSetter__ syntax to define properties which is depricated as the language evolved. Object.defineProperty is currently used for creating a property. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function addDataProperty()&lt;br /&gt;
{&lt;br /&gt;
   var newLine = &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;;&lt;br /&gt;
   var obj = {};&lt;br /&gt;
  &lt;br /&gt;
   // Add a data property to the object.&lt;br /&gt;
   Object.defineProperty(obj, &amp;quot;newDataProperty&amp;quot;, &lt;br /&gt;
   {&lt;br /&gt;
       value: 101,&lt;br /&gt;
       writable: true,&lt;br /&gt;
       enumerable: true,&lt;br /&gt;
       configurable: true&lt;br /&gt;
   });&lt;br /&gt;
&lt;br /&gt;
   // Set the property value.&lt;br /&gt;
   obj.newDataProperty = 102;&lt;br /&gt;
   document.write(&amp;quot;Property value: &amp;quot; + obj.newDataProperty + newLine);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Scala ===&lt;br /&gt;
'''&lt;br /&gt;
[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Scala] has some unconventional ideas that provide a solid, well thought out, and an abbreviated syntax to access object properties. This getter code simply defines a method called “age” and returns the “_age” variable. Scala doesn’t require the return keyword. The setter method name is “age_=”. The underscore is a special character in Scala and in this case, allows for a space in the method name which essentially makes the name “age =”. The parentheses and contents dictate the value and type that needs to be passed in. The “:Unit” code is equivalent to returning void. The remaining code is setting the “_age” variable to “value”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person() {&lt;br /&gt;
// Private age variable, renamed to _age&lt;br /&gt;
private var _age = 0&lt;br /&gt;
var name = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Getter&lt;br /&gt;
def age = _age&lt;br /&gt;
&lt;br /&gt;
// Setter&lt;br /&gt;
def age_= (value:Int):Unit = _age = value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// We can invoke the setter as follows : &lt;br /&gt;
 can invoke the setter using the following: &lt;br /&gt;
person.age = 99&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
===Smalltalk===&lt;br /&gt;
'''&lt;br /&gt;
In [http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk] the names of getter methods are usually the same as the name of the instance variable. A colon is added to the end of setter method name e.g. colour:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     name                           &amp;quot;gets the value of name&amp;quot;&lt;br /&gt;
     name:aName              &amp;quot;sets name to the value of aName&amp;quot;&lt;br /&gt;
&lt;br /&gt;
     address                        &amp;quot;gets the value of address&amp;quot;&lt;br /&gt;
     address:anAddress     &amp;quot;sets anAddress to the value of anAddress&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Actionscript ===&lt;br /&gt;
'''&lt;br /&gt;
In [http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000171.html Flex] it is not usually necessary to create the wrapper getter and setting functions on an object because ActionScript supports properties. This means that you can usually just create public properties like:&lt;br /&gt;
public var firstName:String;&lt;br /&gt;
If the internal implementation of getting or setting the firstName property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class:&lt;br /&gt;
private var _firstName:String;&lt;br /&gt;
&lt;br /&gt;
Getting or setting the property would call the getter and setter functions instead of accessing the property directly&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public var firstName:String;&lt;br /&gt;
private var _firstName:String;&lt;br /&gt;
&lt;br /&gt;
public function get firstName():String {&lt;br /&gt;
   return _firstName;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public function set fullName(_firstName:String):void {&lt;br /&gt;
   this._firstName = _firstName;&lt;br /&gt;
}&lt;br /&gt;
// getters&lt;br /&gt;
var1 = obj.firstName;&lt;br /&gt;
var2 = obj['firstName'];&lt;br /&gt;
// setters&lt;br /&gt;
obj.firstName = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
obj['fullName'] = &amp;quot;Yes&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
==Getters and Setters from a different perspective==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
A fundamental precept of OO systems is that an object should not expose any of its implementation details. This way, you can change the implementation without changing the code that uses the object. It follows then that in OO systems you should avoid getter and setter functions since they mostly provide access to implementation details. For instance if you need change the return type of a getter method from int to long to accommodate the big numbers you need to change all the invocations of that getter method. This negates the concept of [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html information hiding]. The same issue arises when you need to change the accessed field’s type. You also have to change the getter’s return type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Solution:	 &lt;br /&gt;
Maintainability is inversely proportionate to the amount of data that moves between objects. Thus, its best to minimize data movement as much as possible. The idea is to focus on what you will do rather than how you will do it. Don't ask for the information you need to do the work; ask the object that has the information to do the work for you. Lets use an example to explain this better. While building user interfaces, we dont want UI builder class call methods like &amp;quot;GetAttributes()&amp;quot;. Classes can have methods like &amp;quot;DrawYourself()&amp;quot; and getters that returns an object that implements an interface. In our UI Construction example, GetIdentity() getter method can return an object that implements Identity Interface and this Interface includes the method &amp;quot;DrawYourself()&amp;quot;. This GetIdentity() call does not return a simple field but a complex object with a defined behavior and the internals of this object is kept hidden &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== When to Use Getters and Setters ? ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
1. When a getter returns an object that implements an Interface since the interface isolates the class that uses this interface from the implementing class. &lt;br /&gt;
2. Generic interfaces like Java Database Connectivity (JDBC) are unaware of how it will be used and in such cases getters are used to provide flexibility&lt;br /&gt;
&lt;br /&gt;
Programmers use getters and setters because of procedural language mindset. A useful design strategy to this end is to center our design in terms of use cases without getters and setters by thinking on the lines of communication or interaction between the objects with well defined behavior.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
'''&lt;br /&gt;
Getters and setters provide a convenient method to access the instance variables. A lot of new languages have come up with the support for accessing getters and setters as instance variable reference which improves the readability of the code. While such convenient mechanisms are available, it is important to use the getters and setters wisely with the goal of minimizing the data movement between the objects. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== References ==&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx Understanding properties in C#]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html why getters and setters are evil ]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set php5 OOPS tutorial]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://stefaanlippens.net/python_property_trick python-hiding attribute getters and setters behind standard attribute access]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 Object.defineProperty Function (JavaScript)]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Getters and Setters in Scala]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ ColdFusion 9 : Implicit/Generated CFC Methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000171.html Using getters and setters]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.touch-code-magazine.com/objective-c-properties/ Objective C properties]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Properties in Lua]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.netalive.org/tinkering/serious-perl/#import_extend Perl ]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Classes#Instance_Variables Ruby]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://java.about.com/od/workingwithobjects/a/accessormutator.htm Accessors and Mutators]&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=51122</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h hs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=51122"/>
		<updated>2011-09-26T02:33:25Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Advantages of getters and setters as method calls */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
== What are getters and setters ? ==&lt;br /&gt;
''' &lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide getter and setter methods to access/modify object data. When writing new classes, it's a good idea to pay attention to the issue of access control. Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. Because of this naming convention, accessor methods are more often referred to as getter methods. This is a good programming practice, since the data fields are not directly accessible outside the class. Thus 'Getters' and 'Setters' allow us to effectively protect your data. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Syntactic Notation ==&lt;br /&gt;
'''&lt;br /&gt;
There 2 common syntax for getters and setters available in programming languages: &lt;br /&gt;
&lt;br /&gt;
Method Call:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
value = ObjectName.getAttribute();&lt;br /&gt;
&lt;br /&gt;
ObjectName.setAttribute(val); &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above notation a getter is the same as any other instance method call. Its common for the getters and setters to be defined as public methods. &lt;br /&gt;
&lt;br /&gt;
Instance Variables:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectName.Field = Value;&lt;br /&gt;
&lt;br /&gt;
Value = ObjetName.Field;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this notation getters and setters looks like a accessing a class field. In most languages, internally this would invoke a method which would behave very similar to the getter method call described above. This syntactic notation offers a convenience of using intuitive syntax of getting or setting a variable.   &lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and setters as method calls ==&lt;br /&gt;
'''&lt;br /&gt;
For each variable, a get method will return its value and a set method will set the value. Here are the advantages of using getter and setter as method calls: &lt;br /&gt;
* [http://java.about.com/od/workingwithobjects/a/accessormutator.htm Encapsulate] the data from accidental / inadvertent modification. The private member variable is not part of the public interface of your class; only the public getter and setter methods are, and you are free to change their implementations without changing the public interface of your class&lt;br /&gt;
* If we decide that some action should be taken every time you change/access the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. For Instance, we can keep track of how many times a variable is accessed. &lt;br /&gt;
* Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== Advantages of getters and getters as variable references(properties) ==&lt;br /&gt;
'''&lt;br /&gt;
Properties are a robust way to handle object’s data. Properties support accessing the instance variables the same way as calling an instance method. A property communicates the idea of &amp;quot;I will make a value available to you, or accept a value from you.&amp;quot; It's not an implementation concept, it's an interface concept. Different languages follow specific syntax for adding a property to a class. Following are the advantages properties: &lt;br /&gt;
* the code is much cleaner when accessing a property when compared to Java or C++ which uses 2 separate methods for each instance variable. They are very useful in GUI programming which necessitates using a lot of fields for UI elements&lt;br /&gt;
* With properties we have fine-grained access control. For instance we can define a property as abstract thereby forcing the derived class to define that property. &lt;br /&gt;
* The main advantage of using properties is that if the internal implementation of getting or setting the property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class. This allows the interface of the object to stay the same even if the underlying implementation of getting and setting the property changes. &lt;br /&gt;
&lt;br /&gt;
Realizing the importance of getters and setters, popular IDEs like Eclipse, Visual studio has a built in mechanism to add getter and setter for a field or to create a property (in C#) for a given field.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples Languages that use getters and setters as method calls: ==&lt;br /&gt;
'''&lt;br /&gt;
'''&lt;br /&gt;
===C++===&lt;br /&gt;
'''&lt;br /&gt;
'Getters' and 'Setters' allow you to effectively protect your data. This is a technique used greatly when creating classes in C++. The getters and setters are usually public and the variables are made private. The reason for it is the data members are not accessible outside the class. For each variable, a get method will return its value and a set method will set the value.The reason for not editing the methods directly is twofold. Firstly, if you decide that some action should be taken every time you change the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
  int x_value;&lt;br /&gt;
&lt;br /&gt;
  public:&lt;br /&gt;
  // Getter&lt;br /&gt;
  int getx_value()&lt;br /&gt;
  {&lt;br /&gt;
      return x;&lt;br /&gt;
  }&lt;br /&gt;
  // Setter&lt;br /&gt;
  void setx_value( int x )&lt;br /&gt;
  {&lt;br /&gt;
      x_value = x;&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
void main()&lt;br /&gt;
{ &lt;br /&gt;
    A a;&lt;br /&gt;
    a.setx_value(5);&lt;br /&gt;
    cout&amp;lt;&amp;lt;a.getx_value();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class BookStore&lt;br /&gt;
{ &lt;br /&gt;
  String title;&lt;br /&gt;
  public String getTitle()&lt;br /&gt;
  {&lt;br /&gt;
     return title;&lt;br /&gt;
  }&lt;br /&gt;
  // a setter method might check that the value that is being assigned to the variable is legal&lt;br /&gt;
  public void setTitle( String newTitle ) &lt;br /&gt;
  {&lt;br /&gt;
    if ( newTitle == null )   // Don't allow null strings as titles!&lt;br /&gt;
       title = &amp;quot;(Untitled)&amp;quot;;  // Use an appropriate default value instead.&lt;br /&gt;
    else&lt;br /&gt;
       title = newTitle;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
     BookStore obj;&lt;br /&gt;
     obj. setTitle(&amp;quot;&amp;quot;);&lt;br /&gt;
     System.out.println(obj.getTitle());&lt;br /&gt;
}&lt;br /&gt;
Output:&lt;br /&gt;
(Untitled)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
'''&lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide accessor methods to modify object data. [http://www.netalive.org/tinkering/serious-perl/#import_extend Perl] does not have private variables but we can still use the concept of getter, setter functions methods.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub setName &lt;br /&gt;
{&lt;br /&gt;
   my ( $self, $Name ) = @_;&lt;br /&gt;
   $self-&amp;gt;{_Name} = $Name;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
sub getName &lt;br /&gt;
{&lt;br /&gt;
   my( $self ) = @_;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== ColdFusion === &lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
If we want to override the getter and setter method, you just need to define those methods in your [http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ CFC] and ColdFusion will call our method instead of calling the implicit one.The implicit methods can also do some nice validation if you have given the ‘type’ for properties. For instance, if we define a property as numeric and try to provide a try to set a string as its value It will throw a nice error saying “The value cannot be converted to a numeric”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Component Person&lt;br /&gt;
{&lt;br /&gt;
   property name&lt;br /&gt;
   property age;&lt;br /&gt;
   property city;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;!--- Once an object is created we can directly call the setters and getters for the properties as ---&amp;gt;&lt;br /&gt;
&amp;lt;cfscript&amp;gt;&lt;br /&gt;
   person = new Person();&lt;br /&gt;
   person.setName(&amp;quot;Brad&amp;quot;);&lt;br /&gt;
   person.setAge(46);&lt;br /&gt;
&lt;br /&gt;
   writeOutput(&amp;quot;Name : #person.getName()#&amp;quot;);&lt;br /&gt;
   writeOutput(&amp;quot;Age : #person.getAge()#&amp;quot;); &lt;br /&gt;
&amp;lt;/cfscript&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples from Languages that use getters and setters as instance variable references:  ==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== C#: ===&lt;br /&gt;
'''&lt;br /&gt;
In [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx C#], properties are nothing but natural extension of data fields. The properties are an important features added in language level inside C#.yC# also supports static properties, which belongs to the class rather than to the objects of the class. The properties of a Base class can be inherited to a Derived class and can be overridden by polymorphism. They are very useful in GUI programming. The compiler generates the appropriate getter and setter methods when it parses the C# property syntax.In C#, data encapsulation is possible through either classes or structures. By using various access modifiers like private, public, protected, internal etc it is possible to control the accessibility of the class members.  Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. This is a good programming practice, since the data fields are not directly accessible out side the class. We must use the set/get methods to access the data fields.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;class MyClass&lt;br /&gt;
{&lt;br /&gt;
      private int x;&lt;br /&gt;
      public int X&lt;br /&gt;
      {&lt;br /&gt;
            get&lt;br /&gt;
           {&lt;br /&gt;
             return x;&lt;br /&gt;
           }&lt;br /&gt;
          set&lt;br /&gt;
          {&lt;br /&gt;
             x = value;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
//Invocation&lt;br /&gt;
MyClass mc = new MyClass();&lt;br /&gt;
mc.X = 10;                   // calls set accessor of the property X, and pass 10 as value of the standard field 'value'.&lt;br /&gt;
Console.WriteLine(mc.X);     // displays 10. Calls the get accessor of the property X.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
===Lua===&lt;br /&gt;
'''&lt;br /&gt;
Getter and Setter functions can be implemented in [http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Lua], which is similar to the properties concept in C#. This allows the functions to bind to a property that can be assigned and accessed as a value.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class 'Test'&lt;br /&gt;
  function  Test : getLength()&lt;br /&gt;
   return # self.value&lt;br /&gt;
  end&lt;br /&gt;
  function  Test : setLength(newLength)&lt;br /&gt;
    for  i = self.length, newLength do&lt;br /&gt;
        table.insert(self.value, false )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
test =  Test({1, 2, 3, 4})&lt;br /&gt;
print(test.length)&lt;br /&gt;
self.length = property( Test.getLength, Test.setLength )    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
===Ruby===&lt;br /&gt;
'''&lt;br /&gt;
Ruby simplifies the creation of getters and setters with a little metaprogramming and the methods attr, attr_reader, attr_writer, and attr_accessor, all from the Module class. By supplying the attr method, Ruby provides a way to acces the instances directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
    def initialize(lname, fname)&lt;br /&gt;
        @lname = lname&lt;br /&gt;
        @fname = fname&lt;br /&gt;
    end&lt;br /&gt;
attr_reader :lname // creates a getter method&lt;br /&gt;
    attr_writer :lname    // creates a setter method&lt;br /&gt;
    attr_accessor :fname // creates both getter and setter method&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x = Person.new(&amp;quot;ABC&amp;quot;, &amp;quot;XYZ&amp;quot;)&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
x.fname = &amp;quot;PQR&amp;quot;&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
===Php===&lt;br /&gt;
'''&lt;br /&gt;
An interesting aspect of php worth noting is that we can assign values to undefined variables. Because of the above limitation, [http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set PHP] engine provides two magic methods __get() and __set(). __get() is used when value from an undefined variable is to be read and __set() is used when a value is to be assigned to a undefined variable of a class.In the above example when email@domain.com is assigned to the undefined variable $email, the magic method __set() is called. To this __set() method the name of the variable is passed into $dt variable of __set() method and the value i.e. email@domain.com is passed to $vl variable of the __set() method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
class Customer&lt;br /&gt;
{&lt;br /&gt;
   public $name;&lt;br /&gt;
   private $data = array();&lt;br /&gt;
   public function __set($dt, $vl) &lt;br /&gt;
   {&lt;br /&gt;
      $this-&amp;gt;data[$dt] = $vl;&lt;br /&gt;
   }&lt;br /&gt;
   public function __get($dt) &lt;br /&gt;
   {&lt;br /&gt;
      return $this-&amp;gt;data[$dt];&lt;br /&gt;
   }&lt;br /&gt;
} &lt;br /&gt;
$c = new Customer();&lt;br /&gt;
$c-&amp;gt;name = “Sunil”; // $name is set because its public&lt;br /&gt;
$c-&amp;gt;email = “email@domain.com”; //assigning email@domain.com to the $email variable.&lt;br /&gt;
echo $c-&amp;gt;email;&lt;br /&gt;
?&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Objective C===&lt;br /&gt;
'''&lt;br /&gt;
In [http://www.touch-code-magazine.com/objective-c-properties/ Objective C] we can define a property using @property directive. @synthesize will create automatically for you a setter and a getter methods for the property which becomes accessible during the run time.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// public header file&lt;br /&gt;
@interface MyObject : NSObject&lt;br /&gt;
{&lt;br /&gt;
  NSString *make; &lt;br /&gt;
  NSString* model;&lt;br /&gt;
  NSNumber* vin;&lt;br /&gt;
}&lt;br /&gt;
@property (readonly, copy) NSString *language;&lt;br /&gt;
@property(readwrite, retain) NSString* make;&lt;br /&gt;
@property(readwrite, retain) NSString* model;&lt;br /&gt;
@property(readwrite, retain) NSNumber* vin;&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
#import &amp;quot;SimpleCar.h&amp;quot;&lt;br /&gt;
@implementation SimpleCar&lt;br /&gt;
@synthesize make, model, vin;&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Python ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DoubleIt(object):&lt;br /&gt;
   def _get_value(self):&lt;br /&gt;
       return self._value * 2&lt;br /&gt;
   def _set_value(self, value):&lt;br /&gt;
       self._value = value&lt;br /&gt;
   value = property(_get_value, _set_value)&lt;br /&gt;
&lt;br /&gt;
# Invocation &lt;br /&gt;
x = DoubleIt()&lt;br /&gt;
 &lt;br /&gt;
x.value = 10&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = 'foo'&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = [1,2,3]&lt;br /&gt;
print x.value&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above [http://stefaanlippens.net/python_property_trick python] code, the output is doubled since the getter multiplies the value by 2&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Javascript ===&lt;br /&gt;
'''&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 JavaScript] supports accessing getters and setters as variable as properties. Javascript originally used __defineGetter__ and __defineSetter__ syntax to define properties which is depricated as the language evolved. Object.defineProperty is currently used for creating a property. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function addDataProperty()&lt;br /&gt;
{&lt;br /&gt;
   var newLine = &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;;&lt;br /&gt;
   var obj = {};&lt;br /&gt;
  &lt;br /&gt;
   // Add a data property to the object.&lt;br /&gt;
   Object.defineProperty(obj, &amp;quot;newDataProperty&amp;quot;, &lt;br /&gt;
   {&lt;br /&gt;
       value: 101,&lt;br /&gt;
       writable: true,&lt;br /&gt;
       enumerable: true,&lt;br /&gt;
       configurable: true&lt;br /&gt;
   });&lt;br /&gt;
&lt;br /&gt;
   // Set the property value.&lt;br /&gt;
   obj.newDataProperty = 102;&lt;br /&gt;
   document.write(&amp;quot;Property value: &amp;quot; + obj.newDataProperty + newLine);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Scala ===&lt;br /&gt;
'''&lt;br /&gt;
[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Scala] has some unconventional ideas that provide a solid, well thought out, and an abbreviated syntax to access object properties. This getter code simply defines a method called “age” and returns the “_age” variable. Scala doesn’t require the return keyword. The setter method name is “age_=”. The underscore is a special character in Scala and in this case, allows for a space in the method name which essentially makes the name “age =”. The parentheses and contents dictate the value and type that needs to be passed in. The “:Unit” code is equivalent to returning void. The remaining code is setting the “_age” variable to “value”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person() {&lt;br /&gt;
// Private age variable, renamed to _age&lt;br /&gt;
private var _age = 0&lt;br /&gt;
var name = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Getter&lt;br /&gt;
def age = _age&lt;br /&gt;
&lt;br /&gt;
// Setter&lt;br /&gt;
def age_= (value:Int):Unit = _age = value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// We can invoke the setter as follows : &lt;br /&gt;
 can invoke the setter using the following: &lt;br /&gt;
person.age = 99&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
===Smalltalk===&lt;br /&gt;
'''&lt;br /&gt;
In [http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk] the names of getter methods are usually the same as the name of the instance variable. A colon is added to the end of setter method name e.g. colour:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     name                           &amp;quot;gets the value of name&amp;quot;&lt;br /&gt;
     name:aName              &amp;quot;sets name to the value of aName&amp;quot;&lt;br /&gt;
&lt;br /&gt;
     address                        &amp;quot;gets the value of address&amp;quot;&lt;br /&gt;
     address:anAddress     &amp;quot;sets anAddress to the value of anAddress&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Actionscript ===&lt;br /&gt;
'''&lt;br /&gt;
In [http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000171.html Flex] it is not usually necessary to create the wrapper getter and setting functions on an object because ActionScript supports properties. This means that you can usually just create public properties like:&lt;br /&gt;
public var firstName:String;&lt;br /&gt;
If the internal implementation of getting or setting the firstName property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class:&lt;br /&gt;
private var _firstName:String;&lt;br /&gt;
&lt;br /&gt;
Getting or setting the property would call the getter and setter functions instead of accessing the property directly&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public var firstName:String;&lt;br /&gt;
private var _firstName:String;&lt;br /&gt;
&lt;br /&gt;
public function get firstName():String {&lt;br /&gt;
   return _firstName;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public function set fullName(_firstName:String):void {&lt;br /&gt;
   this._firstName = _firstName;&lt;br /&gt;
}&lt;br /&gt;
// getters&lt;br /&gt;
var1 = obj.firstName;&lt;br /&gt;
var2 = obj['firstName'];&lt;br /&gt;
// setters&lt;br /&gt;
obj.firstName = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
obj['fullName'] = &amp;quot;Yes&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
==Getters and Setters from a different perspective==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
A fundamental precept of OO systems is that an object should not expose any of its implementation details. This way, you can change the implementation without changing the code that uses the object. It follows then that in OO systems you should avoid getter and setter functions since they mostly provide access to implementation details. For instance if you need change the return type of a getter method from int to long to accommodate the big numbers you need to change all the invocations of that getter method. This negates the concept of [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html information hiding]. The same issue arises when you need to change the accessed field’s type. You also have to change the getter’s return type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Solution:	 &lt;br /&gt;
Maintainability is inversely proportionate to the amount of data that moves between objects. Thus, its best to minimize data movement as much as possible. The idea is to focus on what you will do rather than how you will do it. Don't ask for the information you need to do the work; ask the object that has the information to do the work for you. Lets use an example to explain this better. While building user interfaces, we dont want UI builder class call methods like &amp;quot;GetAttributes()&amp;quot;. Classes can have methods like &amp;quot;DrawYourself()&amp;quot; and getters that returns an object that implements an interface. In our UI Construction example, GetIdentity() getter method can return an object that implements Identity Interface and this Interface includes the method &amp;quot;DrawYourself()&amp;quot;. This GetIdentity() call does not return a simple field but a complex object with a defined behavior and the internals of this object is kept hidden &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== When to Use Getters and Setters ? ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
1. When a getter returns an object that implements an Interface since the interface isolates the class that uses this interface from the implementing class. &lt;br /&gt;
2. Generic interfaces like Java Database Connectivity (JDBC) are unaware of how it will be used and in such cases getters are used to provide flexibility&lt;br /&gt;
&lt;br /&gt;
Programmers use getters and setters because of procedural language mindset. A useful design strategy to this end is to center our design in terms of use cases without getters and setters by thinking on the lines of communication or interaction between the objects with well defined behavior.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
'''&lt;br /&gt;
Getters and setters provide a convenient method to access the instance variables. A lot of new languages have come up with the support for accessing getters and setters as instance variable reference which improves the readability of the code. While such convenient mechanisms are available, it is important to use the getters and setters wisely with the goal of minimizing the data movement between the objects. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== References ==&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx Understanding properties in C#]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html why getters and setters are evil ]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set php5 OOPS tutorial]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://stefaanlippens.net/python_property_trick python-hiding attribute getters and setters behind standard attribute access]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 Object.defineProperty Function (JavaScript)]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Getters and Setters in Scala]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ ColdFusion 9 : Implicit/Generated CFC Methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000171.html Using getters and setters]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.touch-code-magazine.com/objective-c-properties/ Objective C properties]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Properties in Lua]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.netalive.org/tinkering/serious-perl/#import_extend Perl ]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Classes#Instance_Variables Ruby]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://java.about.com/od/workingwithobjects/a/accessormutator.htm Accessors and Mutators]&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=51120</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h hs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=51120"/>
		<updated>2011-09-26T02:30:49Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
== What are getters and setters ? ==&lt;br /&gt;
''' &lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide getter and setter methods to access/modify object data. When writing new classes, it's a good idea to pay attention to the issue of access control. Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. Because of this naming convention, accessor methods are more often referred to as getter methods. This is a good programming practice, since the data fields are not directly accessible outside the class. Thus 'Getters' and 'Setters' allow us to effectively protect your data. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Syntactic Notation ==&lt;br /&gt;
'''&lt;br /&gt;
There 2 common syntax for getters and setters available in programming languages: &lt;br /&gt;
&lt;br /&gt;
Method Call:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
value = ObjectName.getAttribute();&lt;br /&gt;
&lt;br /&gt;
ObjectName.setAttribute(val); &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above notation a getter is the same as any other instance method call. Its common for the getters and setters to be defined as public methods. &lt;br /&gt;
&lt;br /&gt;
Instance Variables:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectName.Field = Value;&lt;br /&gt;
&lt;br /&gt;
Value = ObjetName.Field;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this notation getters and setters looks like a accessing a class field. In most languages, internally this would invoke a method which would behave very similar to the getter method call described above. This syntactic notation offers a convenience of using intuitive syntax of getting or setting a variable.   &lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and setters as method calls ==&lt;br /&gt;
'''&lt;br /&gt;
For each variable, a get method will return its value and a set method will set the value. Here are the advantages of using getter and setter as method calls: &lt;br /&gt;
* Encapsulate the data from accidental / inadvertent modification. The private member variable is not part of the public interface of your class; only the public getter and setter methods are, and you are free to change their implementations without changing the public interface of your class&lt;br /&gt;
* If we decide that some action should be taken every time you change/access the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. For Instance, we can keep track of how many times a variable is accessed. &lt;br /&gt;
* Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and getters as variable references(properties) ==&lt;br /&gt;
'''&lt;br /&gt;
Properties are a robust way to handle object’s data. Properties support accessing the instance variables the same way as calling an instance method. A property communicates the idea of &amp;quot;I will make a value available to you, or accept a value from you.&amp;quot; It's not an implementation concept, it's an interface concept. Different languages follow specific syntax for adding a property to a class. Following are the advantages properties: &lt;br /&gt;
* the code is much cleaner when accessing a property when compared to Java or C++ which uses 2 separate methods for each instance variable. They are very useful in GUI programming which necessitates using a lot of fields for UI elements&lt;br /&gt;
* With properties we have fine-grained access control. For instance we can define a property as abstract thereby forcing the derived class to define that property. &lt;br /&gt;
* The main advantage of using properties is that if the internal implementation of getting or setting the property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class. This allows the interface of the object to stay the same even if the underlying implementation of getting and setting the property changes. &lt;br /&gt;
&lt;br /&gt;
Realizing the importance of getters and setters, popular IDEs like Eclipse, Visual studio has a built in mechanism to add getter and setter for a field or to create a property (in C#) for a given field.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples Languages that use getters and setters as method calls: ==&lt;br /&gt;
'''&lt;br /&gt;
'''&lt;br /&gt;
===C++===&lt;br /&gt;
'''&lt;br /&gt;
'Getters' and 'Setters' allow you to effectively protect your data. This is a technique used greatly when creating classes in C++. The getters and setters are usually public and the variables are made private. The reason for it is the data members are not accessible outside the class. For each variable, a get method will return its value and a set method will set the value.The reason for not editing the methods directly is twofold. Firstly, if you decide that some action should be taken every time you change the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
  int x_value;&lt;br /&gt;
&lt;br /&gt;
  public:&lt;br /&gt;
  // Getter&lt;br /&gt;
  int getx_value()&lt;br /&gt;
  {&lt;br /&gt;
      return x;&lt;br /&gt;
  }&lt;br /&gt;
  // Setter&lt;br /&gt;
  void setx_value( int x )&lt;br /&gt;
  {&lt;br /&gt;
      x_value = x;&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
void main()&lt;br /&gt;
{ &lt;br /&gt;
    A a;&lt;br /&gt;
    a.setx_value(5);&lt;br /&gt;
    cout&amp;lt;&amp;lt;a.getx_value();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class BookStore&lt;br /&gt;
{ &lt;br /&gt;
  String title;&lt;br /&gt;
  public String getTitle()&lt;br /&gt;
  {&lt;br /&gt;
     return title;&lt;br /&gt;
  }&lt;br /&gt;
  // a setter method might check that the value that is being assigned to the variable is legal&lt;br /&gt;
  public void setTitle( String newTitle ) &lt;br /&gt;
  {&lt;br /&gt;
    if ( newTitle == null )   // Don't allow null strings as titles!&lt;br /&gt;
       title = &amp;quot;(Untitled)&amp;quot;;  // Use an appropriate default value instead.&lt;br /&gt;
    else&lt;br /&gt;
       title = newTitle;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
     BookStore obj;&lt;br /&gt;
     obj. setTitle(&amp;quot;&amp;quot;);&lt;br /&gt;
     System.out.println(obj.getTitle());&lt;br /&gt;
}&lt;br /&gt;
Output:&lt;br /&gt;
(Untitled)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
'''&lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide accessor methods to modify object data. [http://www.netalive.org/tinkering/serious-perl/#import_extend Perl] does not have private variables but we can still use the concept of getter, setter functions methods.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub setName &lt;br /&gt;
{&lt;br /&gt;
   my ( $self, $Name ) = @_;&lt;br /&gt;
   $self-&amp;gt;{_Name} = $Name;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
sub getName &lt;br /&gt;
{&lt;br /&gt;
   my( $self ) = @_;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== ColdFusion === &lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
If we want to override the getter and setter method, you just need to define those methods in your [http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ CFC] and ColdFusion will call our method instead of calling the implicit one.The implicit methods can also do some nice validation if you have given the ‘type’ for properties. For instance, if we define a property as numeric and try to provide a try to set a string as its value It will throw a nice error saying “The value cannot be converted to a numeric”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Component Person&lt;br /&gt;
{&lt;br /&gt;
   property name&lt;br /&gt;
   property age;&lt;br /&gt;
   property city;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;!--- Once an object is created we can directly call the setters and getters for the properties as ---&amp;gt;&lt;br /&gt;
&amp;lt;cfscript&amp;gt;&lt;br /&gt;
   person = new Person();&lt;br /&gt;
   person.setName(&amp;quot;Brad&amp;quot;);&lt;br /&gt;
   person.setAge(46);&lt;br /&gt;
&lt;br /&gt;
   writeOutput(&amp;quot;Name : #person.getName()#&amp;quot;);&lt;br /&gt;
   writeOutput(&amp;quot;Age : #person.getAge()#&amp;quot;); &lt;br /&gt;
&amp;lt;/cfscript&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples from Languages that use getters and setters as instance variable references:  ==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== C#: ===&lt;br /&gt;
'''&lt;br /&gt;
In [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx C#], properties are nothing but natural extension of data fields. The properties are an important features added in language level inside C#.yC# also supports static properties, which belongs to the class rather than to the objects of the class. The properties of a Base class can be inherited to a Derived class and can be overridden by polymorphism. They are very useful in GUI programming. The compiler generates the appropriate getter and setter methods when it parses the C# property syntax.In C#, data encapsulation is possible through either classes or structures. By using various access modifiers like private, public, protected, internal etc it is possible to control the accessibility of the class members.  Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. This is a good programming practice, since the data fields are not directly accessible out side the class. We must use the set/get methods to access the data fields.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;class MyClass&lt;br /&gt;
{&lt;br /&gt;
      private int x;&lt;br /&gt;
      public int X&lt;br /&gt;
      {&lt;br /&gt;
            get&lt;br /&gt;
           {&lt;br /&gt;
             return x;&lt;br /&gt;
           }&lt;br /&gt;
          set&lt;br /&gt;
          {&lt;br /&gt;
             x = value;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
//Invocation&lt;br /&gt;
MyClass mc = new MyClass();&lt;br /&gt;
mc.X = 10;                   // calls set accessor of the property X, and pass 10 as value of the standard field 'value'.&lt;br /&gt;
Console.WriteLine(mc.X);     // displays 10. Calls the get accessor of the property X.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
===Lua===&lt;br /&gt;
'''&lt;br /&gt;
Getter and Setter functions can be implemented in [http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Lua], which is similar to the properties concept in C#. This allows the functions to bind to a property that can be assigned and accessed as a value.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class 'Test'&lt;br /&gt;
  function  Test : getLength()&lt;br /&gt;
   return # self.value&lt;br /&gt;
  end&lt;br /&gt;
  function  Test : setLength(newLength)&lt;br /&gt;
    for  i = self.length, newLength do&lt;br /&gt;
        table.insert(self.value, false )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
test =  Test({1, 2, 3, 4})&lt;br /&gt;
print(test.length)&lt;br /&gt;
self.length = property( Test.getLength, Test.setLength )    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
===Ruby===&lt;br /&gt;
'''&lt;br /&gt;
Ruby simplifies the creation of getters and setters with a little metaprogramming and the methods attr, attr_reader, attr_writer, and attr_accessor, all from the Module class. By supplying the attr method, Ruby provides a way to acces the instances directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
    def initialize(lname, fname)&lt;br /&gt;
        @lname = lname&lt;br /&gt;
        @fname = fname&lt;br /&gt;
    end&lt;br /&gt;
attr_reader :lname // creates a getter method&lt;br /&gt;
    attr_writer :lname    // creates a setter method&lt;br /&gt;
    attr_accessor :fname // creates both getter and setter method&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x = Person.new(&amp;quot;ABC&amp;quot;, &amp;quot;XYZ&amp;quot;)&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
x.fname = &amp;quot;PQR&amp;quot;&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
===Php===&lt;br /&gt;
'''&lt;br /&gt;
An interesting aspect of php worth noting is that we can assign values to undefined variables. Because of the above limitation, [http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set PHP] engine provides two magic methods __get() and __set(). __get() is used when value from an undefined variable is to be read and __set() is used when a value is to be assigned to a undefined variable of a class.In the above example when email@domain.com is assigned to the undefined variable $email, the magic method __set() is called. To this __set() method the name of the variable is passed into $dt variable of __set() method and the value i.e. email@domain.com is passed to $vl variable of the __set() method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
class Customer&lt;br /&gt;
{&lt;br /&gt;
   public $name;&lt;br /&gt;
   private $data = array();&lt;br /&gt;
   public function __set($dt, $vl) &lt;br /&gt;
   {&lt;br /&gt;
      $this-&amp;gt;data[$dt] = $vl;&lt;br /&gt;
   }&lt;br /&gt;
   public function __get($dt) &lt;br /&gt;
   {&lt;br /&gt;
      return $this-&amp;gt;data[$dt];&lt;br /&gt;
   }&lt;br /&gt;
} &lt;br /&gt;
$c = new Customer();&lt;br /&gt;
$c-&amp;gt;name = “Sunil”; // $name is set because its public&lt;br /&gt;
$c-&amp;gt;email = “email@domain.com”; //assigning email@domain.com to the $email variable.&lt;br /&gt;
echo $c-&amp;gt;email;&lt;br /&gt;
?&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Objective C===&lt;br /&gt;
'''&lt;br /&gt;
In [http://www.touch-code-magazine.com/objective-c-properties/ Objective C] we can define a property using @property directive. @synthesize will create automatically for you a setter and a getter methods for the property which becomes accessible during the run time.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// public header file&lt;br /&gt;
@interface MyObject : NSObject&lt;br /&gt;
{&lt;br /&gt;
  NSString *make; &lt;br /&gt;
  NSString* model;&lt;br /&gt;
  NSNumber* vin;&lt;br /&gt;
}&lt;br /&gt;
@property (readonly, copy) NSString *language;&lt;br /&gt;
@property(readwrite, retain) NSString* make;&lt;br /&gt;
@property(readwrite, retain) NSString* model;&lt;br /&gt;
@property(readwrite, retain) NSNumber* vin;&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
#import &amp;quot;SimpleCar.h&amp;quot;&lt;br /&gt;
@implementation SimpleCar&lt;br /&gt;
@synthesize make, model, vin;&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Python ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DoubleIt(object):&lt;br /&gt;
   def _get_value(self):&lt;br /&gt;
       return self._value * 2&lt;br /&gt;
   def _set_value(self, value):&lt;br /&gt;
       self._value = value&lt;br /&gt;
   value = property(_get_value, _set_value)&lt;br /&gt;
&lt;br /&gt;
# Invocation &lt;br /&gt;
x = DoubleIt()&lt;br /&gt;
 &lt;br /&gt;
x.value = 10&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = 'foo'&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = [1,2,3]&lt;br /&gt;
print x.value&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above [http://stefaanlippens.net/python_property_trick python] code, the output is doubled since the getter multiplies the value by 2&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Javascript ===&lt;br /&gt;
'''&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 JavaScript] supports accessing getters and setters as variable as properties. Javascript originally used __defineGetter__ and __defineSetter__ syntax to define properties which is depricated as the language evolved. Object.defineProperty is currently used for creating a property. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function addDataProperty()&lt;br /&gt;
{&lt;br /&gt;
   var newLine = &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;;&lt;br /&gt;
   var obj = {};&lt;br /&gt;
  &lt;br /&gt;
   // Add a data property to the object.&lt;br /&gt;
   Object.defineProperty(obj, &amp;quot;newDataProperty&amp;quot;, &lt;br /&gt;
   {&lt;br /&gt;
       value: 101,&lt;br /&gt;
       writable: true,&lt;br /&gt;
       enumerable: true,&lt;br /&gt;
       configurable: true&lt;br /&gt;
   });&lt;br /&gt;
&lt;br /&gt;
   // Set the property value.&lt;br /&gt;
   obj.newDataProperty = 102;&lt;br /&gt;
   document.write(&amp;quot;Property value: &amp;quot; + obj.newDataProperty + newLine);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Scala ===&lt;br /&gt;
'''&lt;br /&gt;
[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Scala] has some unconventional ideas that provide a solid, well thought out, and an abbreviated syntax to access object properties. This getter code simply defines a method called “age” and returns the “_age” variable. Scala doesn’t require the return keyword. The setter method name is “age_=”. The underscore is a special character in Scala and in this case, allows for a space in the method name which essentially makes the name “age =”. The parentheses and contents dictate the value and type that needs to be passed in. The “:Unit” code is equivalent to returning void. The remaining code is setting the “_age” variable to “value”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person() {&lt;br /&gt;
// Private age variable, renamed to _age&lt;br /&gt;
private var _age = 0&lt;br /&gt;
var name = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Getter&lt;br /&gt;
def age = _age&lt;br /&gt;
&lt;br /&gt;
// Setter&lt;br /&gt;
def age_= (value:Int):Unit = _age = value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// We can invoke the setter as follows : &lt;br /&gt;
 can invoke the setter using the following: &lt;br /&gt;
person.age = 99&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
===Smalltalk===&lt;br /&gt;
'''&lt;br /&gt;
In [http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk] the names of getter methods are usually the same as the name of the instance variable. A colon is added to the end of setter method name e.g. colour:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     name                           &amp;quot;gets the value of name&amp;quot;&lt;br /&gt;
     name:aName              &amp;quot;sets name to the value of aName&amp;quot;&lt;br /&gt;
&lt;br /&gt;
     address                        &amp;quot;gets the value of address&amp;quot;&lt;br /&gt;
     address:anAddress     &amp;quot;sets anAddress to the value of anAddress&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Actionscript ===&lt;br /&gt;
'''&lt;br /&gt;
In [http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000171.html Flex] it is not usually necessary to create the wrapper getter and setting functions on an object because ActionScript supports properties. This means that you can usually just create public properties like:&lt;br /&gt;
public var firstName:String;&lt;br /&gt;
If the internal implementation of getting or setting the firstName property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class:&lt;br /&gt;
private var _firstName:String;&lt;br /&gt;
&lt;br /&gt;
Getting or setting the property would call the getter and setter functions instead of accessing the property directly&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public var firstName:String;&lt;br /&gt;
private var _firstName:String;&lt;br /&gt;
&lt;br /&gt;
public function get firstName():String {&lt;br /&gt;
   return _firstName;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public function set fullName(_firstName:String):void {&lt;br /&gt;
   this._firstName = _firstName;&lt;br /&gt;
}&lt;br /&gt;
// getters&lt;br /&gt;
var1 = obj.firstName;&lt;br /&gt;
var2 = obj['firstName'];&lt;br /&gt;
// setters&lt;br /&gt;
obj.firstName = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
obj['fullName'] = &amp;quot;Yes&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
==Getters and Setters from a different perspective==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
A fundamental precept of OO systems is that an object should not expose any of its implementation details. This way, you can change the implementation without changing the code that uses the object. It follows then that in OO systems you should avoid getter and setter functions since they mostly provide access to implementation details. For instance if you need change the return type of a getter method from int to long to accommodate the big numbers you need to change all the invocations of that getter method. This negates the concept of [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html information hiding]. The same issue arises when you need to change the accessed field’s type. You also have to change the getter’s return type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Solution:	 &lt;br /&gt;
Maintainability is inversely proportionate to the amount of data that moves between objects. Thus, its best to minimize data movement as much as possible. The idea is to focus on what you will do rather than how you will do it. Don't ask for the information you need to do the work; ask the object that has the information to do the work for you. Lets use an example to explain this better. While building user interfaces, we dont want UI builder class call methods like &amp;quot;GetAttributes()&amp;quot;. Classes can have methods like &amp;quot;DrawYourself()&amp;quot; and getters that returns an object that implements an interface. In our UI Construction example, GetIdentity() getter method can return an object that implements Identity Interface and this Interface includes the method &amp;quot;DrawYourself()&amp;quot;. This GetIdentity() call does not return a simple field but a complex object with a defined behavior and the internals of this object is kept hidden &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== When to Use Getters and Setters ? ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
1. When a getter returns an object that implements an Interface since the interface isolates the class that uses this interface from the implementing class. &lt;br /&gt;
2. Generic interfaces like Java Database Connectivity (JDBC) are unaware of how it will be used and in such cases getters are used to provide flexibility&lt;br /&gt;
&lt;br /&gt;
Programmers use getters and setters because of procedural language mindset. A useful design strategy to this end is to center our design in terms of use cases without getters and setters by thinking on the lines of communication or interaction between the objects with well defined behavior.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
'''&lt;br /&gt;
Getters and setters provide a convenient method to access the instance variables. A lot of new languages have come up with the support for accessing getters and setters as instance variable reference which improves the readability of the code. While such convenient mechanisms are available, it is important to use the getters and setters wisely with the goal of minimizing the data movement between the objects. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== References ==&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx Understanding properties in C#]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html why getters and setters are evil ]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set php5 OOPS tutorial]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://stefaanlippens.net/python_property_trick python-hiding attribute getters and setters behind standard attribute access]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 Object.defineProperty Function (JavaScript)]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Getters and Setters in Scala]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ ColdFusion 9 : Implicit/Generated CFC Methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000171.html Using getters and setters]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.touch-code-magazine.com/objective-c-properties/ Objective C properties]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Properties in Lua]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.netalive.org/tinkering/serious-perl/#import_extend Perl ]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Classes#Instance_Variables Ruby]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://java.about.com/od/workingwithobjects/a/accessormutator.htm Accessors and Mutators]&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=51115</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h hs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=51115"/>
		<updated>2011-09-26T02:25:37Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
== What are getters and setters ? ==&lt;br /&gt;
''' &lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide getter and setter methods to access/modify object data. When writing new classes, it's a good idea to pay attention to the issue of access control. Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. Because of this naming convention, accessor methods are more often referred to as getter methods. This is a good programming practice, since the data fields are not directly accessible outside the class. Thus 'Getters' and 'Setters' allow us to effectively protect your data. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Syntactic Notation ==&lt;br /&gt;
'''&lt;br /&gt;
There 2 common syntax for getters and setters available in programming languages: &lt;br /&gt;
&lt;br /&gt;
Method Call:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
value = ObjectName.getAttribute();&lt;br /&gt;
&lt;br /&gt;
ObjectName.setAttribute(val); &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above notation a getter is the same as any other instance method call. Its common for the getters and setters to be defined as public methods. &lt;br /&gt;
&lt;br /&gt;
Instance Variables:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectName.Field = Value;&lt;br /&gt;
&lt;br /&gt;
Value = ObjetName.Field;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this notation getters and setters looks like a accessing a class field. In most languages, internally this would invoke a method which would behave very similar to the getter method call described above. This syntactic notation offers a convenience of using intuitive syntax of getting or setting a variable.   &lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and setters as method calls ==&lt;br /&gt;
'''&lt;br /&gt;
For each variable, a get method will return its value and a set method will set the value. Here are the advantages of using getter and setter as method calls: &lt;br /&gt;
* Encapsulate the data from accidental / inadvertent modification. The private member variable is not part of the public interface of your class; only the public getter and setter methods are, and you are free to change their implementations without changing the public interface of your class&lt;br /&gt;
* If we decide that some action should be taken every time you change/access the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. For Instance, we can keep track of how many times a variable is accessed. &lt;br /&gt;
* Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and getters as variable references(properties) ==&lt;br /&gt;
'''&lt;br /&gt;
Properties are a robust way to handle object’s data. Properties support accessing the instance variables the same way as calling an instance method. A property communicates the idea of &amp;quot;I will make a value available to you, or accept a value from you.&amp;quot; It's not an implementation concept, it's an interface concept. Different languages follow specific syntax for adding a property to a class. Following are the advantages properties: &lt;br /&gt;
* the code is much cleaner when accessing a property when compared to Java or C++ which uses 2 separate methods for each instance variable. They are very useful in GUI programming which necessitates using a lot of fields for UI elements&lt;br /&gt;
* With properties we have fine-grained access control. For instance we can define a property as abstract thereby forcing the derived class to define that property. &lt;br /&gt;
* The main advantage of using properties is that if the internal implementation of getting or setting the property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class. This allows the interface of the object to stay the same even if the underlying implementation of getting and setting the property changes. &lt;br /&gt;
&lt;br /&gt;
Realizing the importance of getters and setters, popular IDEs like Eclipse, Visual studio has a built in mechanism to add getter and setter for a field or to create a property (in C#) for a given field.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples Languages that use getters and setters as method calls: ==&lt;br /&gt;
'''&lt;br /&gt;
'''&lt;br /&gt;
===C++===&lt;br /&gt;
'''&lt;br /&gt;
'Getters' and 'Setters' allow you to effectively protect your data. This is a technique used greatly when creating classes in C++. The getters and setters are usually public and the variables are made private. The reason for it is the data members are not accessible outside the class. For each variable, a get method will return its value and a set method will set the value.The reason for not editing the methods directly is twofold. Firstly, if you decide that some action should be taken every time you change the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
  int x_value;&lt;br /&gt;
&lt;br /&gt;
  public:&lt;br /&gt;
  // Getter&lt;br /&gt;
  int getx_value()&lt;br /&gt;
  {&lt;br /&gt;
      return x;&lt;br /&gt;
  }&lt;br /&gt;
  // Setter&lt;br /&gt;
  void setx_value( int x )&lt;br /&gt;
  {&lt;br /&gt;
      x_value = x;&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
void main()&lt;br /&gt;
{ &lt;br /&gt;
    A a;&lt;br /&gt;
    a.setx_value(5);&lt;br /&gt;
    cout&amp;lt;&amp;lt;a.getx_value();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class BookStore&lt;br /&gt;
{ &lt;br /&gt;
  String title;&lt;br /&gt;
  public String getTitle()&lt;br /&gt;
  {&lt;br /&gt;
     return title;&lt;br /&gt;
  }&lt;br /&gt;
  // a setter method might check that the value that is being assigned to the variable is legal&lt;br /&gt;
  public void setTitle( String newTitle ) &lt;br /&gt;
  {&lt;br /&gt;
    if ( newTitle == null )   // Don't allow null strings as titles!&lt;br /&gt;
       title = &amp;quot;(Untitled)&amp;quot;;  // Use an appropriate default value instead.&lt;br /&gt;
    else&lt;br /&gt;
       title = newTitle;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
     BookStore obj;&lt;br /&gt;
     obj. setTitle(&amp;quot;&amp;quot;);&lt;br /&gt;
     System.out.println(obj.getTitle());&lt;br /&gt;
}&lt;br /&gt;
Output:&lt;br /&gt;
(Untitled)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
'''&lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide accessor methods to modify object data. [http://www.netalive.org/tinkering/serious-perl/#import_extend Perl] does not have private variables but we can still use the concept of getter, setter functions methods.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub setName &lt;br /&gt;
{&lt;br /&gt;
   my ( $self, $Name ) = @_;&lt;br /&gt;
   $self-&amp;gt;{_Name} = $Name;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
sub getName &lt;br /&gt;
{&lt;br /&gt;
   my( $self ) = @_;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== ColdFusion === &lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
If we want to override the getter and setter method, you just need to define those methods in your [http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ CFC] and ColdFusion will call our method instead of calling the implicit one.The implicit methods can also do some nice validation if you have given the ‘type’ for properties. For instance, if we define a property as numeric and try to provide a try to set a string as its value It will throw a nice error saying “The value cannot be converted to a numeric”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Component Person&lt;br /&gt;
{&lt;br /&gt;
   property name&lt;br /&gt;
   property age;&lt;br /&gt;
   property city;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;!--- Once an object is created we can directly call the setters and getters for the properties as ---&amp;gt;&lt;br /&gt;
&amp;lt;cfscript&amp;gt;&lt;br /&gt;
   person = new Person();&lt;br /&gt;
   person.setName(&amp;quot;Brad&amp;quot;);&lt;br /&gt;
   person.setAge(46);&lt;br /&gt;
&lt;br /&gt;
   writeOutput(&amp;quot;Name : #person.getName()#&amp;quot;);&lt;br /&gt;
   writeOutput(&amp;quot;Age : #person.getAge()#&amp;quot;); &lt;br /&gt;
&amp;lt;/cfscript&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples from Languages that use getters and setters as instance variable references:  ==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== C#: ===&lt;br /&gt;
'''&lt;br /&gt;
In [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx C#], properties are nothing but natural extension of data fields. The properties are an important features added in language level inside C#.yC# also supports static properties, which belongs to the class rather than to the objects of the class. The properties of a Base class can be inherited to a Derived class and can be overridden by polymorphism. They are very useful in GUI programming. The compiler generates the appropriate getter and setter methods when it parses the C# property syntax.In C#, data encapsulation is possible through either classes or structures. By using various access modifiers like private, public, protected, internal etc it is possible to control the accessibility of the class members.  Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. This is a good programming practice, since the data fields are not directly accessible out side the class. We must use the set/get methods to access the data fields.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;class MyClass&lt;br /&gt;
{&lt;br /&gt;
      private int x;&lt;br /&gt;
      public int X&lt;br /&gt;
      {&lt;br /&gt;
            get&lt;br /&gt;
           {&lt;br /&gt;
             return x;&lt;br /&gt;
           }&lt;br /&gt;
          set&lt;br /&gt;
          {&lt;br /&gt;
             x = value;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
//Invocation&lt;br /&gt;
MyClass mc = new MyClass();&lt;br /&gt;
mc.X = 10;                   // calls set accessor of the property X, and pass 10 as value of the standard field 'value'.&lt;br /&gt;
Console.WriteLine(mc.X);     // displays 10. Calls the get accessor of the property X.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
===Lua===&lt;br /&gt;
'''&lt;br /&gt;
Getter and Setter functions can be implemented in [http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Lua], which is similar to the properties concept in C#. This allows the functions to bind to a property that can be assigned and accessed as a value.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class 'Test'&lt;br /&gt;
  function  Test : getLength()&lt;br /&gt;
   return # self.value&lt;br /&gt;
  end&lt;br /&gt;
  function  Test : setLength(newLength)&lt;br /&gt;
    for  i = self.length, newLength do&lt;br /&gt;
        table.insert(self.value, false )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
test =  Test({1, 2, 3, 4})&lt;br /&gt;
print(test.length)&lt;br /&gt;
self.length = property( Test.getLength, Test.setLength )    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
===Ruby===&lt;br /&gt;
'''&lt;br /&gt;
Ruby simplifies the creation of getters and setters with a little metaprogramming and the methods attr, attr_reader, attr_writer, and attr_accessor, all from the Module class. By supplying the attr method, Ruby provides a way to acces the instances directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
    def initialize(lname, fname)&lt;br /&gt;
        @lname = lname&lt;br /&gt;
        @fname = fname&lt;br /&gt;
    end&lt;br /&gt;
attr_reader :lname // creates a getter method&lt;br /&gt;
    attr_writer :lname    // creates a setter method&lt;br /&gt;
    attr_accessor :fname // creates both getter and setter method&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x = Person.new(&amp;quot;ABC&amp;quot;, &amp;quot;XYZ&amp;quot;)&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
x.fname = &amp;quot;PQR&amp;quot;&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
===Php===&lt;br /&gt;
'''&lt;br /&gt;
An interesting aspect of php worth noting is that we can assign values to undefined variables. Because of the above limitation, [http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set PHP] engine provides two magic methods __get() and __set(). __get() is used when value from an undefined variable is to be read and __set() is used when a value is to be assigned to a undefined variable of a class.In the above example when email@domain.com is assigned to the undefined variable $email, the magic method __set() is called. To this __set() method the name of the variable is passed into $dt variable of __set() method and the value i.e. email@domain.com is passed to $vl variable of the __set() method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
class Customer&lt;br /&gt;
{&lt;br /&gt;
   public $name;&lt;br /&gt;
   private $data = array();&lt;br /&gt;
   public function __set($dt, $vl) &lt;br /&gt;
   {&lt;br /&gt;
      $this-&amp;gt;data[$dt] = $vl;&lt;br /&gt;
   }&lt;br /&gt;
   public function __get($dt) &lt;br /&gt;
   {&lt;br /&gt;
      return $this-&amp;gt;data[$dt];&lt;br /&gt;
   }&lt;br /&gt;
} &lt;br /&gt;
$c = new Customer();&lt;br /&gt;
$c-&amp;gt;name = “Sunil”; // $name is set because its public&lt;br /&gt;
$c-&amp;gt;email = “email@domain.com”; //assigning email@domain.com to the $email variable.&lt;br /&gt;
echo $c-&amp;gt;email;&lt;br /&gt;
?&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Objective C===&lt;br /&gt;
'''&lt;br /&gt;
In [http://www.touch-code-magazine.com/objective-c-properties/ Objective C] we can define a property using @property directive. @synthesize will create automatically for you a setter and a getter methods for the property which becomes accessible during the run time.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// public header file&lt;br /&gt;
@interface MyObject : NSObject&lt;br /&gt;
{&lt;br /&gt;
  NSString *make; &lt;br /&gt;
  NSString* model;&lt;br /&gt;
  NSNumber* vin;&lt;br /&gt;
}&lt;br /&gt;
@property (readonly, copy) NSString *language;&lt;br /&gt;
@property(readwrite, retain) NSString* make;&lt;br /&gt;
@property(readwrite, retain) NSString* model;&lt;br /&gt;
@property(readwrite, retain) NSNumber* vin;&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
#import &amp;quot;SimpleCar.h&amp;quot;&lt;br /&gt;
@implementation SimpleCar&lt;br /&gt;
@synthesize make, model, vin;&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Python ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DoubleIt(object):&lt;br /&gt;
   def _get_value(self):&lt;br /&gt;
       return self._value * 2&lt;br /&gt;
   def _set_value(self, value):&lt;br /&gt;
       self._value = value&lt;br /&gt;
   value = property(_get_value, _set_value)&lt;br /&gt;
&lt;br /&gt;
# Invocation &lt;br /&gt;
x = DoubleIt()&lt;br /&gt;
 &lt;br /&gt;
x.value = 10&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = 'foo'&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = [1,2,3]&lt;br /&gt;
print x.value&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above [http://stefaanlippens.net/python_property_trick python] code, the output is doubled since the getter multiplies the value by 2&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Javascript ===&lt;br /&gt;
'''&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 JavaScript] supports accessing getters and setters as variable as properties. Javascript originally used __defineGetter__ and __defineSetter__ syntax to define properties which is depricated as the language evolved. Object.defineProperty is currently used for creating a property. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function addDataProperty()&lt;br /&gt;
{&lt;br /&gt;
   var newLine = &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;;&lt;br /&gt;
   var obj = {};&lt;br /&gt;
  &lt;br /&gt;
   // Add a data property to the object.&lt;br /&gt;
   Object.defineProperty(obj, &amp;quot;newDataProperty&amp;quot;, &lt;br /&gt;
   {&lt;br /&gt;
       value: 101,&lt;br /&gt;
       writable: true,&lt;br /&gt;
       enumerable: true,&lt;br /&gt;
       configurable: true&lt;br /&gt;
   });&lt;br /&gt;
&lt;br /&gt;
   // Set the property value.&lt;br /&gt;
   obj.newDataProperty = 102;&lt;br /&gt;
   document.write(&amp;quot;Property value: &amp;quot; + obj.newDataProperty + newLine);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Scala ===&lt;br /&gt;
'''&lt;br /&gt;
[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Scala] has some unconventional ideas that provide a solid, well thought out, and an abbreviated syntax to access object properties. This getter code simply defines a method called “age” and returns the “_age” variable. Scala doesn’t require the return keyword. The setter method name is “age_=”. The underscore is a special character in Scala and in this case, allows for a space in the method name which essentially makes the name “age =”. The parentheses and contents dictate the value and type that needs to be passed in. The “:Unit” code is equivalent to returning void. The remaining code is setting the “_age” variable to “value”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person() {&lt;br /&gt;
// Private age variable, renamed to _age&lt;br /&gt;
private var _age = 0&lt;br /&gt;
var name = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Getter&lt;br /&gt;
def age = _age&lt;br /&gt;
&lt;br /&gt;
// Setter&lt;br /&gt;
def age_= (value:Int):Unit = _age = value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// We can invoke the setter as follows : &lt;br /&gt;
 can invoke the setter using the following: &lt;br /&gt;
person.age = 99&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
===Smalltalk===&lt;br /&gt;
'''&lt;br /&gt;
In [http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk] the names of getter methods are usually the same as the name of the instance variable. A colon is added to the end of setter method name e.g. colour:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     name                           &amp;quot;gets the value of name&amp;quot;&lt;br /&gt;
     name:aName              &amp;quot;sets name to the value of aName&amp;quot;&lt;br /&gt;
&lt;br /&gt;
     address                        &amp;quot;gets the value of address&amp;quot;&lt;br /&gt;
     address:anAddress     &amp;quot;sets anAddress to the value of anAddress&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Actionscript ===&lt;br /&gt;
'''&lt;br /&gt;
In [http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000171.html Flex] it is not usually necessary to create the wrapper getter and setting functions on an object because ActionScript supports properties. This means that you can usually just create public properties like:&lt;br /&gt;
public var firstName:String;&lt;br /&gt;
If the internal implementation of getting or setting the firstName property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class:&lt;br /&gt;
private var _firstName:String;&lt;br /&gt;
&lt;br /&gt;
Getting or setting the property would call the getter and setter functions instead of accessing the property directly&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public var firstName:String;&lt;br /&gt;
private var _firstName:String;&lt;br /&gt;
&lt;br /&gt;
public function get firstName():String {&lt;br /&gt;
   return _firstName;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public function set fullName(_firstName:String):void {&lt;br /&gt;
   this._firstName = _firstName;&lt;br /&gt;
}&lt;br /&gt;
// getters&lt;br /&gt;
var1 = obj.firstName;&lt;br /&gt;
var2 = obj['firstName'];&lt;br /&gt;
// setters&lt;br /&gt;
obj.firstName = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
obj['fullName'] = &amp;quot;Yes&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
==Getters and Setters from a different perspective==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
A fundamental precept of OO systems is that an object should not expose any of its implementation details. This way, you can change the implementation without changing the code that uses the object. It follows then that in OO systems you should avoid getter and setter functions since they mostly provide access to implementation details. For instance if you need change the return type of a getter method from int to long to accommodate the big numbers you need to change all the invocations of that getter method. This negates the concept of [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html information hiding]. The same issue arises when you need to change the accessed field’s type. You also have to change the getter’s return type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Solution:	 &lt;br /&gt;
Maintainability is inversely proportionate to the amount of data that moves between objects. Thus, its best to minimize data movement as much as possible. The idea is to focus on what you will do rather than how you will do it. Don't ask for the information you need to do the work; ask the object that has the information to do the work for you. Lets use an example to explain this better. While building user interfaces, we dont want UI builder class call methods like &amp;quot;GetAttributes()&amp;quot;. Classes can have methods like &amp;quot;DrawYourself()&amp;quot; and getters that returns an object that implements an interface. In our UI Construction example, GetIdentity() getter method can return an object that implements Identity Interface and this Interface includes the method &amp;quot;DrawYourself()&amp;quot;. This GetIdentity() call does not return a simple field but a complex object with a defined behavior and the internals of this object is kept hidden &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== When to Use Getters and Setters ? ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
1. When a getter returns an object that implements an Interface since the interface isolates the class that uses this interface from the implementing class. &lt;br /&gt;
2. Generic interfaces like Java Database Connectivity (JDBC) are unaware of how it will be used and in such cases getters are used to provide flexibility&lt;br /&gt;
&lt;br /&gt;
Programmers use getters and setters because of procedural language mindset. A useful design strategy to this end is to center our design in terms of use cases without getters and setters by thinking on the lines of communication or interaction between the objects with well defined behavior.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
'''&lt;br /&gt;
Getters and setters provide a convenient method to access the instance variables. A lot of new languages have come up with the support for accessing getters and setters as instance variable reference which improves the readability of the code. While such convenient mechanisms are available, it is important to use the getters and setters wisely with the goal of minimizing the data movement between the objects. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== References ==&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx Understanding properties in C#]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html why getters and setters are evil ]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set php5 OOPS tutorial]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://stefaanlippens.net/python_property_trick python-hiding attribute getters and setters behind standard attribute access]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 Object.defineProperty Function (JavaScript)]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Getters and Setters in Scala]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ ColdFusion 9 : Implicit/Generated CFC Methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000171.html Using getters and setters]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.touch-code-magazine.com/objective-c-properties/ Objective C properties]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Properties in Lua]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.netalive.org/tinkering/serious-perl/#import_extend Perl ]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Classes#Instance_Variables Ruby]&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=51103</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h hs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=51103"/>
		<updated>2011-09-26T02:01:16Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
== What are getters and setters ? ==&lt;br /&gt;
''' &lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide getter and setter methods to access/modify object data. When writing new classes, it's a good idea to pay attention to the issue of access control. Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. Because of this naming convention, accessor methods are more often referred to as getter methods. This is a good programming practice, since the data fields are not directly accessible outside the class. Thus 'Getters' and 'Setters' allow us to effectively protect your data. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Syntactic Notation ==&lt;br /&gt;
'''&lt;br /&gt;
There 2 common syntax for getters and setters available in programming languages: &lt;br /&gt;
&lt;br /&gt;
Method Call:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
value = ObjectName.getAttribute();&lt;br /&gt;
&lt;br /&gt;
ObjectName.setAttribute(val); &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above notation a getter is the same as any other instance method call. Its common for the getters and setters to be defined as public methods. &lt;br /&gt;
&lt;br /&gt;
Instance Variables:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ObjectName.Field = Value;&lt;br /&gt;
Value = ObjetName.Field;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this notation getters and setters looks like a accessing a class field. In most languages, internally this would invoke a method which would behave very similar to the getter method call described above. This syntactic notation offers a convenience of using intuitive syntax of getting or setting a variable.   &lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and setters as method calls ==&lt;br /&gt;
'''&lt;br /&gt;
For each variable, a get method will return its value and a set method will set the value. Here are the advantages of using getter and setter as method calls: &lt;br /&gt;
* Encapsulate the data from accidental / inadvertent modification. The private member variable is not part of the public interface of your class; only the public getter and setter methods are, and you are free to change their implementations without changing the public interface of your class&lt;br /&gt;
* If we decide that some action should be taken every time you change/access the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. For Instance, we can keep track of how many times a variable is accessed. &lt;br /&gt;
* Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and getters as variable references(properties) ==&lt;br /&gt;
'''&lt;br /&gt;
Properties are a robust way to handle object’s data. Properties support accessing the instance variables the same way as calling an instance method. A property communicates the idea of &amp;quot;I will make a value available to you, or accept a value from you.&amp;quot; It's not an implementation concept, it's an interface concept. Different languages follow specific syntax for adding a property to a class. Following are the advantages properties: &lt;br /&gt;
* the code is much cleaner when accessing a property when compared to Java or C++ which uses 2 separate methods for each instance variable. They are very useful in GUI programming which necessitates using a lot of fields for UI elements&lt;br /&gt;
* With properties we have fine-grained access control. For instance we can define a property as abstract thereby forcing the derived class to define that property. &lt;br /&gt;
* The main advantage of using properties is that if the internal implementation of getting or setting the property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class. This allows the interface of the object to stay the same even if the underlying implementation of getting and setting the property changes. &lt;br /&gt;
&lt;br /&gt;
Realizing the importance of getters and setters, popular IDEs like Eclipse, Visual studio has a built in mechanism to add getter and setter for a field or to create a property (in C#) for a given field.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples Languages that use getters and setters as method calls: ==&lt;br /&gt;
'''&lt;br /&gt;
'''&lt;br /&gt;
===C++===&lt;br /&gt;
'''&lt;br /&gt;
'Getters' and 'Setters' allow you to effectively protect your data. This is a technique used greatly when creating classes in C++. The getters and setters are usually public and the variables are made private. The reason for it is the data members are not accessible outside the class. For each variable, a get method will return its value and a set method will set the value.The reason for not editing the methods directly is twofold. Firstly, if you decide that some action should be taken every time you change the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
  int x_value;&lt;br /&gt;
&lt;br /&gt;
  public:&lt;br /&gt;
  // Getter&lt;br /&gt;
  int getx_value()&lt;br /&gt;
  {&lt;br /&gt;
      return x;&lt;br /&gt;
  }&lt;br /&gt;
  // Setter&lt;br /&gt;
  void setx_value( int x )&lt;br /&gt;
  {&lt;br /&gt;
      x_value = x;&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
void main()&lt;br /&gt;
{ &lt;br /&gt;
    A a;&lt;br /&gt;
    a.setx_value(5);&lt;br /&gt;
    cout&amp;lt;&amp;lt;a.getx_value();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class BookStore&lt;br /&gt;
{ &lt;br /&gt;
  String title;&lt;br /&gt;
  public String getTitle()&lt;br /&gt;
  {&lt;br /&gt;
     return title;&lt;br /&gt;
  }&lt;br /&gt;
  // a setter method might check that the value that is being assigned to the variable is legal&lt;br /&gt;
  public void setTitle( String newTitle ) &lt;br /&gt;
  {&lt;br /&gt;
    if ( newTitle == null )   // Don't allow null strings as titles!&lt;br /&gt;
       title = &amp;quot;(Untitled)&amp;quot;;  // Use an appropriate default value instead.&lt;br /&gt;
    else&lt;br /&gt;
       title = newTitle;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
     BookStore obj;&lt;br /&gt;
     obj. setTitle(&amp;quot;&amp;quot;);&lt;br /&gt;
     System.out.println(obj.getTitle());&lt;br /&gt;
}&lt;br /&gt;
Output:&lt;br /&gt;
(Untitled)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
'''&lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide accessor methods to modify object data. [http://www.netalive.org/tinkering/serious-perl/#import_extend Perl] does not have private variables but we can still use the concept of getter, setter functions methods.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub setName &lt;br /&gt;
{&lt;br /&gt;
   my ( $self, $Name ) = @_;&lt;br /&gt;
   $self-&amp;gt;{_Name} = $Name;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
sub getName &lt;br /&gt;
{&lt;br /&gt;
   my( $self ) = @_;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== ColdFusion === &lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
If we want to override the getter and setter method, you just need to define those methods in your [http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ CFC] and ColdFusion will call our method instead of calling the implicit one.The implicit methods can also do some nice validation if you have given the ‘type’ for properties. For instance, if we define a property as numeric and try to provide a try to set a string as its value It will throw a nice error saying “The value cannot be converted to a numeric”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Component Person&lt;br /&gt;
{&lt;br /&gt;
   property name&lt;br /&gt;
   property age;&lt;br /&gt;
   property city;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;!--- Once an object is created we can directly call the setters and getters for the properties as ---&amp;gt;&lt;br /&gt;
&amp;lt;cfscript&amp;gt;&lt;br /&gt;
   person = new Person();&lt;br /&gt;
   person.setName(&amp;quot;Brad&amp;quot;);&lt;br /&gt;
   person.setAge(46);&lt;br /&gt;
&lt;br /&gt;
   writeOutput(&amp;quot;Name : #person.getName()#&amp;quot;);&lt;br /&gt;
   writeOutput(&amp;quot;Age : #person.getAge()#&amp;quot;); &lt;br /&gt;
&amp;lt;/cfscript&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples from Languages that use getters and setters as instance variable references:  ==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== C#: ===&lt;br /&gt;
'''&lt;br /&gt;
In [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx C#], properties are nothing but natural extension of data fields. The properties are an important features added in language level inside C#.yC# also supports static properties, which belongs to the class rather than to the objects of the class. The properties of a Base class can be inherited to a Derived class and can be overridden by polymorphism. They are very useful in GUI programming. The compiler generates the appropriate getter and setter methods when it parses the C# property syntax.In C#, data encapsulation is possible through either classes or structures. By using various access modifiers like private, public, protected, internal etc it is possible to control the accessibility of the class members.  Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. This is a good programming practice, since the data fields are not directly accessible out side the class. We must use the set/get methods to access the data fields.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;class MyClass&lt;br /&gt;
{&lt;br /&gt;
      private int x;&lt;br /&gt;
      public int X&lt;br /&gt;
      {&lt;br /&gt;
            get&lt;br /&gt;
           {&lt;br /&gt;
             return x;&lt;br /&gt;
           }&lt;br /&gt;
          set&lt;br /&gt;
          {&lt;br /&gt;
             x = value;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
//Invocation&lt;br /&gt;
MyClass mc = new MyClass();&lt;br /&gt;
mc.X = 10;                   // calls set accessor of the property X, and pass 10 as value of the standard field 'value'.&lt;br /&gt;
Console.WriteLine(mc.X);     // displays 10. Calls the get accessor of the property X.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
===Lua===&lt;br /&gt;
'''&lt;br /&gt;
Getter and Setter functions can be implemented in [http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Lua], which is similar to the properties concept in C#. This allows the functions to bind to a property that can be assigned and accessed as a value.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class 'Test'&lt;br /&gt;
  function  Test : getLength()&lt;br /&gt;
   return # self.value&lt;br /&gt;
  end&lt;br /&gt;
  function  Test : setLength(newLength)&lt;br /&gt;
    for  i = self.length, newLength do&lt;br /&gt;
        table.insert(self.value, false )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
test =  Test({1, 2, 3, 4})&lt;br /&gt;
print(test.length)&lt;br /&gt;
self.length = property( Test.getLength, Test.setLength )    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
===Ruby===&lt;br /&gt;
'''&lt;br /&gt;
Ruby simplifies the creation of getters and setters with a little metaprogramming and the methods attr, attr_reader, attr_writer, and attr_accessor, all from the Module class. By supplying the attr method, Ruby provides a way to acces the instances directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
    def initialize(lname, fname)&lt;br /&gt;
        @lname = lname&lt;br /&gt;
        @fname = fname&lt;br /&gt;
    end&lt;br /&gt;
attr_reader :lname // creates a getter method&lt;br /&gt;
    attr_writer :lname    // creates a setter method&lt;br /&gt;
    attr_accessor :fname // creates both getter and setter method&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x = Person.new(&amp;quot;ABC&amp;quot;, &amp;quot;XYZ&amp;quot;)&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
x.fname = &amp;quot;PQR&amp;quot;&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
===Php===&lt;br /&gt;
'''&lt;br /&gt;
An interesting aspect of php worth noting is that we can assign values to undefined variables. Because of the above limitation, [http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set PHP] engine provides two magic methods __get() and __set(). __get() is used when value from an undefined variable is to be read and __set() is used when a value is to be assigned to a undefined variable of a class.In the above example when email@domain.com is assigned to the undefined variable $email, the magic method __set() is called. To this __set() method the name of the variable is passed into $dt variable of __set() method and the value i.e. email@domain.com is passed to $vl variable of the __set() method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
class Customer&lt;br /&gt;
{&lt;br /&gt;
   public $name;&lt;br /&gt;
   private $data = array();&lt;br /&gt;
   public function __set($dt, $vl) &lt;br /&gt;
   {&lt;br /&gt;
      $this-&amp;gt;data[$dt] = $vl;&lt;br /&gt;
   }&lt;br /&gt;
   public function __get($dt) &lt;br /&gt;
   {&lt;br /&gt;
      return $this-&amp;gt;data[$dt];&lt;br /&gt;
   }&lt;br /&gt;
} &lt;br /&gt;
$c = new Customer();&lt;br /&gt;
$c-&amp;gt;name = “Sunil”; // $name is set because its public&lt;br /&gt;
$c-&amp;gt;email = “email@domain.com”; //assigning email@domain.com to the $email variable.&lt;br /&gt;
echo $c-&amp;gt;email;&lt;br /&gt;
?&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Objective C===&lt;br /&gt;
'''&lt;br /&gt;
In [http://www.touch-code-magazine.com/objective-c-properties/ Objective C] we can define a property using @property directive. @synthesize will create automatically for you a setter and a getter methods for the property which becomes accessible during the run time.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// public header file&lt;br /&gt;
@interface MyObject : NSObject&lt;br /&gt;
{&lt;br /&gt;
  NSString *make; &lt;br /&gt;
  NSString* model;&lt;br /&gt;
  NSNumber* vin;&lt;br /&gt;
}&lt;br /&gt;
@property (readonly, copy) NSString *language;&lt;br /&gt;
@property(readwrite, retain) NSString* make;&lt;br /&gt;
@property(readwrite, retain) NSString* model;&lt;br /&gt;
@property(readwrite, retain) NSNumber* vin;&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
#import &amp;quot;SimpleCar.h&amp;quot;&lt;br /&gt;
@implementation SimpleCar&lt;br /&gt;
@synthesize make, model, vin;&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Python ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DoubleIt(object):&lt;br /&gt;
   def _get_value(self):&lt;br /&gt;
       return self._value * 2&lt;br /&gt;
   def _set_value(self, value):&lt;br /&gt;
       self._value = value&lt;br /&gt;
   value = property(_get_value, _set_value)&lt;br /&gt;
&lt;br /&gt;
# Invocation &lt;br /&gt;
x = DoubleIt()&lt;br /&gt;
 &lt;br /&gt;
x.value = 10&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = 'foo'&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = [1,2,3]&lt;br /&gt;
print x.value&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above [http://stefaanlippens.net/python_property_trick python] code, the output is doubled since the getter multiplies the value by 2&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Javascript ===&lt;br /&gt;
'''&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 JavaScript] supports accessing getters and setters as variable as properties. Javascript originally used __defineGetter__ and __defineSetter__ syntax to define properties which is depricated as the language evolved. Object.defineProperty is currently used for creating a property. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function addDataProperty()&lt;br /&gt;
{&lt;br /&gt;
   var newLine = &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;;&lt;br /&gt;
   var obj = {};&lt;br /&gt;
  &lt;br /&gt;
   // Add a data property to the object.&lt;br /&gt;
   Object.defineProperty(obj, &amp;quot;newDataProperty&amp;quot;, &lt;br /&gt;
   {&lt;br /&gt;
       value: 101,&lt;br /&gt;
       writable: true,&lt;br /&gt;
       enumerable: true,&lt;br /&gt;
       configurable: true&lt;br /&gt;
   });&lt;br /&gt;
&lt;br /&gt;
   // Set the property value.&lt;br /&gt;
   obj.newDataProperty = 102;&lt;br /&gt;
   document.write(&amp;quot;Property value: &amp;quot; + obj.newDataProperty + newLine);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Scala ===&lt;br /&gt;
'''&lt;br /&gt;
[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Scala] has some unconventional ideas that provide a solid, well thought out, and an abbreviated syntax to access object properties. This getter code simply defines a method called “age” and returns the “_age” variable. Scala doesn’t require the return keyword. The setter method name is “age_=”. The underscore is a special character in Scala and in this case, allows for a space in the method name which essentially makes the name “age =”. The parentheses and contents dictate the value and type that needs to be passed in. The “:Unit” code is equivalent to returning void. The remaining code is setting the “_age” variable to “value”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person() {&lt;br /&gt;
// Private age variable, renamed to _age&lt;br /&gt;
private var _age = 0&lt;br /&gt;
var name = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Getter&lt;br /&gt;
def age = _age&lt;br /&gt;
&lt;br /&gt;
// Setter&lt;br /&gt;
def age_= (value:Int):Unit = _age = value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// We can invoke the setter as follows : &lt;br /&gt;
 can invoke the setter using the following: &lt;br /&gt;
person.age = 99&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
===Smalltalk===&lt;br /&gt;
'''&lt;br /&gt;
In [http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk] the names of getter methods are usually the same as the name of the instance variable. A colon is added to the end of setter method name e.g. colour:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     name                           &amp;quot;gets the value of name&amp;quot;&lt;br /&gt;
     name:aName              &amp;quot;sets name to the value of aName&amp;quot;&lt;br /&gt;
&lt;br /&gt;
     address                        &amp;quot;gets the value of address&amp;quot;&lt;br /&gt;
     address:anAddress     &amp;quot;sets anAddress to the value of anAddress&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Actionscript ===&lt;br /&gt;
'''&lt;br /&gt;
In [http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000171.html Flex] it is not usually necessary to create the wrapper getter and setting functions on an object because ActionScript supports properties. This means that you can usually just create public properties like:&lt;br /&gt;
public var firstName:String;&lt;br /&gt;
If the internal implementation of getting or setting the firstName property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class:&lt;br /&gt;
private var _firstName:String;&lt;br /&gt;
&lt;br /&gt;
Getting or setting the property would call the getter and setter functions instead of accessing the property directly&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public var firstName:String;&lt;br /&gt;
private var _firstName:String;&lt;br /&gt;
&lt;br /&gt;
public function get firstName():String {&lt;br /&gt;
   return _firstName;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public function set fullName(_firstName:String):void {&lt;br /&gt;
   this._firstName = _firstName;&lt;br /&gt;
}&lt;br /&gt;
// getters&lt;br /&gt;
var1 = obj.firstName;&lt;br /&gt;
var2 = obj['firstName'];&lt;br /&gt;
// setters&lt;br /&gt;
obj.firstName = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
obj['fullName'] = &amp;quot;Yes&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
==Getters and Setters from a different perspective==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
A fundamental precept of OO systems is that an object should not expose any of its implementation details. This way, you can change the implementation without changing the code that uses the object. It follows then that in OO systems you should avoid getter and setter functions since they mostly provide access to implementation details. For instance if you need change the return type of a getter method from int to long to accommodate the big numbers you need to change all the invocations of that getter method. This negates the concept of [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html information hiding]. The same issue arises when you need to change the accessed field’s type. You also have to change the getter’s return type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Solution:	 &lt;br /&gt;
Maintainability is inversely proportionate to the amount of data that moves between objects. Thus, its best to minimize data movement as much as possible. The idea is to focus on what you will do rather than how you will do it. Don't ask for the information you need to do the work; ask the object that has the information to do the work for you. Lets use an example to explain this better. While building user interfaces, we dont want UI builder class call methods like &amp;quot;GetAttributes()&amp;quot;. Classes can have methods like &amp;quot;DrawYourself()&amp;quot; and getters that returns an object that implements an interface. In our UI Construction example, GetIdentity() getter method can return an object that implements Identity Interface and this Interface includes the method &amp;quot;DrawYourself()&amp;quot;. This GetIdentity() call does not return a simple field but a complex object with a defined behavior and the internals of this object is kept hidden &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== When to Use Getters and Setters ? ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
1. When a getter returns an object that implements an Interface since the interface isolates the class that uses this interface from the implementing class. &lt;br /&gt;
2. Generic interfaces like Java Database Connectivity (JDBC) are unaware of how it will be used and in such cases getters are used to provide flexibility&lt;br /&gt;
&lt;br /&gt;
Programmers use getters and setters because of procedural language mindset. A useful design strategy to this end is to center our design in terms of use cases without getters and setters by thinking on the lines of communication or interaction between the objects with well defined behavior.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
'''&lt;br /&gt;
Getters and setters provide a convenient method to access the instance variables. A lot of new languages have come up with the support for accessing getters and setters as instance variable reference which improves the readability of the code. While such convenient mechanisms are available, it is important to use the getters and setters wisely with the goal of minimizing the data movement between the objects. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== References ==&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx Understanding properties in C#]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html why getters and setters are evil ]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set php5 OOPS tutorial]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://stefaanlippens.net/python_property_trick python-hiding attribute getters and setters behind standard attribute access]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 Object.defineProperty Function (JavaScript)]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Getters and Setters in Scala]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ ColdFusion 9 : Implicit/Generated CFC Methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000171.html Using getters and setters]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.touch-code-magazine.com/objective-c-properties/ Objective C properties]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Properties in Lua]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.netalive.org/tinkering/serious-perl/#import_extend Perl ]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Classes#Instance_Variables Ruby]&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=49999</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h hs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=49999"/>
		<updated>2011-09-21T16:06:20Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Getters and Setters from a different perspective */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
== What are getters and setters ? ==&lt;br /&gt;
''' &lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide getter and setter methods to access/modify object data. When writing new classes, it's a good idea to pay attention to the issue of access control. Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. Because of this naming convention, accessor methods are more often referred to as getter methods. This is a good programming practice, since the data fields are not directly accessible outside the class. Thus 'Getters' and 'Setters' allow us to effectively protect your data. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and setters as method calls ==&lt;br /&gt;
'''&lt;br /&gt;
For each variable, a get method will return its value and a set method will set the value. Here are the advantages of using getter and setter as method calls: &lt;br /&gt;
* Encapsulate the data from accidental / inadvertent modification. The private member variable is not part of the public interface of your class; only the public getter and setter methods are, and you are free to change their implementations without changing the public interface of your class&lt;br /&gt;
* If we decide that some action should be taken every time you change/access the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. For Instance, we can keep track of how many times a variable is accessed. &lt;br /&gt;
* Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and getters as variable references(properties) ==&lt;br /&gt;
'''&lt;br /&gt;
Properties are a robust way to handle object’s data. Properties support accessing the instance variables the same way as calling an instance method. A property communicates the idea of &amp;quot;I will make a value available to you, or accept a value from you.&amp;quot; It's not an implementation concept, it's an interface concept. Different languages follow specific syntax for adding a property to a class. Following are the advantages properties: &lt;br /&gt;
* the code is much cleaner when accessing a property when compared to Java or C++ which uses 2 separate methods for each instance variable. They are very useful in GUI programming which necessitates using a lot of fields for UI elements&lt;br /&gt;
* With properties we have fine-grained access control. For instance we can define a property as abstract thereby forcing the derived class to define that property. &lt;br /&gt;
* The main advantage of using properties is that if the internal implementation of getting or setting the property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class. This allows the interface of the object to stay the same even if the underlying implementation of getting and setting the property changes. &lt;br /&gt;
&lt;br /&gt;
Realizing the importance of getters and setters, popular IDEs like Eclipse, Visual studio has a built in mechanism to add getter and setter for a field or to create a property (in C#) for a given field.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples Languages that use getters and setters as method calls: ==&lt;br /&gt;
'''&lt;br /&gt;
'''&lt;br /&gt;
===C++===&lt;br /&gt;
'''&lt;br /&gt;
'Getters' and 'Setters' allow you to effectively protect your data. This is a technique used greatly when creating classes in C++. The getters and setters are usually public and the variables are made private. The reason for it is the data members are not accessible outside the class. For each variable, a get method will return its value and a set method will set the value.The reason for not editing the methods directly is twofold. Firstly, if you decide that some action should be taken every time you change the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
  int x_value;&lt;br /&gt;
&lt;br /&gt;
  public:&lt;br /&gt;
  // Getter&lt;br /&gt;
  int getx_value()&lt;br /&gt;
  {&lt;br /&gt;
      return x;&lt;br /&gt;
  }&lt;br /&gt;
  // Setter&lt;br /&gt;
  void setx_value( int x )&lt;br /&gt;
  {&lt;br /&gt;
      x_value = x;&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
void main()&lt;br /&gt;
{ &lt;br /&gt;
    A a;&lt;br /&gt;
    a.setx_value(5);&lt;br /&gt;
    cout&amp;lt;&amp;lt;a.getx_value();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class BookStore&lt;br /&gt;
{ &lt;br /&gt;
  String title;&lt;br /&gt;
  public String getTitle()&lt;br /&gt;
  {&lt;br /&gt;
     return title;&lt;br /&gt;
  }&lt;br /&gt;
  // a setter method might check that the value that is being assigned to the variable is legal&lt;br /&gt;
  public void setTitle( String newTitle ) &lt;br /&gt;
  {&lt;br /&gt;
    if ( newTitle == null )   // Don't allow null strings as titles!&lt;br /&gt;
       title = &amp;quot;(Untitled)&amp;quot;;  // Use an appropriate default value instead.&lt;br /&gt;
    else&lt;br /&gt;
       title = newTitle;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
     BookStore obj;&lt;br /&gt;
     obj. setTitle(&amp;quot;&amp;quot;);&lt;br /&gt;
     System.out.println(obj.getTitle());&lt;br /&gt;
}&lt;br /&gt;
Output:&lt;br /&gt;
(Untitled)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
'''&lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide accessor methods to modify object data. [http://www.netalive.org/tinkering/serious-perl/#import_extend Perl] does not have private variables but we can still use the concept of getter, setter functions methods.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub setName &lt;br /&gt;
{&lt;br /&gt;
   my ( $self, $Name ) = @_;&lt;br /&gt;
   $self-&amp;gt;{_Name} = $Name;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
sub getName &lt;br /&gt;
{&lt;br /&gt;
   my( $self ) = @_;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== ColdFusion === &lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
If we want to override the getter and setter method, you just need to define those methods in your [http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ CFC] and ColdFusion will call our method instead of calling the implicit one.The implicit methods can also do some nice validation if you have given the ‘type’ for properties. For instance, if we define a property as numeric and try to provide a try to set a string as its value It will throw a nice error saying “The value cannot be converted to a numeric”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Component Person&lt;br /&gt;
{&lt;br /&gt;
   property name&lt;br /&gt;
   property age;&lt;br /&gt;
   property city;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;!--- Once an object is created we can directly call the setters and getters for the properties as ---&amp;gt;&lt;br /&gt;
&amp;lt;cfscript&amp;gt;&lt;br /&gt;
   person = new Person();&lt;br /&gt;
   person.setName(&amp;quot;Brad&amp;quot;);&lt;br /&gt;
   person.setAge(46);&lt;br /&gt;
&lt;br /&gt;
   writeOutput(&amp;quot;Name : #person.getName()#&amp;quot;);&lt;br /&gt;
   writeOutput(&amp;quot;Age : #person.getAge()#&amp;quot;); &lt;br /&gt;
&amp;lt;/cfscript&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples from Languages that use getters and setters as instance variable references:  ==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== C#: ===&lt;br /&gt;
'''&lt;br /&gt;
In [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx C#], properties are nothing but natural extension of data fields. The properties are an important features added in language level inside C#.yC# also supports static properties, which belongs to the class rather than to the objects of the class. The properties of a Base class can be inherited to a Derived class and can be overridden by polymorphism. They are very useful in GUI programming. The compiler generates the appropriate getter and setter methods when it parses the C# property syntax.In C#, data encapsulation is possible through either classes or structures. By using various access modifiers like private, public, protected, internal etc it is possible to control the accessibility of the class members.  Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. This is a good programming practice, since the data fields are not directly accessible out side the class. We must use the set/get methods to access the data fields.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;class MyClass&lt;br /&gt;
{&lt;br /&gt;
      private int x;&lt;br /&gt;
      public int X&lt;br /&gt;
      {&lt;br /&gt;
            get&lt;br /&gt;
           {&lt;br /&gt;
             return x;&lt;br /&gt;
           }&lt;br /&gt;
          set&lt;br /&gt;
          {&lt;br /&gt;
             x = value;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
//Invocation&lt;br /&gt;
MyClass mc = new MyClass();&lt;br /&gt;
mc.X = 10;                   // calls set accessor of the property X, and pass 10 as value of the standard field 'value'.&lt;br /&gt;
Console.WriteLine(mc.X);     // displays 10. Calls the get accessor of the property X.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
===Lua===&lt;br /&gt;
'''&lt;br /&gt;
Getter and Setter functions can be implemented in [http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Lua], which is similar to the properties concept in C#. This allows the functions to bind to a property that can be assigned and accessed as a value.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class 'Test'&lt;br /&gt;
  function  Test : getLength()&lt;br /&gt;
   return # self.value&lt;br /&gt;
  end&lt;br /&gt;
  function  Test : setLength(newLength)&lt;br /&gt;
    for  i = self.length, newLength do&lt;br /&gt;
        table.insert(self.value, false )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
test =  Test({1, 2, 3, 4})&lt;br /&gt;
print(test.length)&lt;br /&gt;
self.length = property( Test.getLength, Test.setLength )    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
===Ruby===&lt;br /&gt;
'''&lt;br /&gt;
Ruby simplifies the creation of getters and setters with a little metaprogramming and the methods attr, attr_reader, attr_writer, and attr_accessor, all from the Module class. By supplying the attr method, Ruby provides a way to acces the instances directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
    def initialize(lname, fname)&lt;br /&gt;
        @lname = lname&lt;br /&gt;
        @fname = fname&lt;br /&gt;
    end&lt;br /&gt;
attr_reader :lname // creates a getter method&lt;br /&gt;
    attr_writer :lname    // creates a setter method&lt;br /&gt;
    attr_accessor :fname // creates both getter and setter method&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x = Person.new(&amp;quot;ABC&amp;quot;, &amp;quot;XYZ&amp;quot;)&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
x.fname = &amp;quot;PQR&amp;quot;&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
===Php===&lt;br /&gt;
'''&lt;br /&gt;
An interesting aspect of php worth noting is that we can assign values to undefined variables. Because of the above limitation, [http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set PHP] engine provides two magic methods __get() and __set(). __get() is used when value from an undefined variable is to be read and __set() is used when a value is to be assigned to a undefined variable of a class.In the above example when email@domain.com is assigned to the undefined variable $email, the magic method __set() is called. To this __set() method the name of the variable is passed into $dt variable of __set() method and the value i.e. email@domain.com is passed to $vl variable of the __set() method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
class Customer&lt;br /&gt;
{&lt;br /&gt;
   public $name;&lt;br /&gt;
   private $data = array();&lt;br /&gt;
   public function __set($dt, $vl) &lt;br /&gt;
   {&lt;br /&gt;
      $this-&amp;gt;data[$dt] = $vl;&lt;br /&gt;
   }&lt;br /&gt;
   public function __get($dt) &lt;br /&gt;
   {&lt;br /&gt;
      return $this-&amp;gt;data[$dt];&lt;br /&gt;
   }&lt;br /&gt;
} &lt;br /&gt;
$c = new Customer();&lt;br /&gt;
$c-&amp;gt;name = “Sunil”; // $name is set because its public&lt;br /&gt;
$c-&amp;gt;email = “email@domain.com”; //assigning email@domain.com to the $email variable.&lt;br /&gt;
echo $c-&amp;gt;email;&lt;br /&gt;
?&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Objective C===&lt;br /&gt;
'''&lt;br /&gt;
In [http://www.touch-code-magazine.com/objective-c-properties/ Objective C] we can define a property using @property directive. @synthesize will create automatically for you a setter and a getter methods for the property which becomes accessible during the run time.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// public header file&lt;br /&gt;
@interface MyObject : NSObject&lt;br /&gt;
{&lt;br /&gt;
  NSString *make; &lt;br /&gt;
  NSString* model;&lt;br /&gt;
  NSNumber* vin;&lt;br /&gt;
}&lt;br /&gt;
@property (readonly, copy) NSString *language;&lt;br /&gt;
@property(readwrite, retain) NSString* make;&lt;br /&gt;
@property(readwrite, retain) NSString* model;&lt;br /&gt;
@property(readwrite, retain) NSNumber* vin;&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
#import &amp;quot;SimpleCar.h&amp;quot;&lt;br /&gt;
@implementation SimpleCar&lt;br /&gt;
@synthesize make, model, vin;&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Python ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DoubleIt(object):&lt;br /&gt;
   def _get_value(self):&lt;br /&gt;
       return self._value * 2&lt;br /&gt;
   def _set_value(self, value):&lt;br /&gt;
       self._value = value&lt;br /&gt;
   value = property(_get_value, _set_value)&lt;br /&gt;
&lt;br /&gt;
# Invocation &lt;br /&gt;
x = DoubleIt()&lt;br /&gt;
 &lt;br /&gt;
x.value = 10&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = 'foo'&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = [1,2,3]&lt;br /&gt;
print x.value&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above [http://stefaanlippens.net/python_property_trick python] code, the output is doubled since the getter multiplies the value by 2&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Javascript ===&lt;br /&gt;
'''&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 JavaScript] supports accessing getters and setters as variable as properties. Javascript originally used __defineGetter__ and __defineSetter__ syntax to define properties which is depricated as the language evolved. Object.defineProperty is currently used for creating a property. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function addDataProperty()&lt;br /&gt;
{&lt;br /&gt;
   var newLine = &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;;&lt;br /&gt;
   var obj = {};&lt;br /&gt;
  &lt;br /&gt;
   // Add a data property to the object.&lt;br /&gt;
   Object.defineProperty(obj, &amp;quot;newDataProperty&amp;quot;, &lt;br /&gt;
   {&lt;br /&gt;
       value: 101,&lt;br /&gt;
       writable: true,&lt;br /&gt;
       enumerable: true,&lt;br /&gt;
       configurable: true&lt;br /&gt;
   });&lt;br /&gt;
&lt;br /&gt;
   // Set the property value.&lt;br /&gt;
   obj.newDataProperty = 102;&lt;br /&gt;
   document.write(&amp;quot;Property value: &amp;quot; + obj.newDataProperty + newLine);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Scala ===&lt;br /&gt;
'''&lt;br /&gt;
[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Scala] has some unconventional ideas that provide a solid, well thought out, and an abbreviated syntax to access object properties. This getter code simply defines a method called “age” and returns the “_age” variable. Scala doesn’t require the return keyword. The setter method name is “age_=”. The underscore is a special character in Scala and in this case, allows for a space in the method name which essentially makes the name “age =”. The parentheses and contents dictate the value and type that needs to be passed in. The “:Unit” code is equivalent to returning void. The remaining code is setting the “_age” variable to “value”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person() {&lt;br /&gt;
// Private age variable, renamed to _age&lt;br /&gt;
private var _age = 0&lt;br /&gt;
var name = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Getter&lt;br /&gt;
def age = _age&lt;br /&gt;
&lt;br /&gt;
// Setter&lt;br /&gt;
def age_= (value:Int):Unit = _age = value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// We can invoke the setter as follows : &lt;br /&gt;
 can invoke the setter using the following: &lt;br /&gt;
person.age = 99&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
===Smalltalk===&lt;br /&gt;
'''&lt;br /&gt;
In [http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk] the names of getter methods are usually the same as the name of the instance variable. A colon is added to the end of setter method name e.g. colour:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     name                           &amp;quot;gets the value of name&amp;quot;&lt;br /&gt;
     name:aName              &amp;quot;sets name to the value of aName&amp;quot;&lt;br /&gt;
&lt;br /&gt;
     address                        &amp;quot;gets the value of address&amp;quot;&lt;br /&gt;
     address:anAddress     &amp;quot;sets anAddress to the value of anAddress&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Actionscript ===&lt;br /&gt;
'''&lt;br /&gt;
In [http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000171.html Flex] it is not usually necessary to create the wrapper getter and setting functions on an object because ActionScript supports properties. This means that you can usually just create public properties like:&lt;br /&gt;
public var firstName:String;&lt;br /&gt;
If the internal implementation of getting or setting the firstName property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class:&lt;br /&gt;
private var _firstName:String;&lt;br /&gt;
&lt;br /&gt;
Getting or setting the property would call the getter and setter functions instead of accessing the property directly&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public var firstName:String;&lt;br /&gt;
private var _firstName:String;&lt;br /&gt;
&lt;br /&gt;
public function get firstName():String {&lt;br /&gt;
   return _firstName;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public function set fullName(_firstName:String):void {&lt;br /&gt;
   this._firstName = _firstName;&lt;br /&gt;
}&lt;br /&gt;
// getters&lt;br /&gt;
var1 = obj.firstName;&lt;br /&gt;
var2 = obj['firstName'];&lt;br /&gt;
// setters&lt;br /&gt;
obj.firstName = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
obj['fullName'] = &amp;quot;Yes&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
==Getters and Setters from a different perspective==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
A fundamental precept of OO systems is that an object should not expose any of its implementation details. This way, you can change the implementation without changing the code that uses the object. It follows then that in OO systems you should avoid getter and setter functions since they mostly provide access to implementation details. For instance if you need change the return type of a getter method from int to long to accommodate the big numbers you need to change all the invocations of that getter method. This negates the concept of [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html information hiding]. The same issue arises when you need to change the accessed field’s type. You also have to change the getter’s return type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Solution:	 &lt;br /&gt;
Maintainability is inversely proportionate to the amount of data that moves between objects. Thus, its best to minimize data movement as much as possible. The idea is to focus on what you will do rather than how you will do it. Don't ask for the information you need to do the work; ask the object that has the information to do the work for you. Lets use an example to explain this better. While building user interfaces, we dont want UI builder class call methods like &amp;quot;GetAttributes()&amp;quot;. Classes can have methods like &amp;quot;DrawYourself()&amp;quot; and getters that returns an object that implements an interface. In our UI Construction example, GetIdentity() getter method can return an object that implements Identity Interface and this Interface includes the method &amp;quot;DrawYourself()&amp;quot;. This GetIdentity() call does not return a simple field but a complex object with a defined behavior and the internals of this object is kept hidden &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== When to Use Getters and Setters ? ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
1. When a getter returns an object that implements an Interface since the interface isolates the class that uses this interface from the implementing class. &lt;br /&gt;
2. Generic interfaces like Java Database Connectivity (JDBC) are unaware of how it will be used and in such cases getters are used to provide flexibility&lt;br /&gt;
&lt;br /&gt;
Programmers use getters and setters because of procedural language mindset. A useful design strategy to this end is to center our design in terms of use cases without getters and setters by thinking on the lines of communication or interaction between the objects with well defined behavior.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
'''&lt;br /&gt;
Getters and setters provide a convenient method to access the instance variables. A lot of new languages have come up with the support for accessing getters and setters as instance variable reference which improves the readability of the code. While such convenient mechanisms are available, it is important to use the getters and setters wisely with the goal of minimizing the data movement between the objects. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== References ==&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx Understanding properties in C#]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html why getters and setters are evil ]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set php5 OOPS tutorial]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://stefaanlippens.net/python_property_trick python-hiding attribute getters and setters behind standard attribute access]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 Object.defineProperty Function (JavaScript)]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Getters and Setters in Scala]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ ColdFusion 9 : Implicit/Generated CFC Methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000171.html Using getters and setters]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.touch-code-magazine.com/objective-c-properties/ Objective C properties]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Properties in Lua]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.netalive.org/tinkering/serious-perl/#import_extend Perl ]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Classes#Instance_Variables Ruby]&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=49618</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h hs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=49618"/>
		<updated>2011-09-19T22:04:09Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
== What are getters and setters ? ==&lt;br /&gt;
''' &lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide getter and setter methods to access/modify object data. When writing new classes, it's a good idea to pay attention to the issue of access control. Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. Because of this naming convention, accessor methods are more often referred to as getter methods. This is a good programming practice, since the data fields are not directly accessible outside the class. Thus 'Getters' and 'Setters' allow us to effectively protect your data. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and setters as method calls ==&lt;br /&gt;
'''&lt;br /&gt;
For each variable, a get method will return its value and a set method will set the value. Here are the advantages of using getter and setter as method calls: &lt;br /&gt;
* Encapsulate the data from accidental / inadvertent modification. The private member variable is not part of the public interface of your class; only the public getter and setter methods are, and you are free to change their implementations without changing the public interface of your class&lt;br /&gt;
* If we decide that some action should be taken every time you change/access the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. For Instance, we can keep track of how many times a variable is accessed. &lt;br /&gt;
* Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and getters as variable references(properties) ==&lt;br /&gt;
'''&lt;br /&gt;
Properties are a robust way to handle object’s data. Properties support accessing the instance variables the same way as calling an instance method. A property communicates the idea of &amp;quot;I will make a value available to you, or accept a value from you.&amp;quot; It's not an implementation concept, it's an interface concept. Different languages follow specific syntax for adding a property to a class. Following are the advantages properties: &lt;br /&gt;
* the code is much cleaner when accessing a property when compared to Java or C++ which uses 2 separate methods for each instance variable. They are very useful in GUI programming which necessitates using a lot of fields for UI elements&lt;br /&gt;
* With properties we have fine-grained access control. For instance we can define a property as abstract thereby forcing the derived class to define that property. &lt;br /&gt;
* The main advantage of using properties is that if the internal implementation of getting or setting the property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class. This allows the interface of the object to stay the same even if the underlying implementation of getting and setting the property changes. &lt;br /&gt;
&lt;br /&gt;
Realizing the importance of getters and setters, popular IDEs like Eclipse, Visual studio has a built in mechanism to add getter and setter for a field or to create a property (in C#) for a given field.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples Languages that use getters and setters as method calls: ==&lt;br /&gt;
'''&lt;br /&gt;
'''&lt;br /&gt;
===C++===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
  int x_value;&lt;br /&gt;
&lt;br /&gt;
  public:&lt;br /&gt;
  // Getter&lt;br /&gt;
  int getx_value()&lt;br /&gt;
  {&lt;br /&gt;
      return x;&lt;br /&gt;
  }&lt;br /&gt;
  // Setter&lt;br /&gt;
  void setx_value( int x )&lt;br /&gt;
  {&lt;br /&gt;
      x_value = x;&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
void main()&lt;br /&gt;
{ &lt;br /&gt;
    A a;&lt;br /&gt;
    a.setx_value(5);&lt;br /&gt;
    cout&amp;lt;&amp;lt;a.getx_value();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class BookStore&lt;br /&gt;
{ &lt;br /&gt;
  String title;&lt;br /&gt;
  public String getTitle()&lt;br /&gt;
  {&lt;br /&gt;
     return title;&lt;br /&gt;
  }&lt;br /&gt;
  // a setter method might check that the value that is being assigned to the variable is legal&lt;br /&gt;
  public void setTitle( String newTitle ) &lt;br /&gt;
  {&lt;br /&gt;
    if ( newTitle == null )   // Don't allow null strings as titles!&lt;br /&gt;
       title = &amp;quot;(Untitled)&amp;quot;;  // Use an appropriate default value instead.&lt;br /&gt;
    else&lt;br /&gt;
       title = newTitle;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
     BookStore obj;&lt;br /&gt;
     obj. setTitle(&amp;quot;&amp;quot;);&lt;br /&gt;
     System.out.println(obj.getTitle());&lt;br /&gt;
}&lt;br /&gt;
Output:&lt;br /&gt;
(Untitled)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
'''&lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide accessor methods to modify object data. [http://www.netalive.org/tinkering/serious-perl/#import_extend Perl] does not have private variables but we can still use the concept of getter, setter functions methods.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub setName &lt;br /&gt;
{&lt;br /&gt;
   my ( $self, $Name ) = @_;&lt;br /&gt;
   $self-&amp;gt;{_Name} = $Name;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
sub getName &lt;br /&gt;
{&lt;br /&gt;
   my( $self ) = @_;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== ColdFusion === &lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Component Person&lt;br /&gt;
{&lt;br /&gt;
   property name&lt;br /&gt;
   property age;&lt;br /&gt;
   property city;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;!--- Once an object is created we can directly call the setters and getters for the properties as ---&amp;gt;&lt;br /&gt;
&amp;lt;cfscript&amp;gt;&lt;br /&gt;
   person = new Person();&lt;br /&gt;
   person.setName(&amp;quot;Brad&amp;quot;);&lt;br /&gt;
   person.setAge(46);&lt;br /&gt;
&lt;br /&gt;
   writeOutput(&amp;quot;Name : #person.getName()#&amp;quot;);&lt;br /&gt;
   writeOutput(&amp;quot;Age : #person.getAge()#&amp;quot;); &lt;br /&gt;
&amp;lt;/cfscript&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want to override the getter and setter method, you just need to define those methods in your CFC and ColdFusion will call our method instead of calling the implicit one.The implicit methods can also do some nice validation if you have given the ‘type’ for properties. For instance, if we define a property as numeric and try to provide a try to set a string as its value It will throw a nice error saying “The value cannot be converted to a numeric”.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples from Languages that use getters and setters as instance variable references:  ==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== C#: ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;class MyClass&lt;br /&gt;
{&lt;br /&gt;
      private int x;&lt;br /&gt;
      public int X&lt;br /&gt;
      {&lt;br /&gt;
            get&lt;br /&gt;
           {&lt;br /&gt;
             return x;&lt;br /&gt;
           }&lt;br /&gt;
          set&lt;br /&gt;
          {&lt;br /&gt;
             x = value;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
//Invocation&lt;br /&gt;
MyClass mc = new MyClass();&lt;br /&gt;
mc.X = 10;                   // calls set accessor of the property X, and pass 10 as value of the standard field 'value'.&lt;br /&gt;
Console.WriteLine(mc.X);     // displays 10. Calls the get accessor of the property X.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
C# also supports static properties, which belongs to the class rather than to the objects of the class. The properties of a Base class can be inherited to a Derived class and can be overridden polymorphicaly. &lt;br /&gt;
'''&lt;br /&gt;
===Lua===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class 'Test'&lt;br /&gt;
  function  Test : getLength()&lt;br /&gt;
   return # self.value&lt;br /&gt;
  end&lt;br /&gt;
  function  Test : setLength(newLength)&lt;br /&gt;
    for  i = self.length, newLength do&lt;br /&gt;
        table.insert(self.value, false )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
test =  Test({1, 2, 3, 4})&lt;br /&gt;
print(test.length)&lt;br /&gt;
self.length = property( Test.getLength, Test.setLength )    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getter and Setter functions can be implemented in Lua, which is similar to the properties concept in C#. This allows the functions to bind to a property that can be assigned and accessed as a value.&lt;br /&gt;
'''&lt;br /&gt;
===Ruby===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
    def initialize(lname, fname)&lt;br /&gt;
        @lname = lname&lt;br /&gt;
        @fname = fname&lt;br /&gt;
    end&lt;br /&gt;
attr_reader :lname // creates a getter method&lt;br /&gt;
    attr_writer :lname    // creates a setter method&lt;br /&gt;
    attr_accessor :fname // creates both getter and setter method&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x = Person.new(&amp;quot;ABC&amp;quot;, &amp;quot;XYZ&amp;quot;)&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
x.fname = &amp;quot;PQR&amp;quot;&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ruby simplifies the creation of getters and setters with a little metaprogramming and the methods attr, attr_reader, attr_writer, and attr_accessor, all from the Module class. By supplying the attr method, Ruby provides a way to acces the instances directly.&lt;br /&gt;
'''&lt;br /&gt;
===Php===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
class Customer&lt;br /&gt;
{&lt;br /&gt;
   public $name;&lt;br /&gt;
   private $data = array();&lt;br /&gt;
   public function __set($dt, $vl) &lt;br /&gt;
   {&lt;br /&gt;
      $this-&amp;gt;data[$dt] = $vl;&lt;br /&gt;
   }&lt;br /&gt;
   public function __get($dt) &lt;br /&gt;
   {&lt;br /&gt;
      return $this-&amp;gt;data[$dt];&lt;br /&gt;
   }&lt;br /&gt;
} &lt;br /&gt;
$c = new Customer();&lt;br /&gt;
$c-&amp;gt;name = “Sunil”; // $name is set because its public&lt;br /&gt;
$c-&amp;gt;email = “email@domain.com”; //assigning email@domain.com to the $email variable.&lt;br /&gt;
echo $c-&amp;gt;email;&lt;br /&gt;
?&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
An interesting aspect of php worth noting is that we can assign values to undefined variables. Because of the above limitation, PHP engine provides two magic methods __get() and __set(). __get() is used when value from an undefined variable is to be read and __set() is used when a value is to be assigned to a undefined variable of a class.In the above example when email@domain.com is assigned to the undefined variable $email, the magic method __set() is called. To this __set() method the name of the variable is passed into $dt variable of __set() method and the value i.e. email@domain.com is passed to $vl variable of the __set() method.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Objective C===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// public header file&lt;br /&gt;
@interface MyObject : NSObject&lt;br /&gt;
{&lt;br /&gt;
  NSString *make; &lt;br /&gt;
  NSString* model;&lt;br /&gt;
  NSNumber* vin;&lt;br /&gt;
}&lt;br /&gt;
@property (readonly, copy) NSString *language;&lt;br /&gt;
@property(readwrite, retain) NSString* make;&lt;br /&gt;
@property(readwrite, retain) NSString* model;&lt;br /&gt;
@property(readwrite, retain) NSNumber* vin;&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
#import &amp;quot;SimpleCar.h&amp;quot;&lt;br /&gt;
@implementation SimpleCar&lt;br /&gt;
@synthesize make, model, vin;&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Objective C we can define a property using @property directive. @synthesize will create automatically for you a setter and a getter methods for the property which becomes accessible during the run time.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Python ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DoubleIt(object):&lt;br /&gt;
   def _get_value(self):&lt;br /&gt;
       return self._value * 2&lt;br /&gt;
   def _set_value(self, value):&lt;br /&gt;
       self._value = value&lt;br /&gt;
   value = property(_get_value, _set_value)&lt;br /&gt;
&lt;br /&gt;
# Invocation &lt;br /&gt;
x = DoubleIt()&lt;br /&gt;
 &lt;br /&gt;
x.value = 10&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = 'foo'&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = [1,2,3]&lt;br /&gt;
print x.value&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above [http://stefaanlippens.net/python_property_trick python] code, the output is doubled since the getter multiplies the value by 2&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Javascript ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function addDataProperty()&lt;br /&gt;
{&lt;br /&gt;
   var newLine = &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;;&lt;br /&gt;
   var obj = {};&lt;br /&gt;
  &lt;br /&gt;
   // Add a data property to the object.&lt;br /&gt;
   Object.defineProperty(obj, &amp;quot;newDataProperty&amp;quot;, &lt;br /&gt;
   {&lt;br /&gt;
       value: 101,&lt;br /&gt;
       writable: true,&lt;br /&gt;
       enumerable: true,&lt;br /&gt;
       configurable: true&lt;br /&gt;
   });&lt;br /&gt;
&lt;br /&gt;
   // Set the property value.&lt;br /&gt;
   obj.newDataProperty = 102;&lt;br /&gt;
   document.write(&amp;quot;Property value: &amp;quot; + obj.newDataProperty + newLine);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Javascript supports accessing getters and setters as variable as properties. Javascript originally used __defineGetter__ and __defineSetter__ syntax to define properties which is depricated as the language evolved. Object.defineProperty is currently used for creating a property. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Scala ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person() {&lt;br /&gt;
// Private age variable, renamed to _age&lt;br /&gt;
private var _age = 0&lt;br /&gt;
var name = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Getter&lt;br /&gt;
def age = _age&lt;br /&gt;
&lt;br /&gt;
// Setter&lt;br /&gt;
def age_= (value:Int):Unit = _age = value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// We can invoke the setter as follows : &lt;br /&gt;
 can invoke the setter using the following: &lt;br /&gt;
person.age = 99&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Scala has some unconventional ideas that provide a solid, well thought out, and an abbreviated syntax to access object properties. This getter code simply defines a method called “age” and returns the “_age” variable. Scala doesn’t require the return keyword. The setter method name is “age_=”. The underscore is a special character in Scala and in this case, allows for a space in the method name which essentially makes the name “age =”. The parentheses and contents dictate the value and type that needs to be passed in. The “:Unit” code is equivalent to returning void. The remaining code is setting the “_age” variable to “value”.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Smalltalk===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     name                           &amp;quot;gets the value of name&amp;quot;&lt;br /&gt;
     name:aName              &amp;quot;sets name to the value of aName&amp;quot;&lt;br /&gt;
&lt;br /&gt;
     address                        &amp;quot;gets the value of address&amp;quot;&lt;br /&gt;
     address:anAddress     &amp;quot;sets anAddress to the value of anAddress&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In [http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk] the names of getter methods are usually the same as the name of the instance variable. A colon is added to the end of setter method name e.g. colour:&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Actionscript ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public var fullName:String;&lt;br /&gt;
private var _fullName:String;&lt;br /&gt;
&lt;br /&gt;
public function get fullName():String {&lt;br /&gt;
   return _fullName;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public function set fullName(_fullName:String):void {&lt;br /&gt;
   this._fullName = _fullName;&lt;br /&gt;
}&lt;br /&gt;
// getters&lt;br /&gt;
var1 = obj.fullName;&lt;br /&gt;
var2 = obj['fullName'];&lt;br /&gt;
// setters&lt;br /&gt;
obj.fullName = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
obj['fullName'] = &amp;quot;Yes&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getting or setting the property would call the getter and setter functions instead of accessing the property directly&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
==Getters and Setters from a different perspective==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
A fundamental precept of OO systems is that an object should not expose any of its implementation details. This way, you can change the implementation without changing the code that uses the object. It follows then that in OO systems you should avoid getter and setter functions since they mostly provide access to implementation details. For instance if you need change the return type of a gettr method from int to long to accommodate the big numbers you need to change all the invocations of that getter method. This negates the concept of [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html information hiding]. The same issue arises when you need to change the accessed field’s type. You also have to change the getter’s return type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Solution:	 &lt;br /&gt;
Maintainability is inversely proportionate to the amount of data that moves between objects. Thus, its best to minimize data movement as much as possible. The idea is to focus on what you will do rather than how you will do it. Don't ask for the information you need to do the work; ask the object that has the information to do the work for you. Lets use an example to explain this better. While building user interfaces, instead of having UI builder class call methods like &amp;quot;GetAttributes()&amp;quot;. Classes can have methods like &amp;quot;DrawYourself()&amp;quot;. Classes can have getters that returns an object that implements an interface. In our UI Construction example, GetIdentity() can return a method that implements Identity Interface and this Interface includes the method &amp;quot;DrawYourself()&amp;quot;. In this example, GetIdentity() does not return a simple field but a complex object with a defined behavior and the internals of this object is kept hidden &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== When to Use Getters and Setters ? ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
1. When a getter returns an object that implements an Interface since the interface isolates the class that uses this interface from the implementing class. &lt;br /&gt;
2. Generic interfaces like Java Database Connectivity (JDBC) are unaware of how it will be used and in such cases getters are used to provide flexibility&lt;br /&gt;
&lt;br /&gt;
Programmers use getters and setters because of procedural language mindset. A useful design strategy to this end is to center our design in terms of use cases without getters and setters by thinking on the lines of communication or interaction between the objects with well defined behavior.  &lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
'''&lt;br /&gt;
Getters and setters provide a convenient method to access the instance variables. A lot of new languages have come up with the support for accessing getters and setters as instance variable reference which improves the readability of the code. While such convenient mechanisms are available, it is important to use the getters and setters wisely with the goal of minimizing the data movement between the objects. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== References ==&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx Understanding properties in C#]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html why getters and setters are evil ]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set php5 OOPS tutorial]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://stefaanlippens.net/python_property_trick python-hiding attribute getters and setters behind standard attribute access]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 Object.defineProperty Function (JavaScript)]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Getters and Setters in Scala]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ ColdFusion 9 : Implicit/Generated CFC Methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.jamesward.com/2010/05/07/flex-and-java-differences-getters-setters/  Flex and Java Differences: Getters &amp;amp; Setters]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.touch-code-magazine.com/objective-c-properties/ Objective C properties]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Properties in Lua]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.netalive.org/tinkering/serious-perl/#import_extend Perl ]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Classes#Instance_Variables Ruby]&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=49110</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h hs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=49110"/>
		<updated>2011-09-17T23:03:03Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
== What are getters and setters ? ==&lt;br /&gt;
''' &lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide getter and setter methods to access/modify object data. When writing new classes, it's a good idea to pay attention to the issue of access control. Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. Because of this naming convention, accessor methods are more often referred to as getter methods. This is a good programming practice, since the data fields are not directly accessible outside the class. Thus 'Getters' and 'Setters' allow us to effectively protect your data. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and setters as method calls ==&lt;br /&gt;
'''&lt;br /&gt;
For each variable, a get method will return its value and a set method will set the value. Here are the advantages of using getter and setter as method calls: &lt;br /&gt;
* Encapsulate the data from accidental / inadvertent modification. The private member variable is not part of the public interface of your class; only the public getter and setter methods are, and you are free to change their implementations without changing the public interface of your class&lt;br /&gt;
* If we decide that some action should be taken every time you change/access the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. For Instance, we can keep track of how many times a variable is accessed. &lt;br /&gt;
* Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and getters as variable references(properties) ==&lt;br /&gt;
'''&lt;br /&gt;
Properties are a robust way to handle object’s data. Properties support accessing the instance variables the same way as calling an instance method. A property communicates the idea of &amp;quot;I will make a value available to you, or accept a value from you.&amp;quot; It's not an implementation concept, it's an interface concept. Different languages follow specific syntax for adding a property to a class. Following are the advantages properties: &lt;br /&gt;
* the code is much cleaner when accessing a property when compared to Java or C++ which uses 2 separate methods for each instance variable. They are very useful in GUI programming which necessitates using a lot of fields for UI elements&lt;br /&gt;
* With properties we have fine-grained access control. For instance we can define a property as abstract thereby forcing the derived class to define that property. &lt;br /&gt;
* The main advantage of using properties is that if the internal implementation of getting or setting the property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class. This allows the interface of the object to stay the same even if the underlying implementation of getting and setting the property changes. &lt;br /&gt;
&lt;br /&gt;
Realizing the importance of getters and setters, popular IDEs like Eclipse, Visual studio has a built in mechanism to add getter and setter for a field or to create a property (in C#) for a given field.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples Languages that use getters and setters as method calls: ==&lt;br /&gt;
'''&lt;br /&gt;
'''&lt;br /&gt;
===C++===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
  int x_value;&lt;br /&gt;
&lt;br /&gt;
  public:&lt;br /&gt;
  // Getter&lt;br /&gt;
  int getx_value()&lt;br /&gt;
  {&lt;br /&gt;
      return x;&lt;br /&gt;
  }&lt;br /&gt;
  // Setter&lt;br /&gt;
  void setx_value( int x )&lt;br /&gt;
  {&lt;br /&gt;
      x_value = x;&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
void main()&lt;br /&gt;
{ &lt;br /&gt;
    A a;&lt;br /&gt;
    a.setx_value(5);&lt;br /&gt;
    cout&amp;lt;&amp;lt;a.getx_value();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class BookStore&lt;br /&gt;
{ &lt;br /&gt;
  String title;&lt;br /&gt;
  public String getTitle()&lt;br /&gt;
  {&lt;br /&gt;
     return title;&lt;br /&gt;
  }&lt;br /&gt;
  // a setter method might check that the value that is being assigned to the variable is legal&lt;br /&gt;
  public void setTitle( String newTitle ) &lt;br /&gt;
  {&lt;br /&gt;
    if ( newTitle == null )   // Don't allow null strings as titles!&lt;br /&gt;
       title = &amp;quot;(Untitled)&amp;quot;;  // Use an appropriate default value instead.&lt;br /&gt;
    else&lt;br /&gt;
       title = newTitle;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
     BookStore obj;&lt;br /&gt;
     obj. setTitle(&amp;quot;&amp;quot;);&lt;br /&gt;
     System.out.println(obj.getTitle());&lt;br /&gt;
}&lt;br /&gt;
Output:&lt;br /&gt;
(Untitled)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
'''&lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide accessor methods to modify object data. [http://www.netalive.org/tinkering/serious-perl/#import_extend Perl] does not have private variables but we can still use the concept of getter, setter functions methods.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub setName &lt;br /&gt;
{&lt;br /&gt;
   my ( $self, $Name ) = @_;&lt;br /&gt;
   $self-&amp;gt;{_Name} = $Name;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
sub getName &lt;br /&gt;
{&lt;br /&gt;
   my( $self ) = @_;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== ColdFusion === &lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Component Person&lt;br /&gt;
{&lt;br /&gt;
   property name&lt;br /&gt;
   property age;&lt;br /&gt;
   property city;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;!--- Once an object is created we can directly call the setters and getters for the properties as ---&amp;gt;&lt;br /&gt;
&amp;lt;cfscript&amp;gt;&lt;br /&gt;
   person = new Person();&lt;br /&gt;
   person.setName(&amp;quot;Brad&amp;quot;);&lt;br /&gt;
   person.setAge(46);&lt;br /&gt;
&lt;br /&gt;
   writeOutput(&amp;quot;Name : #person.getName()#&amp;quot;);&lt;br /&gt;
   writeOutput(&amp;quot;Age : #person.getAge()#&amp;quot;); &lt;br /&gt;
&amp;lt;/cfscript&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want to override the getter and setter method, you just need to define those methods in your CFC and ColdFusion will call our method instead of calling the implicit one.The implicit methods can also do some nice validation if you have given the ‘type’ for properties. For instance, if we define a property as numeric and try to provide a try to set a string as its value It will throw a nice error saying “The value cannot be converted to a numeric”.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples from Languages that use getters and setters as instance variable references:  ==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== C#: ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;class MyClass&lt;br /&gt;
{&lt;br /&gt;
      private int x;&lt;br /&gt;
      public int X&lt;br /&gt;
      {&lt;br /&gt;
            get&lt;br /&gt;
           {&lt;br /&gt;
             return x;&lt;br /&gt;
           }&lt;br /&gt;
          set&lt;br /&gt;
          {&lt;br /&gt;
             x = value;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
//Invocation&lt;br /&gt;
MyClass mc = new MyClass();&lt;br /&gt;
mc.X = 10;                   // calls set accessor of the property X, and pass 10 as value of the standard field 'value'.&lt;br /&gt;
Console.WriteLine(mc.X);     // displays 10. Calls the get accessor of the property X.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
C# also supports static properties, which belongs to the class rather than to the objects of the class. The properties of a Base class can be inherited to a Derived class and can be overridden polymorphicaly. &lt;br /&gt;
'''&lt;br /&gt;
===Lua===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class 'Test'&lt;br /&gt;
  function  Test : getLength()&lt;br /&gt;
   return # self.value&lt;br /&gt;
  end&lt;br /&gt;
  function  Test : setLength(newLength)&lt;br /&gt;
    for  i = self.length, newLength do&lt;br /&gt;
        table.insert(self.value, false )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
test =  Test({1, 2, 3, 4})&lt;br /&gt;
print(test.length)&lt;br /&gt;
self.length = property( Test.getLength, Test.setLength )    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getter and Setter functions can be implemented in Lua, which is similar to the properties concept in C#. This allows the functions to bind to a property that can be assigned and accessed as a value.&lt;br /&gt;
'''&lt;br /&gt;
===Ruby===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
    def initialize(lname, fname)&lt;br /&gt;
        @lname = lname&lt;br /&gt;
        @fname = fname&lt;br /&gt;
    end&lt;br /&gt;
attr_reader :lname // creates a getter method&lt;br /&gt;
    attr_writer :lname    // creates a setter method&lt;br /&gt;
    attr_accessor :fname // creates both getter and setter method&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x = Person.new(&amp;quot;ABC&amp;quot;, &amp;quot;XYZ&amp;quot;)&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
x.fname = &amp;quot;PQR&amp;quot;&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ruby simplifies the creation of getters and setters with a little metaprogramming and the methods attr, attr_reader, attr_writer, and attr_accessor, all from the Module class. By supplying the attr method, Ruby provides a way to acces the instances directly.&lt;br /&gt;
'''&lt;br /&gt;
===Php===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
class Customer&lt;br /&gt;
{&lt;br /&gt;
   public $name;&lt;br /&gt;
   private $data = array();&lt;br /&gt;
   public function __set($dt, $vl) &lt;br /&gt;
   {&lt;br /&gt;
      $this-&amp;gt;data[$dt] = $vl;&lt;br /&gt;
   }&lt;br /&gt;
   public function __get($dt) &lt;br /&gt;
   {&lt;br /&gt;
      return $this-&amp;gt;data[$dt];&lt;br /&gt;
   }&lt;br /&gt;
} &lt;br /&gt;
$c = new Customer();&lt;br /&gt;
$c-&amp;gt;name = “Sunil”; // $name is set because its public&lt;br /&gt;
$c-&amp;gt;email = “email@domain.com”; //assigning email@domain.com to the $email variable.&lt;br /&gt;
echo $c-&amp;gt;email;&lt;br /&gt;
?&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
An interesting aspect of php worth noting is that we can assign values to undefined variables. Because of the above limitation, PHP engine provides two magic methods __get() and __set(). __get() is used when value from an undefined variable is to be read and __set() is used when a value is to be assigned to a undefined variable of a class.In the above example when email@domain.com is assigned to the undefined variable $email, the magic method __set() is called. To this __set() method the name of the variable is passed into $dt variable of __set() method and the value i.e. email@domain.com is passed to $vl variable of the __set() method.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Objective C===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// public header file&lt;br /&gt;
@interface MyObject : NSObject&lt;br /&gt;
{&lt;br /&gt;
  NSString *make; &lt;br /&gt;
  NSString* model;&lt;br /&gt;
  NSNumber* vin;&lt;br /&gt;
}&lt;br /&gt;
@property (readonly, copy) NSString *language;&lt;br /&gt;
@property(readwrite, retain) NSString* make;&lt;br /&gt;
@property(readwrite, retain) NSString* model;&lt;br /&gt;
@property(readwrite, retain) NSNumber* vin;&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
#import &amp;quot;SimpleCar.h&amp;quot;&lt;br /&gt;
@implementation SimpleCar&lt;br /&gt;
@synthesize make, model, vin;&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Objective C we can define a property using @property directive. @synthesize will create automatically for you a setter and a getter methods for the property which becomes accessible during the run time.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Python ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DoubleIt(object):&lt;br /&gt;
   def _get_value(self):&lt;br /&gt;
       return self._value * 2&lt;br /&gt;
   def _set_value(self, value):&lt;br /&gt;
       self._value = value&lt;br /&gt;
   value = property(_get_value, _set_value)&lt;br /&gt;
&lt;br /&gt;
# Invocation &lt;br /&gt;
x = DoubleIt()&lt;br /&gt;
 &lt;br /&gt;
x.value = 10&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = 'foo'&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = [1,2,3]&lt;br /&gt;
print x.value&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above [http://stefaanlippens.net/python_property_trick python] code, the output is doubled since the getter multiplies the value by 2&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Javascript ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function addDataProperty()&lt;br /&gt;
{&lt;br /&gt;
   var newLine = &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;;&lt;br /&gt;
   var obj = {};&lt;br /&gt;
  &lt;br /&gt;
   // Add a data property to the object.&lt;br /&gt;
   Object.defineProperty(obj, &amp;quot;newDataProperty&amp;quot;, &lt;br /&gt;
   {&lt;br /&gt;
       value: 101,&lt;br /&gt;
       writable: true,&lt;br /&gt;
       enumerable: true,&lt;br /&gt;
       configurable: true&lt;br /&gt;
   });&lt;br /&gt;
&lt;br /&gt;
   // Set the property value.&lt;br /&gt;
   obj.newDataProperty = 102;&lt;br /&gt;
   document.write(&amp;quot;Property value: &amp;quot; + obj.newDataProperty + newLine);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Javascript supports accessing getters and setters as variable as properties. Javascript originally used __defineGetter__ and __defineSetter__ syntax to define properties which is depricated as the language evolved. Object.defineProperty is currently used for creating a property. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Scala ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person() {&lt;br /&gt;
// Private age variable, renamed to _age&lt;br /&gt;
private var _age = 0&lt;br /&gt;
var name = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Getter&lt;br /&gt;
def age = _age&lt;br /&gt;
&lt;br /&gt;
// Setter&lt;br /&gt;
def age_= (value:Int):Unit = _age = value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// We can invoke the setter as follows : &lt;br /&gt;
 can invoke the setter using the following: &lt;br /&gt;
person.age = 99&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Scala has some unconventional ideas that provide a solid, well thought out, and an abbreviated syntax to access object properties. This getter code simply defines a method called “age” and returns the “_age” variable. Scala doesn’t require the return keyword. The setter method name is “age_=”. The underscore is a special character in Scala and in this case, allows for a space in the method name which essentially makes the name “age =”. The parentheses and contents dictate the value and type that needs to be passed in. The “:Unit” code is equivalent to returning void. The remaining code is setting the “_age” variable to “value”.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Smalltalk===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     name                           &amp;quot;gets the value of name&amp;quot;&lt;br /&gt;
     name:aName              &amp;quot;sets name to the value of aName&amp;quot;&lt;br /&gt;
&lt;br /&gt;
     address                        &amp;quot;gets the value of address&amp;quot;&lt;br /&gt;
     address:anAddress     &amp;quot;sets anAddress to the value of anAddress&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In [http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk] the names of getter methods are usually the same as the name of the instance variable. A colon is added to the end of setter method name e.g. colour:&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Actionscript ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public var fullName:String;&lt;br /&gt;
private var _fullName:String;&lt;br /&gt;
&lt;br /&gt;
public function get fullName():String {&lt;br /&gt;
   return _fullName;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public function set fullName(_fullName:String):void {&lt;br /&gt;
   this._fullName = _fullName;&lt;br /&gt;
}&lt;br /&gt;
// getters&lt;br /&gt;
var1 = obj.fullName;&lt;br /&gt;
var2 = obj['fullName'];&lt;br /&gt;
// setters&lt;br /&gt;
obj.fullName = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
obj['fullName'] = &amp;quot;Yes&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getting or setting the property would call the getter and setter functions instead of accessing the property directly&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
==Getters and Setters from a different perspective==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
A fundamental precept of OO systems is that an object should not expose any of its implementation details. This way, you can change the implementation without changing the code that uses the object. It follows then that in OO systems you should avoid getter and setter functions since they mostly provide access to implementation details. For instance if you need change the return type of a gettr method from int to long to accommodate the big numbers you need to change all the invocations of that getter method. This negates the concept of [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html information hiding]. The same issue arises when you need to change the accessed field’s type. You also have to change the getter’s return type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Solution:	 &lt;br /&gt;
Maintainability is inversely proportionate to the amount of data that moves between objects. Thus, its best to minimize data movement as much as possible. The idea is to focus on what you will do rather than how you will do it. Don't ask for the information you need to do the work; ask the object that has the information to do the work for you. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
'''&lt;br /&gt;
Getters and setters provide a convenient method to access the instance variables. A lot of new languages have come up with the support for accessing getters and setters as instance variable reference which improves the readability of the code. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== References ==&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx Understanding properties in C#]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html why getters and setters are evil ]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set php5 OOPS tutorial]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://stefaanlippens.net/python_property_trick python-hiding attribute getters and setters behind standard attribute access]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 Object.defineProperty Function (JavaScript)]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Getters and Setters in Scala]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ ColdFusion 9 : Implicit/Generated CFC Methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.jamesward.com/2010/05/07/flex-and-java-differences-getters-setters/  Flex and Java Differences: Getters &amp;amp; Setters]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.touch-code-magazine.com/objective-c-properties/ Objective C properties]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Properties in Lua]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.netalive.org/tinkering/serious-perl/#import_extend Perl ]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Classes#Instance_Variables Ruby]&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=49109</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h hs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=49109"/>
		<updated>2011-09-17T22:50:30Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Perl */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
== What are getters and setters ? ==&lt;br /&gt;
''' &lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide getter and setter methods to access/modify object data. When writing new classes, it's a good idea to pay attention to the issue of access control. Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. Because of this naming convention, accessor methods are more often referred to as getter methods. This is a good programming practice, since the data fields are not directly accessible outside the class. Thus 'Getters' and 'Setters' allow us to effectively protect your data. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and setters as method calls ==&lt;br /&gt;
'''&lt;br /&gt;
For each variable, a get method will return its value and a set method will set the value. Here are the advantages of using getter and setter as method calls: &lt;br /&gt;
* Encapsulate the data from accidental / inadvertent modification. The private member variable is not part of the public interface of your class; only the public getter and setter methods are, and you are free to change their implementations without changing the public interface of your class&lt;br /&gt;
* If we decide that some action should be taken every time you change/access the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. For Instance, we can keep track of how many times a variable is accessed. &lt;br /&gt;
* Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and getters as variable references(properties) ==&lt;br /&gt;
'''&lt;br /&gt;
Properties are a robust way to handle object’s data. Properties support accessing the instance variables the same way as calling an instance method. A property communicates the idea of &amp;quot;I will make a value available to you, or accept a value from you.&amp;quot; It's not an implementation concept, it's an interface concept. Different languages follow specific syntax for adding a property to a class. Following are the advantages properties: &lt;br /&gt;
* the code is much cleaner when accessing a property when compared to Java or C++ which uses 2 separate methods for each instance variable. They are very useful in GUI programming which necessitates using a lot of fields for UI elements&lt;br /&gt;
* With properties we have fine-grained access control. For instance we can define a property as abstract thereby forcing the derived class to define that property. &lt;br /&gt;
* The main advantage of using properties is that if the internal implementation of getting or setting the property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class. This allows the interface of the object to stay the same even if the underlying implementation of getting and setting the property changes. &lt;br /&gt;
&lt;br /&gt;
Realizing the importance of getters and setters, popular IDEs like Eclipse, Visual studio has a built in mechanism to add getter and setter for a field or to create a property (in C#) for a given field.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples Languages that use getters and setters as method calls: ==&lt;br /&gt;
'''&lt;br /&gt;
'''&lt;br /&gt;
===C++===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
  int x_value;&lt;br /&gt;
&lt;br /&gt;
  public:&lt;br /&gt;
  // Getter&lt;br /&gt;
  int getx_value()&lt;br /&gt;
  {&lt;br /&gt;
      return x;&lt;br /&gt;
  }&lt;br /&gt;
  // Setter&lt;br /&gt;
  void setx_value( int x )&lt;br /&gt;
  {&lt;br /&gt;
      x_value = x;&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
void main()&lt;br /&gt;
{ &lt;br /&gt;
    A a;&lt;br /&gt;
    a.setx_value(5);&lt;br /&gt;
    cout&amp;lt;&amp;lt;a.getx_value();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class BookStore&lt;br /&gt;
{ &lt;br /&gt;
  String title;&lt;br /&gt;
  public String getTitle()&lt;br /&gt;
  {&lt;br /&gt;
     return title;&lt;br /&gt;
  }&lt;br /&gt;
  // a setter method might check that the value that is being assigned to the variable is legal&lt;br /&gt;
  public void setTitle( String newTitle ) &lt;br /&gt;
  {&lt;br /&gt;
    if ( newTitle == null )   // Don't allow null strings as titles!&lt;br /&gt;
       title = &amp;quot;(Untitled)&amp;quot;;  // Use an appropriate default value instead.&lt;br /&gt;
    else&lt;br /&gt;
       title = newTitle;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
     BookStore obj;&lt;br /&gt;
     obj. setTitle(&amp;quot;&amp;quot;);&lt;br /&gt;
     System.out.println(obj.getTitle());&lt;br /&gt;
}&lt;br /&gt;
Output:&lt;br /&gt;
(Untitled)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
'''&lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide accessor methods to modify object data. [http://www.netalive.org/tinkering/serious-perl/#import_extend Perl] does not have private variables but we can still use the concept of getter, setter functions methods.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub setName &lt;br /&gt;
{&lt;br /&gt;
   my ( $self, $Name ) = @_;&lt;br /&gt;
   $self-&amp;gt;{_Name} = $Name;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
sub getName &lt;br /&gt;
{&lt;br /&gt;
   my( $self ) = @_;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== ColdFusion === &lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Component Person&lt;br /&gt;
{&lt;br /&gt;
   property name&lt;br /&gt;
   property age;&lt;br /&gt;
   property city;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;!--- Once an object is created we can directly call the setters and getters for the properties as ---&amp;gt;&lt;br /&gt;
&amp;lt;cfscript&amp;gt;&lt;br /&gt;
   person = new Person();&lt;br /&gt;
   person.setName(&amp;quot;Brad&amp;quot;);&lt;br /&gt;
   person.setAge(46);&lt;br /&gt;
&lt;br /&gt;
   writeOutput(&amp;quot;Name : #person.getName()#&amp;quot;);&lt;br /&gt;
   writeOutput(&amp;quot;Age : #person.getAge()#&amp;quot;); &lt;br /&gt;
&amp;lt;/cfscript&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want to override the getter and setter method, you just need to define those methods in your CFC and ColdFusion will call our method instead of calling the implicit one.The implicit methods can also do some nice validation if you have given the ‘type’ for properties. For instance, if we define a property as numeric and try to provide a try to set a string as its value It will throw a nice error saying “The value cannot be converted to a numeric”.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples from Languages that use getters and setters as instance variable references:  ==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== C#: ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;class MyClass&lt;br /&gt;
{&lt;br /&gt;
      private int x;&lt;br /&gt;
      public int X&lt;br /&gt;
      {&lt;br /&gt;
            get&lt;br /&gt;
           {&lt;br /&gt;
             return x;&lt;br /&gt;
           }&lt;br /&gt;
          set&lt;br /&gt;
          {&lt;br /&gt;
             x = value;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
//Invocation&lt;br /&gt;
MyClass mc = new MyClass();&lt;br /&gt;
mc.X = 10;                   // calls set accessor of the property X, and pass 10 as value of the standard field 'value'.&lt;br /&gt;
Console.WriteLine(mc.X);     // displays 10. Calls the get accessor of the property X.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
C# also supports static properties, which belongs to the class rather than to the objects of the class. The properties of a Base class can be inherited to a Derived class and can be overridden polymorphicaly. &lt;br /&gt;
'''&lt;br /&gt;
===Lua===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class 'Test'&lt;br /&gt;
  function  Test : getLength()&lt;br /&gt;
   return # self.value&lt;br /&gt;
  end&lt;br /&gt;
  function  Test : setLength(newLength)&lt;br /&gt;
    for  i = self.length, newLength do&lt;br /&gt;
        table.insert(self.value, false )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
test =  Test({1, 2, 3, 4})&lt;br /&gt;
print(test.length)&lt;br /&gt;
self.length = property( Test.getLength, Test.setLength )    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getter and Setter functions can be implemented in Lua, which is similar to the properties concept in C#. This allows the functions to bind to a property that can be assigned and accessed as a value.&lt;br /&gt;
'''&lt;br /&gt;
===Ruby===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
    def initialize(lname, fname)&lt;br /&gt;
        @lname = lname&lt;br /&gt;
        @fname = fname&lt;br /&gt;
    end&lt;br /&gt;
attr_reader :lname // creates a getter method&lt;br /&gt;
    attr_writer :lname    // creates a setter method&lt;br /&gt;
    attr_accessor :fname // creates both getter and setter method&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x = Person.new(&amp;quot;ABC&amp;quot;, &amp;quot;XYZ&amp;quot;)&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
x.fname = &amp;quot;PQR&amp;quot;&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ruby simplifies the creation of getters and setters with a little metaprogramming and the methods attr, attr_reader, attr_writer, and attr_accessor, all from the Module class. By supplying the attr method, Ruby provides a way to acces the instances directly.&lt;br /&gt;
'''&lt;br /&gt;
===Php===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
class Customer&lt;br /&gt;
{&lt;br /&gt;
   public $name;&lt;br /&gt;
   private $data = array();&lt;br /&gt;
   public function __set($dt, $vl) &lt;br /&gt;
   {&lt;br /&gt;
      $this-&amp;gt;data[$dt] = $vl;&lt;br /&gt;
   }&lt;br /&gt;
   public function __get($dt) &lt;br /&gt;
   {&lt;br /&gt;
      return $this-&amp;gt;data[$dt];&lt;br /&gt;
   }&lt;br /&gt;
} &lt;br /&gt;
$c = new Customer();&lt;br /&gt;
$c-&amp;gt;name = “Sunil”; // $name is set because its public&lt;br /&gt;
$c-&amp;gt;email = “email@domain.com”; //assigning email@domain.com to the $email variable.&lt;br /&gt;
echo $c-&amp;gt;email;&lt;br /&gt;
?&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
An interesting aspect of php worth noting is that we can assign values to undefined variables. Because of the above limitation, PHP engine provides two magic methods __get() and __set(). __get() is used when value from an undefined variable is to be read and __set() is used when a value is to be assigned to a undefined variable of a class.In the above example when email@domain.com is assigned to the undefined variable $email, the magic method __set() is called. To this __set() method the name of the variable is passed into $dt variable of __set() method and the value i.e. email@domain.com is passed to $vl variable of the __set() method.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Objective C===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// public header file&lt;br /&gt;
@interface MyObject : NSObject&lt;br /&gt;
{&lt;br /&gt;
  NSString *make; &lt;br /&gt;
  NSString* model;&lt;br /&gt;
  NSNumber* vin;&lt;br /&gt;
}&lt;br /&gt;
@property (readonly, copy) NSString *language;&lt;br /&gt;
@property(readwrite, retain) NSString* make;&lt;br /&gt;
@property(readwrite, retain) NSString* model;&lt;br /&gt;
@property(readwrite, retain) NSNumber* vin;&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
#import &amp;quot;SimpleCar.h&amp;quot;&lt;br /&gt;
@implementation SimpleCar&lt;br /&gt;
@synthesize make, model, vin;&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Objective C we can define a property using @property directive. @synthesize will create automatically for you a setter and a getter methods for the property which becomes accessible during the run time.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Python ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DoubleIt(object):&lt;br /&gt;
   def _get_value(self):&lt;br /&gt;
       return self._value * 2&lt;br /&gt;
   def _set_value(self, value):&lt;br /&gt;
       self._value = value&lt;br /&gt;
   value = property(_get_value, _set_value)&lt;br /&gt;
&lt;br /&gt;
# Invocation &lt;br /&gt;
x = DoubleIt()&lt;br /&gt;
 &lt;br /&gt;
x.value = 10&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = 'foo'&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = [1,2,3]&lt;br /&gt;
print x.value&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above [http://stefaanlippens.net/python_property_trick python] code, the output is doubled since the getter multiplies the value by 2&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Javascript ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function addDataProperty()&lt;br /&gt;
{&lt;br /&gt;
   var newLine = &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;;&lt;br /&gt;
   var obj = {};&lt;br /&gt;
  &lt;br /&gt;
   // Add a data property to the object.&lt;br /&gt;
   Object.defineProperty(obj, &amp;quot;newDataProperty&amp;quot;, &lt;br /&gt;
   {&lt;br /&gt;
       value: 101,&lt;br /&gt;
       writable: true,&lt;br /&gt;
       enumerable: true,&lt;br /&gt;
       configurable: true&lt;br /&gt;
   });&lt;br /&gt;
&lt;br /&gt;
   // Set the property value.&lt;br /&gt;
   obj.newDataProperty = 102;&lt;br /&gt;
   document.write(&amp;quot;Property value: &amp;quot; + obj.newDataProperty + newLine);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Javascript supports accessing getters and setters as variable as properties. Javascript originally used __defineGetter__ and __defineSetter__ syntax to define properties which is depricated as the language evolved. Object.defineProperty is currently used for creating a property. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Scala ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person() {&lt;br /&gt;
// Private age variable, renamed to _age&lt;br /&gt;
private var _age = 0&lt;br /&gt;
var name = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Getter&lt;br /&gt;
def age = _age&lt;br /&gt;
&lt;br /&gt;
// Setter&lt;br /&gt;
def age_= (value:Int):Unit = _age = value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// We can invoke the setter as follows : &lt;br /&gt;
 can invoke the setter using the following: &lt;br /&gt;
person.age = 99&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Scala has some unconventional ideas that provide a solid, well thought out, and an abbreviated syntax to access object properties. This getter code simply defines a method called “age” and returns the “_age” variable. Scala doesn’t require the return keyword. The setter method name is “age_=”. The underscore is a special character in Scala and in this case, allows for a space in the method name which essentially makes the name “age =”. The parentheses and contents dictate the value and type that needs to be passed in. The “:Unit” code is equivalent to returning void. The remaining code is setting the “_age” variable to “value”.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Smalltalk===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     name                           &amp;quot;gets the value of name&amp;quot;&lt;br /&gt;
     name:aName              &amp;quot;sets name to the value of aName&amp;quot;&lt;br /&gt;
&lt;br /&gt;
     address                        &amp;quot;gets the value of address&amp;quot;&lt;br /&gt;
     address:anAddress     &amp;quot;sets anAddress to the value of anAddress&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In [http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk] the names of getter methods are usually the same as the name of the instance variable. A colon is added to the end of setter method name e.g. colour:&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Actionscript ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public var fullName:String;&lt;br /&gt;
private var _fullName:String;&lt;br /&gt;
&lt;br /&gt;
public function get fullName():String {&lt;br /&gt;
   return _fullName;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public function set fullName(_fullName:String):void {&lt;br /&gt;
   this._fullName = _fullName;&lt;br /&gt;
}&lt;br /&gt;
// getters&lt;br /&gt;
var1 = obj.fullName;&lt;br /&gt;
var2 = obj['fullName'];&lt;br /&gt;
// setters&lt;br /&gt;
obj.fullName = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
obj['fullName'] = &amp;quot;Yes&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getting or setting the property would call the getter and setter functions instead of accessing the property directly&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
==Getters and Setters from a different perspective==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
A fundamental precept of OO systems is that an object should not expose any of its implementation details. This way, you can change the implementation without changing the code that uses the object. It follows then that in OO systems you should avoid getter and setter functions since they mostly provide access to implementation details. For instance if you need change the return type of a gettr method from int to long to accommodate the big numbers you need to change all the invocations of that getter method. This negates the concept of [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html information hiding]. The same issue arises when you need to change the accessed field’s type. You also have to change the getter’s return type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Solution:	 &lt;br /&gt;
Maintainability is inversely proportionate to the amount of data that moves between objects. Thus, its best to minimize data movement as much as possible. The idea is to focus on what you will do rather than how you will do it. Don't ask for the information you need to do the work; ask the object that has the information to do the work for you. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
'''&lt;br /&gt;
Getters and setters provide a convenient method to access the instance variables. A lot of new languages have come up with the support for accessing getters and setters as instance variable reference which improves the readability of the code. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== References ==&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx Understanding properties in C#]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html why getters and setters are evil ]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set php5 OOPS tutorial]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://stefaanlippens.net/python_property_trick python-hiding attribute getters and setters behind standard attribute access]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 Object.defineProperty Function (JavaScript)]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Getters and Setters in Scala]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ ColdFusion 9 : Implicit/Generated CFC Methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.jamesward.com/2010/05/07/flex-and-java-differences-getters-setters/  Flex and Java Differences: Getters &amp;amp; Setters]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.touch-code-magazine.com/objective-c-properties/ Objective C properties]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Properties in Lua]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.netalive.org/tinkering/serious-perl/#import_extend Perl ]&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=49108</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h hs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=49108"/>
		<updated>2011-09-17T22:46:54Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
== What are getters and setters ? ==&lt;br /&gt;
''' &lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide getter and setter methods to access/modify object data. When writing new classes, it's a good idea to pay attention to the issue of access control. Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. Because of this naming convention, accessor methods are more often referred to as getter methods. This is a good programming practice, since the data fields are not directly accessible outside the class. Thus 'Getters' and 'Setters' allow us to effectively protect your data. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and setters as method calls ==&lt;br /&gt;
'''&lt;br /&gt;
For each variable, a get method will return its value and a set method will set the value. Here are the advantages of using getter and setter as method calls: &lt;br /&gt;
* Encapsulate the data from accidental / inadvertent modification. The private member variable is not part of the public interface of your class; only the public getter and setter methods are, and you are free to change their implementations without changing the public interface of your class&lt;br /&gt;
* If we decide that some action should be taken every time you change/access the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. For Instance, we can keep track of how many times a variable is accessed. &lt;br /&gt;
* Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and getters as variable references(properties) ==&lt;br /&gt;
'''&lt;br /&gt;
Properties are a robust way to handle object’s data. Properties support accessing the instance variables the same way as calling an instance method. A property communicates the idea of &amp;quot;I will make a value available to you, or accept a value from you.&amp;quot; It's not an implementation concept, it's an interface concept. Different languages follow specific syntax for adding a property to a class. Following are the advantages properties: &lt;br /&gt;
* the code is much cleaner when accessing a property when compared to Java or C++ which uses 2 separate methods for each instance variable. They are very useful in GUI programming which necessitates using a lot of fields for UI elements&lt;br /&gt;
* With properties we have fine-grained access control. For instance we can define a property as abstract thereby forcing the derived class to define that property. &lt;br /&gt;
* The main advantage of using properties is that if the internal implementation of getting or setting the property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class. This allows the interface of the object to stay the same even if the underlying implementation of getting and setting the property changes. &lt;br /&gt;
&lt;br /&gt;
Realizing the importance of getters and setters, popular IDEs like Eclipse, Visual studio has a built in mechanism to add getter and setter for a field or to create a property (in C#) for a given field.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples Languages that use getters and setters as method calls: ==&lt;br /&gt;
'''&lt;br /&gt;
'''&lt;br /&gt;
===C++===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
  int x_value;&lt;br /&gt;
&lt;br /&gt;
  public:&lt;br /&gt;
  // Getter&lt;br /&gt;
  int getx_value()&lt;br /&gt;
  {&lt;br /&gt;
      return x;&lt;br /&gt;
  }&lt;br /&gt;
  // Setter&lt;br /&gt;
  void setx_value( int x )&lt;br /&gt;
  {&lt;br /&gt;
      x_value = x;&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
void main()&lt;br /&gt;
{ &lt;br /&gt;
    A a;&lt;br /&gt;
    a.setx_value(5);&lt;br /&gt;
    cout&amp;lt;&amp;lt;a.getx_value();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class BookStore&lt;br /&gt;
{ &lt;br /&gt;
  String title;&lt;br /&gt;
  public String getTitle()&lt;br /&gt;
  {&lt;br /&gt;
     return title;&lt;br /&gt;
  }&lt;br /&gt;
  // a setter method might check that the value that is being assigned to the variable is legal&lt;br /&gt;
  public void setTitle( String newTitle ) &lt;br /&gt;
  {&lt;br /&gt;
    if ( newTitle == null )   // Don't allow null strings as titles!&lt;br /&gt;
       title = &amp;quot;(Untitled)&amp;quot;;  // Use an appropriate default value instead.&lt;br /&gt;
    else&lt;br /&gt;
       title = newTitle;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
     BookStore obj;&lt;br /&gt;
     obj. setTitle(&amp;quot;&amp;quot;);&lt;br /&gt;
     System.out.println(obj.getTitle());&lt;br /&gt;
}&lt;br /&gt;
Output:&lt;br /&gt;
(Untitled)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
'''&lt;br /&gt;
[http://www.netalive.org/tinkering/serious-perl/#import_extend Perl] does not have private variables but we can still use the concept of getter, setter functions methods.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub setName &lt;br /&gt;
{&lt;br /&gt;
   my ( $self, $Name ) = @_;&lt;br /&gt;
   $self-&amp;gt;{_Name} = $Name;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
sub getName &lt;br /&gt;
{&lt;br /&gt;
   my( $self ) = @_;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== ColdFusion === &lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Component Person&lt;br /&gt;
{&lt;br /&gt;
   property name&lt;br /&gt;
   property age;&lt;br /&gt;
   property city;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;!--- Once an object is created we can directly call the setters and getters for the properties as ---&amp;gt;&lt;br /&gt;
&amp;lt;cfscript&amp;gt;&lt;br /&gt;
   person = new Person();&lt;br /&gt;
   person.setName(&amp;quot;Brad&amp;quot;);&lt;br /&gt;
   person.setAge(46);&lt;br /&gt;
&lt;br /&gt;
   writeOutput(&amp;quot;Name : #person.getName()#&amp;quot;);&lt;br /&gt;
   writeOutput(&amp;quot;Age : #person.getAge()#&amp;quot;); &lt;br /&gt;
&amp;lt;/cfscript&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want to override the getter and setter method, you just need to define those methods in your CFC and ColdFusion will call our method instead of calling the implicit one.The implicit methods can also do some nice validation if you have given the ‘type’ for properties. For instance, if we define a property as numeric and try to provide a try to set a string as its value It will throw a nice error saying “The value cannot be converted to a numeric”.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples from Languages that use getters and setters as instance variable references:  ==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== C#: ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;class MyClass&lt;br /&gt;
{&lt;br /&gt;
      private int x;&lt;br /&gt;
      public int X&lt;br /&gt;
      {&lt;br /&gt;
            get&lt;br /&gt;
           {&lt;br /&gt;
             return x;&lt;br /&gt;
           }&lt;br /&gt;
          set&lt;br /&gt;
          {&lt;br /&gt;
             x = value;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
//Invocation&lt;br /&gt;
MyClass mc = new MyClass();&lt;br /&gt;
mc.X = 10;                   // calls set accessor of the property X, and pass 10 as value of the standard field 'value'.&lt;br /&gt;
Console.WriteLine(mc.X);     // displays 10. Calls the get accessor of the property X.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
C# also supports static properties, which belongs to the class rather than to the objects of the class. The properties of a Base class can be inherited to a Derived class and can be overridden polymorphicaly. &lt;br /&gt;
'''&lt;br /&gt;
===Lua===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class 'Test'&lt;br /&gt;
  function  Test : getLength()&lt;br /&gt;
   return # self.value&lt;br /&gt;
  end&lt;br /&gt;
  function  Test : setLength(newLength)&lt;br /&gt;
    for  i = self.length, newLength do&lt;br /&gt;
        table.insert(self.value, false )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
test =  Test({1, 2, 3, 4})&lt;br /&gt;
print(test.length)&lt;br /&gt;
self.length = property( Test.getLength, Test.setLength )    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getter and Setter functions can be implemented in Lua, which is similar to the properties concept in C#. This allows the functions to bind to a property that can be assigned and accessed as a value.&lt;br /&gt;
'''&lt;br /&gt;
===Ruby===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
    def initialize(lname, fname)&lt;br /&gt;
        @lname = lname&lt;br /&gt;
        @fname = fname&lt;br /&gt;
    end&lt;br /&gt;
attr_reader :lname // creates a getter method&lt;br /&gt;
    attr_writer :lname    // creates a setter method&lt;br /&gt;
    attr_accessor :fname // creates both getter and setter method&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x = Person.new(&amp;quot;ABC&amp;quot;, &amp;quot;XYZ&amp;quot;)&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
x.fname = &amp;quot;PQR&amp;quot;&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ruby simplifies the creation of getters and setters with a little metaprogramming and the methods attr, attr_reader, attr_writer, and attr_accessor, all from the Module class. By supplying the attr method, Ruby provides a way to acces the instances directly.&lt;br /&gt;
'''&lt;br /&gt;
===Php===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
class Customer&lt;br /&gt;
{&lt;br /&gt;
   public $name;&lt;br /&gt;
   private $data = array();&lt;br /&gt;
   public function __set($dt, $vl) &lt;br /&gt;
   {&lt;br /&gt;
      $this-&amp;gt;data[$dt] = $vl;&lt;br /&gt;
   }&lt;br /&gt;
   public function __get($dt) &lt;br /&gt;
   {&lt;br /&gt;
      return $this-&amp;gt;data[$dt];&lt;br /&gt;
   }&lt;br /&gt;
} &lt;br /&gt;
$c = new Customer();&lt;br /&gt;
$c-&amp;gt;name = “Sunil”; // $name is set because its public&lt;br /&gt;
$c-&amp;gt;email = “email@domain.com”; //assigning email@domain.com to the $email variable.&lt;br /&gt;
echo $c-&amp;gt;email;&lt;br /&gt;
?&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
An interesting aspect of php worth noting is that we can assign values to undefined variables. Because of the above limitation, PHP engine provides two magic methods __get() and __set(). __get() is used when value from an undefined variable is to be read and __set() is used when a value is to be assigned to a undefined variable of a class.In the above example when email@domain.com is assigned to the undefined variable $email, the magic method __set() is called. To this __set() method the name of the variable is passed into $dt variable of __set() method and the value i.e. email@domain.com is passed to $vl variable of the __set() method.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Objective C===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// public header file&lt;br /&gt;
@interface MyObject : NSObject&lt;br /&gt;
{&lt;br /&gt;
  NSString *make; &lt;br /&gt;
  NSString* model;&lt;br /&gt;
  NSNumber* vin;&lt;br /&gt;
}&lt;br /&gt;
@property (readonly, copy) NSString *language;&lt;br /&gt;
@property(readwrite, retain) NSString* make;&lt;br /&gt;
@property(readwrite, retain) NSString* model;&lt;br /&gt;
@property(readwrite, retain) NSNumber* vin;&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
#import &amp;quot;SimpleCar.h&amp;quot;&lt;br /&gt;
@implementation SimpleCar&lt;br /&gt;
@synthesize make, model, vin;&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Objective C we can define a property using @property directive. @synthesize will create automatically for you a setter and a getter methods for the property which becomes accessible during the run time.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Python ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DoubleIt(object):&lt;br /&gt;
   def _get_value(self):&lt;br /&gt;
       return self._value * 2&lt;br /&gt;
   def _set_value(self, value):&lt;br /&gt;
       self._value = value&lt;br /&gt;
   value = property(_get_value, _set_value)&lt;br /&gt;
&lt;br /&gt;
# Invocation &lt;br /&gt;
x = DoubleIt()&lt;br /&gt;
 &lt;br /&gt;
x.value = 10&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = 'foo'&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = [1,2,3]&lt;br /&gt;
print x.value&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above [http://stefaanlippens.net/python_property_trick python] code, the output is doubled since the getter multiplies the value by 2&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Javascript ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function addDataProperty()&lt;br /&gt;
{&lt;br /&gt;
   var newLine = &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;;&lt;br /&gt;
   var obj = {};&lt;br /&gt;
  &lt;br /&gt;
   // Add a data property to the object.&lt;br /&gt;
   Object.defineProperty(obj, &amp;quot;newDataProperty&amp;quot;, &lt;br /&gt;
   {&lt;br /&gt;
       value: 101,&lt;br /&gt;
       writable: true,&lt;br /&gt;
       enumerable: true,&lt;br /&gt;
       configurable: true&lt;br /&gt;
   });&lt;br /&gt;
&lt;br /&gt;
   // Set the property value.&lt;br /&gt;
   obj.newDataProperty = 102;&lt;br /&gt;
   document.write(&amp;quot;Property value: &amp;quot; + obj.newDataProperty + newLine);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Javascript supports accessing getters and setters as variable as properties. Javascript originally used __defineGetter__ and __defineSetter__ syntax to define properties which is depricated as the language evolved. Object.defineProperty is currently used for creating a property. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Scala ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person() {&lt;br /&gt;
// Private age variable, renamed to _age&lt;br /&gt;
private var _age = 0&lt;br /&gt;
var name = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Getter&lt;br /&gt;
def age = _age&lt;br /&gt;
&lt;br /&gt;
// Setter&lt;br /&gt;
def age_= (value:Int):Unit = _age = value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// We can invoke the setter as follows : &lt;br /&gt;
 can invoke the setter using the following: &lt;br /&gt;
person.age = 99&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Scala has some unconventional ideas that provide a solid, well thought out, and an abbreviated syntax to access object properties. This getter code simply defines a method called “age” and returns the “_age” variable. Scala doesn’t require the return keyword. The setter method name is “age_=”. The underscore is a special character in Scala and in this case, allows for a space in the method name which essentially makes the name “age =”. The parentheses and contents dictate the value and type that needs to be passed in. The “:Unit” code is equivalent to returning void. The remaining code is setting the “_age” variable to “value”.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Smalltalk===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     name                           &amp;quot;gets the value of name&amp;quot;&lt;br /&gt;
     name:aName              &amp;quot;sets name to the value of aName&amp;quot;&lt;br /&gt;
&lt;br /&gt;
     address                        &amp;quot;gets the value of address&amp;quot;&lt;br /&gt;
     address:anAddress     &amp;quot;sets anAddress to the value of anAddress&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In [http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk] the names of getter methods are usually the same as the name of the instance variable. A colon is added to the end of setter method name e.g. colour:&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Actionscript ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public var fullName:String;&lt;br /&gt;
private var _fullName:String;&lt;br /&gt;
&lt;br /&gt;
public function get fullName():String {&lt;br /&gt;
   return _fullName;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public function set fullName(_fullName:String):void {&lt;br /&gt;
   this._fullName = _fullName;&lt;br /&gt;
}&lt;br /&gt;
// getters&lt;br /&gt;
var1 = obj.fullName;&lt;br /&gt;
var2 = obj['fullName'];&lt;br /&gt;
// setters&lt;br /&gt;
obj.fullName = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
obj['fullName'] = &amp;quot;Yes&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getting or setting the property would call the getter and setter functions instead of accessing the property directly&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
==Getters and Setters from a different perspective==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
A fundamental precept of OO systems is that an object should not expose any of its implementation details. This way, you can change the implementation without changing the code that uses the object. It follows then that in OO systems you should avoid getter and setter functions since they mostly provide access to implementation details. For instance if you need change the return type of a gettr method from int to long to accommodate the big numbers you need to change all the invocations of that getter method. This negates the concept of [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html information hiding]. The same issue arises when you need to change the accessed field’s type. You also have to change the getter’s return type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Solution:	 &lt;br /&gt;
Maintainability is inversely proportionate to the amount of data that moves between objects. Thus, its best to minimize data movement as much as possible. The idea is to focus on what you will do rather than how you will do it. Don't ask for the information you need to do the work; ask the object that has the information to do the work for you. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
'''&lt;br /&gt;
Getters and setters provide a convenient method to access the instance variables. A lot of new languages have come up with the support for accessing getters and setters as instance variable reference which improves the readability of the code. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== References ==&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx Understanding properties in C#]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html why getters and setters are evil ]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set php5 OOPS tutorial]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://stefaanlippens.net/python_property_trick python-hiding attribute getters and setters behind standard attribute access]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 Object.defineProperty Function (JavaScript)]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Getters and Setters in Scala]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ ColdFusion 9 : Implicit/Generated CFC Methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.jamesward.com/2010/05/07/flex-and-java-differences-getters-setters/  Flex and Java Differences: Getters &amp;amp; Setters]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.touch-code-magazine.com/objective-c-properties/ Objective C properties]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Properties in Lua]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.netalive.org/tinkering/serious-perl/#import_extend Perl ]&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=49096</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h hs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=49096"/>
		<updated>2011-09-17T22:26:44Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Perl */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
== What are getters and setters ? ==&lt;br /&gt;
''' &lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide getter and setter methods to access/modify object data. When writing new classes, it's a good idea to pay attention to the issue of access control. Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. Because of this naming convention, accessor methods are more often referred to as getter methods. This is a good programming practice, since the data fields are not directly accessible outside the class. Thus 'Getters' and 'Setters' allow us to effectively protect your data. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and setters as method calls ==&lt;br /&gt;
'''&lt;br /&gt;
For each variable, a get method will return its value and a set method will set the value. Here are the advantages of using getter and setter as method calls: &lt;br /&gt;
* Encapsulate the data from accidental / inadvertent modification. The private member variable is not part of the public interface of your class; only the public getter and setter methods are, and you are free to change their implementations without changing the public interface of your class&lt;br /&gt;
* If we decide that some action should be taken every time you change/access the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. For Instance, we can keep track of how many times a variable is accessed. &lt;br /&gt;
* Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and getters as variable references(properties) ==&lt;br /&gt;
'''&lt;br /&gt;
Properties are a robust way to handle object’s data. Properties support accessing the instance variables the same way as calling an instance method. A property communicates the idea of &amp;quot;I will make a value available to you, or accept a value from you.&amp;quot; It's not an implementation concept, it's an interface concept. Different languages follow specific syntax for adding a property to a class. Following are the advantages properties: &lt;br /&gt;
* the code is much cleaner when accessing a property when compared to Java or C++ which uses 2 separate methods for each instance variable. They are very useful in GUI programming which necessitates using a lot of fields for UI elements&lt;br /&gt;
* With properties we have fine-grained access control. For instance we can define a property as abstract thereby forcing the derived class to define that property. &lt;br /&gt;
* The main advantage of using properties is that if the internal implementation of getting or setting the property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class. This allows the interface of the object to stay the same even if the underlying implementation of getting and setting the property changes. &lt;br /&gt;
&lt;br /&gt;
Realizing the importance of getters and setters, popular IDEs like Eclipse, Visual studio has a built in mechanism to add getter and setter for a field or to create a property (in C#) for a given field.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples Languages that use getters and setters as method calls: ==&lt;br /&gt;
'''&lt;br /&gt;
'''&lt;br /&gt;
===C++===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
  int x_value;&lt;br /&gt;
&lt;br /&gt;
  public:&lt;br /&gt;
  // Getter&lt;br /&gt;
  int getx_value()&lt;br /&gt;
  {&lt;br /&gt;
      return x;&lt;br /&gt;
  }&lt;br /&gt;
  // Setter&lt;br /&gt;
  void setx_value( int x )&lt;br /&gt;
  {&lt;br /&gt;
      x_value = x;&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
void main()&lt;br /&gt;
{ &lt;br /&gt;
    A a;&lt;br /&gt;
    a.setx_value(5);&lt;br /&gt;
    cout&amp;lt;&amp;lt;a.getx_value();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class BookStore&lt;br /&gt;
{ &lt;br /&gt;
  String title;&lt;br /&gt;
  public String getTitle()&lt;br /&gt;
  {&lt;br /&gt;
     return title;&lt;br /&gt;
  }&lt;br /&gt;
  // a setter method might check that the value that is being assigned to the variable is legal&lt;br /&gt;
  public void setTitle( String newTitle ) &lt;br /&gt;
  {&lt;br /&gt;
    if ( newTitle == null )   // Don't allow null strings as titles!&lt;br /&gt;
       title = &amp;quot;(Untitled)&amp;quot;;  // Use an appropriate default value instead.&lt;br /&gt;
    else&lt;br /&gt;
       title = newTitle;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
     BookStore obj;&lt;br /&gt;
     obj. setTitle(&amp;quot;&amp;quot;);&lt;br /&gt;
     System.out.println(obj.getTitle());&lt;br /&gt;
}&lt;br /&gt;
Output:&lt;br /&gt;
(Untitled)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
'''&lt;br /&gt;
Perl does not have private variables but we can still use the concept of getter, setter functions methods.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub setName &lt;br /&gt;
{&lt;br /&gt;
   my ( $self, $Name ) = @_;&lt;br /&gt;
   $self-&amp;gt;{_Name} = $Name if defined($Name);&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
sub getName &lt;br /&gt;
{&lt;br /&gt;
   my( $self ) = @_;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
# Now Set first name using helper function.&lt;br /&gt;
$object-&amp;gt;setName( &amp;quot;ABC&amp;quot; );&lt;br /&gt;
# Get name which is set using constructor.&lt;br /&gt;
$Name = $object-&amp;gt;getName();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== ColdFusion === &lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Component Person&lt;br /&gt;
{&lt;br /&gt;
   property name&lt;br /&gt;
   property age;&lt;br /&gt;
   property city;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;!--- Once an object is created we can directly call the setters and getters for the properties as ---&amp;gt;&lt;br /&gt;
&amp;lt;cfscript&amp;gt;&lt;br /&gt;
   person = new Person();&lt;br /&gt;
   person.setName(&amp;quot;Brad&amp;quot;);&lt;br /&gt;
   person.setAge(46);&lt;br /&gt;
&lt;br /&gt;
   writeOutput(&amp;quot;Name : #person.getName()#&amp;quot;);&lt;br /&gt;
   writeOutput(&amp;quot;Age : #person.getAge()#&amp;quot;); &lt;br /&gt;
&amp;lt;/cfscript&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want to override the getter and setter method, you just need to define those methods in your CFC and ColdFusion will call our method instead of calling the implicit one.The implicit methods can also do some nice validation if you have given the ‘type’ for properties. For instance, if we define a property as numeric and try to provide a try to set a string as its value It will throw a nice error saying “The value cannot be converted to a numeric”.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples from Languages that use getters and setters as instance variable references:  ==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== C#: ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;class MyClass&lt;br /&gt;
{&lt;br /&gt;
      private int x;&lt;br /&gt;
      public int X&lt;br /&gt;
      {&lt;br /&gt;
            get&lt;br /&gt;
           {&lt;br /&gt;
             return x;&lt;br /&gt;
           }&lt;br /&gt;
          set&lt;br /&gt;
          {&lt;br /&gt;
             x = value;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
//Invocation&lt;br /&gt;
MyClass mc = new MyClass();&lt;br /&gt;
mc.X = 10;                   // calls set accessor of the property X, and pass 10 as value of the standard field 'value'.&lt;br /&gt;
Console.WriteLine(mc.X);     // displays 10. Calls the get accessor of the property X.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
C# also supports static properties, which belongs to the class rather than to the objects of the class. The properties of a Base class can be inherited to a Derived class and can be overridden polymorphicaly. &lt;br /&gt;
'''&lt;br /&gt;
===Lua===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class 'Test'&lt;br /&gt;
  function  Test : getLength()&lt;br /&gt;
   return # self.value&lt;br /&gt;
  end&lt;br /&gt;
  function  Test : setLength(newLength)&lt;br /&gt;
    for  i = self.length, newLength do&lt;br /&gt;
        table.insert(self.value, false )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
test =  Test({1, 2, 3, 4})&lt;br /&gt;
print(test.length)&lt;br /&gt;
self.length = property( Test.getLength, Test.setLength )    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getter and Setter functions can be implemented in Lua, which is similar to the properties concept in C#. This allows the functions to bind to a property that can be assigned and accessed as a value.&lt;br /&gt;
'''&lt;br /&gt;
===Ruby===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
    def initialize(lname, fname)&lt;br /&gt;
        @lname = lname&lt;br /&gt;
        @fname = fname&lt;br /&gt;
    end&lt;br /&gt;
attr_reader :lname // creates a getter method&lt;br /&gt;
    attr_writer :lname    // creates a setter method&lt;br /&gt;
    attr_accessor :fname // creates both getter and setter method&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x = Person.new(&amp;quot;ABC&amp;quot;, &amp;quot;XYZ&amp;quot;)&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
x.fname = &amp;quot;PQR&amp;quot;&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ruby simplifies the creation of getters and setters with a little metaprogramming and the methods attr, attr_reader, attr_writer, and attr_accessor, all from the Module class. By supplying the attr method, Ruby provides a way to acces the instances directly.&lt;br /&gt;
'''&lt;br /&gt;
===Php===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
class Customer&lt;br /&gt;
{&lt;br /&gt;
   public $name;&lt;br /&gt;
   private $data = array();&lt;br /&gt;
   public function __set($dt, $vl) &lt;br /&gt;
   {&lt;br /&gt;
      $this-&amp;gt;data[$dt] = $vl;&lt;br /&gt;
   }&lt;br /&gt;
   public function __get($dt) &lt;br /&gt;
   {&lt;br /&gt;
      return $this-&amp;gt;data[$dt];&lt;br /&gt;
   }&lt;br /&gt;
} &lt;br /&gt;
$c = new Customer();&lt;br /&gt;
$c-&amp;gt;name = “Sunil”; // $name is set because its public&lt;br /&gt;
$c-&amp;gt;email = “email@domain.com”; //assigning email@domain.com to the $email variable.&lt;br /&gt;
echo $c-&amp;gt;email;&lt;br /&gt;
?&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
An interesting aspect of php worth noting is that we can assign values to undefined variables. Because of the above limitation, PHP engine provides two magic methods __get() and __set(). __get() is used when value from an undefined variable is to be read and __set() is used when a value is to be assigned to a undefined variable of a class.In the above example when email@domain.com is assigned to the undefined variable $email, the magic method __set() is called. To this __set() method the name of the variable is passed into $dt variable of __set() method and the value i.e. email@domain.com is passed to $vl variable of the __set() method.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Objective C===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// public header file&lt;br /&gt;
@interface MyObject : NSObject&lt;br /&gt;
{&lt;br /&gt;
  NSString *make; &lt;br /&gt;
  NSString* model;&lt;br /&gt;
  NSNumber* vin;&lt;br /&gt;
}&lt;br /&gt;
@property (readonly, copy) NSString *language;&lt;br /&gt;
@property(readwrite, retain) NSString* make;&lt;br /&gt;
@property(readwrite, retain) NSString* model;&lt;br /&gt;
@property(readwrite, retain) NSNumber* vin;&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
#import &amp;quot;SimpleCar.h&amp;quot;&lt;br /&gt;
@implementation SimpleCar&lt;br /&gt;
@synthesize make, model, vin;&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Objective C we can define a property using @property directive. @synthesize will create automatically for you a setter and a getter methods for the property which becomes accessible during the run time.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Python ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DoubleIt(object):&lt;br /&gt;
   def _get_value(self):&lt;br /&gt;
       return self._value * 2&lt;br /&gt;
   def _set_value(self, value):&lt;br /&gt;
       self._value = value&lt;br /&gt;
   value = property(_get_value, _set_value)&lt;br /&gt;
&lt;br /&gt;
# Invocation &lt;br /&gt;
x = DoubleIt()&lt;br /&gt;
 &lt;br /&gt;
x.value = 10&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = 'foo'&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = [1,2,3]&lt;br /&gt;
print x.value&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above [http://stefaanlippens.net/python_property_trick python] code, the output is doubled since the getter multiplies the value by 2&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Javascript ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function addDataProperty()&lt;br /&gt;
{&lt;br /&gt;
   var newLine = &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;;&lt;br /&gt;
   var obj = {};&lt;br /&gt;
  &lt;br /&gt;
   // Add a data property to the object.&lt;br /&gt;
   Object.defineProperty(obj, &amp;quot;newDataProperty&amp;quot;, &lt;br /&gt;
   {&lt;br /&gt;
       value: 101,&lt;br /&gt;
       writable: true,&lt;br /&gt;
       enumerable: true,&lt;br /&gt;
       configurable: true&lt;br /&gt;
   });&lt;br /&gt;
&lt;br /&gt;
   // Set the property value.&lt;br /&gt;
   obj.newDataProperty = 102;&lt;br /&gt;
   document.write(&amp;quot;Property value: &amp;quot; + obj.newDataProperty + newLine);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Javascript supports accessing getters and setters as variable as properties. Javascript originally used __defineGetter__ and __defineSetter__ syntax to define properties which is depricated as the language evolved. Object.defineProperty is currently used for creating a property. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Scala ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person() {&lt;br /&gt;
// Private age variable, renamed to _age&lt;br /&gt;
private var _age = 0&lt;br /&gt;
var name = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Getter&lt;br /&gt;
def age = _age&lt;br /&gt;
&lt;br /&gt;
// Setter&lt;br /&gt;
def age_= (value:Int):Unit = _age = value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// We can invoke the setter as follows : &lt;br /&gt;
 can invoke the setter using the following: &lt;br /&gt;
person.age = 99&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Scala has some unconventional ideas that provide a solid, well thought out, and an abbreviated syntax to access object properties. This getter code simply defines a method called “age” and returns the “_age” variable. Scala doesn’t require the return keyword. The setter method name is “age_=”. The underscore is a special character in Scala and in this case, allows for a space in the method name which essentially makes the name “age =”. The parentheses and contents dictate the value and type that needs to be passed in. The “:Unit” code is equivalent to returning void. The remaining code is setting the “_age” variable to “value”.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Smalltalk===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     name                           &amp;quot;gets the value of name&amp;quot;&lt;br /&gt;
     name:aName              &amp;quot;sets name to the value of aName&amp;quot;&lt;br /&gt;
&lt;br /&gt;
     address                        &amp;quot;gets the value of address&amp;quot;&lt;br /&gt;
     address:anAddress     &amp;quot;sets anAddress to the value of anAddress&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In [http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk] the names of getter methods are usually the same as the name of the instance variable. A colon is added to the end of setter method name e.g. colour:&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Actionscript ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public var fullName:String;&lt;br /&gt;
private var _fullName:String;&lt;br /&gt;
&lt;br /&gt;
public function get fullName():String {&lt;br /&gt;
   return _fullName;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public function set fullName(_fullName:String):void {&lt;br /&gt;
   this._fullName = _fullName;&lt;br /&gt;
}&lt;br /&gt;
// getters&lt;br /&gt;
var1 = obj.fullName;&lt;br /&gt;
var2 = obj['fullName'];&lt;br /&gt;
// setters&lt;br /&gt;
obj.fullName = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
obj['fullName'] = &amp;quot;Yes&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getting or setting the property would call the getter and setter functions instead of accessing the property directly&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
==Getters and Setters from a different perspective==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
A fundamental precept of OO systems is that an object should not expose any of its implementation details. This way, you can change the implementation without changing the code that uses the object. It follows then that in OO systems you should avoid getter and setter functions since they mostly provide access to implementation details. For instance if you need change the return type of a gettr method from int to long to accommodate the big numbers you need to change all the invocations of that getter method. This negates the concept of [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html information hiding]. The same issue arises when you need to change the accessed field’s type. You also have to change the getter’s return type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Solution:	 &lt;br /&gt;
Maintainability is inversely proportionate to the amount of data that moves between objects. Thus, its best to minimize data movement as much as possible. The idea is to focus on what you will do rather than how you will do it. Don't ask for the information you need to do the work; ask the object that has the information to do the work for you. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
'''&lt;br /&gt;
Getters and setters provide a convenient method to access the instance variables. A lot of new languages have come up with the support for accessing getters and setters as instance variable reference which improves the readability of the code. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== References ==&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx Understanding properties in C#]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html why getters and setters are evil ]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set php5 OOPS tutorial]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://stefaanlippens.net/python_property_trick python-hiding attribute getters and setters behind standard attribute access]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 Object.defineProperty Function (JavaScript)]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Getters and Setters in Scala]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ ColdFusion 9 : Implicit/Generated CFC Methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.jamesward.com/2010/05/07/flex-and-java-differences-getters-setters/  Flex and Java Differences: Getters &amp;amp; Setters]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.touch-code-magazine.com/objective-c-properties/ Objective C properties]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Properties in Lua]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://docstore.mik.ua/orelly/perl4/porm/ch11_05.htm Creating getters and setters in perl ]&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=49095</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h hs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=49095"/>
		<updated>2011-09-17T22:25:47Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Java */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
== What are getters and setters ? ==&lt;br /&gt;
''' &lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide getter and setter methods to access/modify object data. When writing new classes, it's a good idea to pay attention to the issue of access control. Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. Because of this naming convention, accessor methods are more often referred to as getter methods. This is a good programming practice, since the data fields are not directly accessible outside the class. Thus 'Getters' and 'Setters' allow us to effectively protect your data. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and setters as method calls ==&lt;br /&gt;
'''&lt;br /&gt;
For each variable, a get method will return its value and a set method will set the value. Here are the advantages of using getter and setter as method calls: &lt;br /&gt;
* Encapsulate the data from accidental / inadvertent modification. The private member variable is not part of the public interface of your class; only the public getter and setter methods are, and you are free to change their implementations without changing the public interface of your class&lt;br /&gt;
* If we decide that some action should be taken every time you change/access the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. For Instance, we can keep track of how many times a variable is accessed. &lt;br /&gt;
* Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and getters as variable references(properties) ==&lt;br /&gt;
'''&lt;br /&gt;
Properties are a robust way to handle object’s data. Properties support accessing the instance variables the same way as calling an instance method. A property communicates the idea of &amp;quot;I will make a value available to you, or accept a value from you.&amp;quot; It's not an implementation concept, it's an interface concept. Different languages follow specific syntax for adding a property to a class. Following are the advantages properties: &lt;br /&gt;
* the code is much cleaner when accessing a property when compared to Java or C++ which uses 2 separate methods for each instance variable. They are very useful in GUI programming which necessitates using a lot of fields for UI elements&lt;br /&gt;
* With properties we have fine-grained access control. For instance we can define a property as abstract thereby forcing the derived class to define that property. &lt;br /&gt;
* The main advantage of using properties is that if the internal implementation of getting or setting the property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class. This allows the interface of the object to stay the same even if the underlying implementation of getting and setting the property changes. &lt;br /&gt;
&lt;br /&gt;
Realizing the importance of getters and setters, popular IDEs like Eclipse, Visual studio has a built in mechanism to add getter and setter for a field or to create a property (in C#) for a given field.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples Languages that use getters and setters as method calls: ==&lt;br /&gt;
'''&lt;br /&gt;
'''&lt;br /&gt;
===C++===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
  int x_value;&lt;br /&gt;
&lt;br /&gt;
  public:&lt;br /&gt;
  // Getter&lt;br /&gt;
  int getx_value()&lt;br /&gt;
  {&lt;br /&gt;
      return x;&lt;br /&gt;
  }&lt;br /&gt;
  // Setter&lt;br /&gt;
  void setx_value( int x )&lt;br /&gt;
  {&lt;br /&gt;
      x_value = x;&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
void main()&lt;br /&gt;
{ &lt;br /&gt;
    A a;&lt;br /&gt;
    a.setx_value(5);&lt;br /&gt;
    cout&amp;lt;&amp;lt;a.getx_value();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class BookStore&lt;br /&gt;
{ &lt;br /&gt;
  String title;&lt;br /&gt;
  public String getTitle()&lt;br /&gt;
  {&lt;br /&gt;
     return title;&lt;br /&gt;
  }&lt;br /&gt;
  // a setter method might check that the value that is being assigned to the variable is legal&lt;br /&gt;
  public void setTitle( String newTitle ) &lt;br /&gt;
  {&lt;br /&gt;
    if ( newTitle == null )   // Don't allow null strings as titles!&lt;br /&gt;
       title = &amp;quot;(Untitled)&amp;quot;;  // Use an appropriate default value instead.&lt;br /&gt;
    else&lt;br /&gt;
       title = newTitle;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
     BookStore obj;&lt;br /&gt;
     obj. setTitle(&amp;quot;&amp;quot;);&lt;br /&gt;
     System.out.println(obj.getTitle());&lt;br /&gt;
}&lt;br /&gt;
Output:&lt;br /&gt;
(Untitled)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub setName &lt;br /&gt;
{&lt;br /&gt;
   my ( $self, $Name ) = @_;&lt;br /&gt;
   $self-&amp;gt;{_Name} = $Name if defined($Name);&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
sub getName &lt;br /&gt;
{&lt;br /&gt;
   my( $self ) = @_;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
# Now Set first name using helper function.&lt;br /&gt;
$object-&amp;gt;setName( &amp;quot;ABC&amp;quot; );&lt;br /&gt;
# Get name which is set using constructor.&lt;br /&gt;
$Name = $object-&amp;gt;getName();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Perl does not have private variables but we can still use the concept of getter, setter functions methods.&lt;br /&gt;
'''&lt;br /&gt;
=== ColdFusion === &lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Component Person&lt;br /&gt;
{&lt;br /&gt;
   property name&lt;br /&gt;
   property age;&lt;br /&gt;
   property city;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;!--- Once an object is created we can directly call the setters and getters for the properties as ---&amp;gt;&lt;br /&gt;
&amp;lt;cfscript&amp;gt;&lt;br /&gt;
   person = new Person();&lt;br /&gt;
   person.setName(&amp;quot;Brad&amp;quot;);&lt;br /&gt;
   person.setAge(46);&lt;br /&gt;
&lt;br /&gt;
   writeOutput(&amp;quot;Name : #person.getName()#&amp;quot;);&lt;br /&gt;
   writeOutput(&amp;quot;Age : #person.getAge()#&amp;quot;); &lt;br /&gt;
&amp;lt;/cfscript&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want to override the getter and setter method, you just need to define those methods in your CFC and ColdFusion will call our method instead of calling the implicit one.The implicit methods can also do some nice validation if you have given the ‘type’ for properties. For instance, if we define a property as numeric and try to provide a try to set a string as its value It will throw a nice error saying “The value cannot be converted to a numeric”.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples from Languages that use getters and setters as instance variable references:  ==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== C#: ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;class MyClass&lt;br /&gt;
{&lt;br /&gt;
      private int x;&lt;br /&gt;
      public int X&lt;br /&gt;
      {&lt;br /&gt;
            get&lt;br /&gt;
           {&lt;br /&gt;
             return x;&lt;br /&gt;
           }&lt;br /&gt;
          set&lt;br /&gt;
          {&lt;br /&gt;
             x = value;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
//Invocation&lt;br /&gt;
MyClass mc = new MyClass();&lt;br /&gt;
mc.X = 10;                   // calls set accessor of the property X, and pass 10 as value of the standard field 'value'.&lt;br /&gt;
Console.WriteLine(mc.X);     // displays 10. Calls the get accessor of the property X.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
C# also supports static properties, which belongs to the class rather than to the objects of the class. The properties of a Base class can be inherited to a Derived class and can be overridden polymorphicaly. &lt;br /&gt;
'''&lt;br /&gt;
===Lua===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class 'Test'&lt;br /&gt;
  function  Test : getLength()&lt;br /&gt;
   return # self.value&lt;br /&gt;
  end&lt;br /&gt;
  function  Test : setLength(newLength)&lt;br /&gt;
    for  i = self.length, newLength do&lt;br /&gt;
        table.insert(self.value, false )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
test =  Test({1, 2, 3, 4})&lt;br /&gt;
print(test.length)&lt;br /&gt;
self.length = property( Test.getLength, Test.setLength )    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getter and Setter functions can be implemented in Lua, which is similar to the properties concept in C#. This allows the functions to bind to a property that can be assigned and accessed as a value.&lt;br /&gt;
'''&lt;br /&gt;
===Ruby===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
    def initialize(lname, fname)&lt;br /&gt;
        @lname = lname&lt;br /&gt;
        @fname = fname&lt;br /&gt;
    end&lt;br /&gt;
attr_reader :lname // creates a getter method&lt;br /&gt;
    attr_writer :lname    // creates a setter method&lt;br /&gt;
    attr_accessor :fname // creates both getter and setter method&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x = Person.new(&amp;quot;ABC&amp;quot;, &amp;quot;XYZ&amp;quot;)&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
x.fname = &amp;quot;PQR&amp;quot;&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ruby simplifies the creation of getters and setters with a little metaprogramming and the methods attr, attr_reader, attr_writer, and attr_accessor, all from the Module class. By supplying the attr method, Ruby provides a way to acces the instances directly.&lt;br /&gt;
'''&lt;br /&gt;
===Php===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
class Customer&lt;br /&gt;
{&lt;br /&gt;
   public $name;&lt;br /&gt;
   private $data = array();&lt;br /&gt;
   public function __set($dt, $vl) &lt;br /&gt;
   {&lt;br /&gt;
      $this-&amp;gt;data[$dt] = $vl;&lt;br /&gt;
   }&lt;br /&gt;
   public function __get($dt) &lt;br /&gt;
   {&lt;br /&gt;
      return $this-&amp;gt;data[$dt];&lt;br /&gt;
   }&lt;br /&gt;
} &lt;br /&gt;
$c = new Customer();&lt;br /&gt;
$c-&amp;gt;name = “Sunil”; // $name is set because its public&lt;br /&gt;
$c-&amp;gt;email = “email@domain.com”; //assigning email@domain.com to the $email variable.&lt;br /&gt;
echo $c-&amp;gt;email;&lt;br /&gt;
?&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
An interesting aspect of php worth noting is that we can assign values to undefined variables. Because of the above limitation, PHP engine provides two magic methods __get() and __set(). __get() is used when value from an undefined variable is to be read and __set() is used when a value is to be assigned to a undefined variable of a class.In the above example when email@domain.com is assigned to the undefined variable $email, the magic method __set() is called. To this __set() method the name of the variable is passed into $dt variable of __set() method and the value i.e. email@domain.com is passed to $vl variable of the __set() method.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Objective C===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// public header file&lt;br /&gt;
@interface MyObject : NSObject&lt;br /&gt;
{&lt;br /&gt;
  NSString *make; &lt;br /&gt;
  NSString* model;&lt;br /&gt;
  NSNumber* vin;&lt;br /&gt;
}&lt;br /&gt;
@property (readonly, copy) NSString *language;&lt;br /&gt;
@property(readwrite, retain) NSString* make;&lt;br /&gt;
@property(readwrite, retain) NSString* model;&lt;br /&gt;
@property(readwrite, retain) NSNumber* vin;&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
#import &amp;quot;SimpleCar.h&amp;quot;&lt;br /&gt;
@implementation SimpleCar&lt;br /&gt;
@synthesize make, model, vin;&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Objective C we can define a property using @property directive. @synthesize will create automatically for you a setter and a getter methods for the property which becomes accessible during the run time.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Python ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DoubleIt(object):&lt;br /&gt;
   def _get_value(self):&lt;br /&gt;
       return self._value * 2&lt;br /&gt;
   def _set_value(self, value):&lt;br /&gt;
       self._value = value&lt;br /&gt;
   value = property(_get_value, _set_value)&lt;br /&gt;
&lt;br /&gt;
# Invocation &lt;br /&gt;
x = DoubleIt()&lt;br /&gt;
 &lt;br /&gt;
x.value = 10&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = 'foo'&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = [1,2,3]&lt;br /&gt;
print x.value&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above [http://stefaanlippens.net/python_property_trick python] code, the output is doubled since the getter multiplies the value by 2&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Javascript ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function addDataProperty()&lt;br /&gt;
{&lt;br /&gt;
   var newLine = &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;;&lt;br /&gt;
   var obj = {};&lt;br /&gt;
  &lt;br /&gt;
   // Add a data property to the object.&lt;br /&gt;
   Object.defineProperty(obj, &amp;quot;newDataProperty&amp;quot;, &lt;br /&gt;
   {&lt;br /&gt;
       value: 101,&lt;br /&gt;
       writable: true,&lt;br /&gt;
       enumerable: true,&lt;br /&gt;
       configurable: true&lt;br /&gt;
   });&lt;br /&gt;
&lt;br /&gt;
   // Set the property value.&lt;br /&gt;
   obj.newDataProperty = 102;&lt;br /&gt;
   document.write(&amp;quot;Property value: &amp;quot; + obj.newDataProperty + newLine);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Javascript supports accessing getters and setters as variable as properties. Javascript originally used __defineGetter__ and __defineSetter__ syntax to define properties which is depricated as the language evolved. Object.defineProperty is currently used for creating a property. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Scala ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person() {&lt;br /&gt;
// Private age variable, renamed to _age&lt;br /&gt;
private var _age = 0&lt;br /&gt;
var name = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Getter&lt;br /&gt;
def age = _age&lt;br /&gt;
&lt;br /&gt;
// Setter&lt;br /&gt;
def age_= (value:Int):Unit = _age = value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// We can invoke the setter as follows : &lt;br /&gt;
 can invoke the setter using the following: &lt;br /&gt;
person.age = 99&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Scala has some unconventional ideas that provide a solid, well thought out, and an abbreviated syntax to access object properties. This getter code simply defines a method called “age” and returns the “_age” variable. Scala doesn’t require the return keyword. The setter method name is “age_=”. The underscore is a special character in Scala and in this case, allows for a space in the method name which essentially makes the name “age =”. The parentheses and contents dictate the value and type that needs to be passed in. The “:Unit” code is equivalent to returning void. The remaining code is setting the “_age” variable to “value”.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Smalltalk===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     name                           &amp;quot;gets the value of name&amp;quot;&lt;br /&gt;
     name:aName              &amp;quot;sets name to the value of aName&amp;quot;&lt;br /&gt;
&lt;br /&gt;
     address                        &amp;quot;gets the value of address&amp;quot;&lt;br /&gt;
     address:anAddress     &amp;quot;sets anAddress to the value of anAddress&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In [http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk] the names of getter methods are usually the same as the name of the instance variable. A colon is added to the end of setter method name e.g. colour:&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Actionscript ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public var fullName:String;&lt;br /&gt;
private var _fullName:String;&lt;br /&gt;
&lt;br /&gt;
public function get fullName():String {&lt;br /&gt;
   return _fullName;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public function set fullName(_fullName:String):void {&lt;br /&gt;
   this._fullName = _fullName;&lt;br /&gt;
}&lt;br /&gt;
// getters&lt;br /&gt;
var1 = obj.fullName;&lt;br /&gt;
var2 = obj['fullName'];&lt;br /&gt;
// setters&lt;br /&gt;
obj.fullName = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
obj['fullName'] = &amp;quot;Yes&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getting or setting the property would call the getter and setter functions instead of accessing the property directly&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
==Getters and Setters from a different perspective==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
A fundamental precept of OO systems is that an object should not expose any of its implementation details. This way, you can change the implementation without changing the code that uses the object. It follows then that in OO systems you should avoid getter and setter functions since they mostly provide access to implementation details. For instance if you need change the return type of a gettr method from int to long to accommodate the big numbers you need to change all the invocations of that getter method. This negates the concept of [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html information hiding]. The same issue arises when you need to change the accessed field’s type. You also have to change the getter’s return type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Solution:	 &lt;br /&gt;
Maintainability is inversely proportionate to the amount of data that moves between objects. Thus, its best to minimize data movement as much as possible. The idea is to focus on what you will do rather than how you will do it. Don't ask for the information you need to do the work; ask the object that has the information to do the work for you. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
'''&lt;br /&gt;
Getters and setters provide a convenient method to access the instance variables. A lot of new languages have come up with the support for accessing getters and setters as instance variable reference which improves the readability of the code. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== References ==&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx Understanding properties in C#]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html why getters and setters are evil ]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set php5 OOPS tutorial]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://stefaanlippens.net/python_property_trick python-hiding attribute getters and setters behind standard attribute access]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 Object.defineProperty Function (JavaScript)]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Getters and Setters in Scala]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ ColdFusion 9 : Implicit/Generated CFC Methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.jamesward.com/2010/05/07/flex-and-java-differences-getters-setters/  Flex and Java Differences: Getters &amp;amp; Setters]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.touch-code-magazine.com/objective-c-properties/ Objective C properties]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Properties in Lua]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://docstore.mik.ua/orelly/perl4/porm/ch11_05.htm Creating getters and setters in perl ]&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=49094</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h hs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=49094"/>
		<updated>2011-09-17T22:24:21Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* C++ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
== What are getters and setters ? ==&lt;br /&gt;
''' &lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide getter and setter methods to access/modify object data. When writing new classes, it's a good idea to pay attention to the issue of access control. Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. Because of this naming convention, accessor methods are more often referred to as getter methods. This is a good programming practice, since the data fields are not directly accessible outside the class. Thus 'Getters' and 'Setters' allow us to effectively protect your data. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and setters as method calls ==&lt;br /&gt;
'''&lt;br /&gt;
For each variable, a get method will return its value and a set method will set the value. Here are the advantages of using getter and setter as method calls: &lt;br /&gt;
* Encapsulate the data from accidental / inadvertent modification. The private member variable is not part of the public interface of your class; only the public getter and setter methods are, and you are free to change their implementations without changing the public interface of your class&lt;br /&gt;
* If we decide that some action should be taken every time you change/access the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. For Instance, we can keep track of how many times a variable is accessed. &lt;br /&gt;
* Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and getters as variable references(properties) ==&lt;br /&gt;
'''&lt;br /&gt;
Properties are a robust way to handle object’s data. Properties support accessing the instance variables the same way as calling an instance method. A property communicates the idea of &amp;quot;I will make a value available to you, or accept a value from you.&amp;quot; It's not an implementation concept, it's an interface concept. Different languages follow specific syntax for adding a property to a class. Following are the advantages properties: &lt;br /&gt;
* the code is much cleaner when accessing a property when compared to Java or C++ which uses 2 separate methods for each instance variable. They are very useful in GUI programming which necessitates using a lot of fields for UI elements&lt;br /&gt;
* With properties we have fine-grained access control. For instance we can define a property as abstract thereby forcing the derived class to define that property. &lt;br /&gt;
* The main advantage of using properties is that if the internal implementation of getting or setting the property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class. This allows the interface of the object to stay the same even if the underlying implementation of getting and setting the property changes. &lt;br /&gt;
&lt;br /&gt;
Realizing the importance of getters and setters, popular IDEs like Eclipse, Visual studio has a built in mechanism to add getter and setter for a field or to create a property (in C#) for a given field.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples Languages that use getters and setters as method calls: ==&lt;br /&gt;
'''&lt;br /&gt;
'''&lt;br /&gt;
===C++===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
  int x_value;&lt;br /&gt;
&lt;br /&gt;
  public:&lt;br /&gt;
  // Getter&lt;br /&gt;
  int getx_value()&lt;br /&gt;
  {&lt;br /&gt;
      return x;&lt;br /&gt;
  }&lt;br /&gt;
  // Setter&lt;br /&gt;
  void setx_value( int x )&lt;br /&gt;
  {&lt;br /&gt;
      x_value = x;&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
void main()&lt;br /&gt;
{ &lt;br /&gt;
    A a;&lt;br /&gt;
    a.setx_value(5);&lt;br /&gt;
    cout&amp;lt;&amp;lt;a.getx_value();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class BookStore&lt;br /&gt;
{ &lt;br /&gt;
  String title;&lt;br /&gt;
public String getTitle()&lt;br /&gt;
{&lt;br /&gt;
   return title;&lt;br /&gt;
}&lt;br /&gt;
// a setter method might check that the value that is being assigned to the variable is legal:&lt;br /&gt;
public void setTitle( String newTitle ) &lt;br /&gt;
{&lt;br /&gt;
  if ( newTitle == null )   // Don't allow null strings as titles!&lt;br /&gt;
     title = &amp;quot;(Untitled)&amp;quot;;  // Use an appropriate default value instead.&lt;br /&gt;
  else&lt;br /&gt;
     title = newTitle;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
     BookStore obj;&lt;br /&gt;
     obj. setTitle(&amp;quot;&amp;quot;);&lt;br /&gt;
     System.out.println(obj.getTitle());&lt;br /&gt;
}&lt;br /&gt;
Output:&lt;br /&gt;
(Untitled)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub setName &lt;br /&gt;
{&lt;br /&gt;
   my ( $self, $Name ) = @_;&lt;br /&gt;
   $self-&amp;gt;{_Name} = $Name if defined($Name);&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
sub getName &lt;br /&gt;
{&lt;br /&gt;
   my( $self ) = @_;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
# Now Set first name using helper function.&lt;br /&gt;
$object-&amp;gt;setName( &amp;quot;ABC&amp;quot; );&lt;br /&gt;
# Get name which is set using constructor.&lt;br /&gt;
$Name = $object-&amp;gt;getName();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Perl does not have private variables but we can still use the concept of getter, setter functions methods.&lt;br /&gt;
'''&lt;br /&gt;
=== ColdFusion === &lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Component Person&lt;br /&gt;
{&lt;br /&gt;
   property name&lt;br /&gt;
   property age;&lt;br /&gt;
   property city;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;!--- Once an object is created we can directly call the setters and getters for the properties as ---&amp;gt;&lt;br /&gt;
&amp;lt;cfscript&amp;gt;&lt;br /&gt;
   person = new Person();&lt;br /&gt;
   person.setName(&amp;quot;Brad&amp;quot;);&lt;br /&gt;
   person.setAge(46);&lt;br /&gt;
&lt;br /&gt;
   writeOutput(&amp;quot;Name : #person.getName()#&amp;quot;);&lt;br /&gt;
   writeOutput(&amp;quot;Age : #person.getAge()#&amp;quot;); &lt;br /&gt;
&amp;lt;/cfscript&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want to override the getter and setter method, you just need to define those methods in your CFC and ColdFusion will call our method instead of calling the implicit one.The implicit methods can also do some nice validation if you have given the ‘type’ for properties. For instance, if we define a property as numeric and try to provide a try to set a string as its value It will throw a nice error saying “The value cannot be converted to a numeric”.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples from Languages that use getters and setters as instance variable references:  ==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== C#: ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;class MyClass&lt;br /&gt;
{&lt;br /&gt;
      private int x;&lt;br /&gt;
      public int X&lt;br /&gt;
      {&lt;br /&gt;
            get&lt;br /&gt;
           {&lt;br /&gt;
             return x;&lt;br /&gt;
           }&lt;br /&gt;
          set&lt;br /&gt;
          {&lt;br /&gt;
             x = value;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
//Invocation&lt;br /&gt;
MyClass mc = new MyClass();&lt;br /&gt;
mc.X = 10;                   // calls set accessor of the property X, and pass 10 as value of the standard field 'value'.&lt;br /&gt;
Console.WriteLine(mc.X);     // displays 10. Calls the get accessor of the property X.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
C# also supports static properties, which belongs to the class rather than to the objects of the class. The properties of a Base class can be inherited to a Derived class and can be overridden polymorphicaly. &lt;br /&gt;
'''&lt;br /&gt;
===Lua===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class 'Test'&lt;br /&gt;
  function  Test : getLength()&lt;br /&gt;
   return # self.value&lt;br /&gt;
  end&lt;br /&gt;
  function  Test : setLength(newLength)&lt;br /&gt;
    for  i = self.length, newLength do&lt;br /&gt;
        table.insert(self.value, false )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
test =  Test({1, 2, 3, 4})&lt;br /&gt;
print(test.length)&lt;br /&gt;
self.length = property( Test.getLength, Test.setLength )    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getter and Setter functions can be implemented in Lua, which is similar to the properties concept in C#. This allows the functions to bind to a property that can be assigned and accessed as a value.&lt;br /&gt;
'''&lt;br /&gt;
===Ruby===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
    def initialize(lname, fname)&lt;br /&gt;
        @lname = lname&lt;br /&gt;
        @fname = fname&lt;br /&gt;
    end&lt;br /&gt;
attr_reader :lname // creates a getter method&lt;br /&gt;
    attr_writer :lname    // creates a setter method&lt;br /&gt;
    attr_accessor :fname // creates both getter and setter method&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x = Person.new(&amp;quot;ABC&amp;quot;, &amp;quot;XYZ&amp;quot;)&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
x.fname = &amp;quot;PQR&amp;quot;&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ruby simplifies the creation of getters and setters with a little metaprogramming and the methods attr, attr_reader, attr_writer, and attr_accessor, all from the Module class. By supplying the attr method, Ruby provides a way to acces the instances directly.&lt;br /&gt;
'''&lt;br /&gt;
===Php===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
class Customer&lt;br /&gt;
{&lt;br /&gt;
   public $name;&lt;br /&gt;
   private $data = array();&lt;br /&gt;
   public function __set($dt, $vl) &lt;br /&gt;
   {&lt;br /&gt;
      $this-&amp;gt;data[$dt] = $vl;&lt;br /&gt;
   }&lt;br /&gt;
   public function __get($dt) &lt;br /&gt;
   {&lt;br /&gt;
      return $this-&amp;gt;data[$dt];&lt;br /&gt;
   }&lt;br /&gt;
} &lt;br /&gt;
$c = new Customer();&lt;br /&gt;
$c-&amp;gt;name = “Sunil”; // $name is set because its public&lt;br /&gt;
$c-&amp;gt;email = “email@domain.com”; //assigning email@domain.com to the $email variable.&lt;br /&gt;
echo $c-&amp;gt;email;&lt;br /&gt;
?&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
An interesting aspect of php worth noting is that we can assign values to undefined variables. Because of the above limitation, PHP engine provides two magic methods __get() and __set(). __get() is used when value from an undefined variable is to be read and __set() is used when a value is to be assigned to a undefined variable of a class.In the above example when email@domain.com is assigned to the undefined variable $email, the magic method __set() is called. To this __set() method the name of the variable is passed into $dt variable of __set() method and the value i.e. email@domain.com is passed to $vl variable of the __set() method.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Objective C===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// public header file&lt;br /&gt;
@interface MyObject : NSObject&lt;br /&gt;
{&lt;br /&gt;
  NSString *make; &lt;br /&gt;
  NSString* model;&lt;br /&gt;
  NSNumber* vin;&lt;br /&gt;
}&lt;br /&gt;
@property (readonly, copy) NSString *language;&lt;br /&gt;
@property(readwrite, retain) NSString* make;&lt;br /&gt;
@property(readwrite, retain) NSString* model;&lt;br /&gt;
@property(readwrite, retain) NSNumber* vin;&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
#import &amp;quot;SimpleCar.h&amp;quot;&lt;br /&gt;
@implementation SimpleCar&lt;br /&gt;
@synthesize make, model, vin;&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Objective C we can define a property using @property directive. @synthesize will create automatically for you a setter and a getter methods for the property which becomes accessible during the run time.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Python ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DoubleIt(object):&lt;br /&gt;
   def _get_value(self):&lt;br /&gt;
       return self._value * 2&lt;br /&gt;
   def _set_value(self, value):&lt;br /&gt;
       self._value = value&lt;br /&gt;
   value = property(_get_value, _set_value)&lt;br /&gt;
&lt;br /&gt;
# Invocation &lt;br /&gt;
x = DoubleIt()&lt;br /&gt;
 &lt;br /&gt;
x.value = 10&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = 'foo'&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = [1,2,3]&lt;br /&gt;
print x.value&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above [http://stefaanlippens.net/python_property_trick python] code, the output is doubled since the getter multiplies the value by 2&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Javascript ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function addDataProperty()&lt;br /&gt;
{&lt;br /&gt;
   var newLine = &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;;&lt;br /&gt;
   var obj = {};&lt;br /&gt;
  &lt;br /&gt;
   // Add a data property to the object.&lt;br /&gt;
   Object.defineProperty(obj, &amp;quot;newDataProperty&amp;quot;, &lt;br /&gt;
   {&lt;br /&gt;
       value: 101,&lt;br /&gt;
       writable: true,&lt;br /&gt;
       enumerable: true,&lt;br /&gt;
       configurable: true&lt;br /&gt;
   });&lt;br /&gt;
&lt;br /&gt;
   // Set the property value.&lt;br /&gt;
   obj.newDataProperty = 102;&lt;br /&gt;
   document.write(&amp;quot;Property value: &amp;quot; + obj.newDataProperty + newLine);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Javascript supports accessing getters and setters as variable as properties. Javascript originally used __defineGetter__ and __defineSetter__ syntax to define properties which is depricated as the language evolved. Object.defineProperty is currently used for creating a property. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Scala ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person() {&lt;br /&gt;
// Private age variable, renamed to _age&lt;br /&gt;
private var _age = 0&lt;br /&gt;
var name = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Getter&lt;br /&gt;
def age = _age&lt;br /&gt;
&lt;br /&gt;
// Setter&lt;br /&gt;
def age_= (value:Int):Unit = _age = value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// We can invoke the setter as follows : &lt;br /&gt;
 can invoke the setter using the following: &lt;br /&gt;
person.age = 99&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Scala has some unconventional ideas that provide a solid, well thought out, and an abbreviated syntax to access object properties. This getter code simply defines a method called “age” and returns the “_age” variable. Scala doesn’t require the return keyword. The setter method name is “age_=”. The underscore is a special character in Scala and in this case, allows for a space in the method name which essentially makes the name “age =”. The parentheses and contents dictate the value and type that needs to be passed in. The “:Unit” code is equivalent to returning void. The remaining code is setting the “_age” variable to “value”.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Smalltalk===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     name                           &amp;quot;gets the value of name&amp;quot;&lt;br /&gt;
     name:aName              &amp;quot;sets name to the value of aName&amp;quot;&lt;br /&gt;
&lt;br /&gt;
     address                        &amp;quot;gets the value of address&amp;quot;&lt;br /&gt;
     address:anAddress     &amp;quot;sets anAddress to the value of anAddress&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In [http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk] the names of getter methods are usually the same as the name of the instance variable. A colon is added to the end of setter method name e.g. colour:&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Actionscript ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public var fullName:String;&lt;br /&gt;
private var _fullName:String;&lt;br /&gt;
&lt;br /&gt;
public function get fullName():String {&lt;br /&gt;
   return _fullName;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public function set fullName(_fullName:String):void {&lt;br /&gt;
   this._fullName = _fullName;&lt;br /&gt;
}&lt;br /&gt;
// getters&lt;br /&gt;
var1 = obj.fullName;&lt;br /&gt;
var2 = obj['fullName'];&lt;br /&gt;
// setters&lt;br /&gt;
obj.fullName = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
obj['fullName'] = &amp;quot;Yes&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getting or setting the property would call the getter and setter functions instead of accessing the property directly&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
==Getters and Setters from a different perspective==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
A fundamental precept of OO systems is that an object should not expose any of its implementation details. This way, you can change the implementation without changing the code that uses the object. It follows then that in OO systems you should avoid getter and setter functions since they mostly provide access to implementation details. For instance if you need change the return type of a gettr method from int to long to accommodate the big numbers you need to change all the invocations of that getter method. This negates the concept of [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html information hiding]. The same issue arises when you need to change the accessed field’s type. You also have to change the getter’s return type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Solution:	 &lt;br /&gt;
Maintainability is inversely proportionate to the amount of data that moves between objects. Thus, its best to minimize data movement as much as possible. The idea is to focus on what you will do rather than how you will do it. Don't ask for the information you need to do the work; ask the object that has the information to do the work for you. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
'''&lt;br /&gt;
Getters and setters provide a convenient method to access the instance variables. A lot of new languages have come up with the support for accessing getters and setters as instance variable reference which improves the readability of the code. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== References ==&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx Understanding properties in C#]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html why getters and setters are evil ]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set php5 OOPS tutorial]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://stefaanlippens.net/python_property_trick python-hiding attribute getters and setters behind standard attribute access]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 Object.defineProperty Function (JavaScript)]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Getters and Setters in Scala]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ ColdFusion 9 : Implicit/Generated CFC Methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.jamesward.com/2010/05/07/flex-and-java-differences-getters-setters/  Flex and Java Differences: Getters &amp;amp; Setters]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.touch-code-magazine.com/objective-c-properties/ Objective C properties]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Properties in Lua]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://docstore.mik.ua/orelly/perl4/porm/ch11_05.htm Creating getters and setters in perl ]&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=49093</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h hs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=49093"/>
		<updated>2011-09-17T22:22:28Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* C++ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
== What are getters and setters ? ==&lt;br /&gt;
''' &lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide getter and setter methods to access/modify object data. When writing new classes, it's a good idea to pay attention to the issue of access control. Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. Because of this naming convention, accessor methods are more often referred to as getter methods. This is a good programming practice, since the data fields are not directly accessible outside the class. Thus 'Getters' and 'Setters' allow us to effectively protect your data. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and setters as method calls ==&lt;br /&gt;
'''&lt;br /&gt;
For each variable, a get method will return its value and a set method will set the value. Here are the advantages of using getter and setter as method calls: &lt;br /&gt;
* Encapsulate the data from accidental / inadvertent modification. The private member variable is not part of the public interface of your class; only the public getter and setter methods are, and you are free to change their implementations without changing the public interface of your class&lt;br /&gt;
* If we decide that some action should be taken every time you change/access the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. For Instance, we can keep track of how many times a variable is accessed. &lt;br /&gt;
* Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and getters as variable references(properties) ==&lt;br /&gt;
'''&lt;br /&gt;
Properties are a robust way to handle object’s data. Properties support accessing the instance variables the same way as calling an instance method. A property communicates the idea of &amp;quot;I will make a value available to you, or accept a value from you.&amp;quot; It's not an implementation concept, it's an interface concept. Different languages follow specific syntax for adding a property to a class. Following are the advantages properties: &lt;br /&gt;
* the code is much cleaner when accessing a property when compared to Java or C++ which uses 2 separate methods for each instance variable. They are very useful in GUI programming which necessitates using a lot of fields for UI elements&lt;br /&gt;
* With properties we have fine-grained access control. For instance we can define a property as abstract thereby forcing the derived class to define that property. &lt;br /&gt;
* The main advantage of using properties is that if the internal implementation of getting or setting the property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class. This allows the interface of the object to stay the same even if the underlying implementation of getting and setting the property changes. &lt;br /&gt;
&lt;br /&gt;
Realizing the importance of getters and setters, popular IDEs like Eclipse, Visual studio has a built in mechanism to add getter and setter for a field or to create a property (in C#) for a given field.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples Languages that use getters and setters as method calls: ==&lt;br /&gt;
'''&lt;br /&gt;
'''&lt;br /&gt;
===C++===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
  int x_value;&lt;br /&gt;
&lt;br /&gt;
  public:&lt;br /&gt;
  // Getters&lt;br /&gt;
  int getx_value()&lt;br /&gt;
  {&lt;br /&gt;
      return x;&lt;br /&gt;
  }&lt;br /&gt;
  // Setters&lt;br /&gt;
  void setx_value( int x )&lt;br /&gt;
  {&lt;br /&gt;
      x_value = x;&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
void main()&lt;br /&gt;
{ &lt;br /&gt;
    A a;&lt;br /&gt;
    a.setx_value(5);&lt;br /&gt;
    cout&amp;lt;&amp;lt;a.getx_value();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class BookStore&lt;br /&gt;
{ &lt;br /&gt;
  String title;&lt;br /&gt;
public String getTitle()&lt;br /&gt;
{&lt;br /&gt;
   return title;&lt;br /&gt;
}&lt;br /&gt;
// a setter method might check that the value that is being assigned to the variable is legal:&lt;br /&gt;
public void setTitle( String newTitle ) &lt;br /&gt;
{&lt;br /&gt;
  if ( newTitle == null )   // Don't allow null strings as titles!&lt;br /&gt;
     title = &amp;quot;(Untitled)&amp;quot;;  // Use an appropriate default value instead.&lt;br /&gt;
  else&lt;br /&gt;
     title = newTitle;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
     BookStore obj;&lt;br /&gt;
     obj. setTitle(&amp;quot;&amp;quot;);&lt;br /&gt;
     System.out.println(obj.getTitle());&lt;br /&gt;
}&lt;br /&gt;
Output:&lt;br /&gt;
(Untitled)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub setName &lt;br /&gt;
{&lt;br /&gt;
   my ( $self, $Name ) = @_;&lt;br /&gt;
   $self-&amp;gt;{_Name} = $Name if defined($Name);&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
sub getName &lt;br /&gt;
{&lt;br /&gt;
   my( $self ) = @_;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
# Now Set first name using helper function.&lt;br /&gt;
$object-&amp;gt;setName( &amp;quot;ABC&amp;quot; );&lt;br /&gt;
# Get name which is set using constructor.&lt;br /&gt;
$Name = $object-&amp;gt;getName();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Perl does not have private variables but we can still use the concept of getter, setter functions methods.&lt;br /&gt;
'''&lt;br /&gt;
=== ColdFusion === &lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Component Person&lt;br /&gt;
{&lt;br /&gt;
   property name&lt;br /&gt;
   property age;&lt;br /&gt;
   property city;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;!--- Once an object is created we can directly call the setters and getters for the properties as ---&amp;gt;&lt;br /&gt;
&amp;lt;cfscript&amp;gt;&lt;br /&gt;
   person = new Person();&lt;br /&gt;
   person.setName(&amp;quot;Brad&amp;quot;);&lt;br /&gt;
   person.setAge(46);&lt;br /&gt;
&lt;br /&gt;
   writeOutput(&amp;quot;Name : #person.getName()#&amp;quot;);&lt;br /&gt;
   writeOutput(&amp;quot;Age : #person.getAge()#&amp;quot;); &lt;br /&gt;
&amp;lt;/cfscript&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want to override the getter and setter method, you just need to define those methods in your CFC and ColdFusion will call our method instead of calling the implicit one.The implicit methods can also do some nice validation if you have given the ‘type’ for properties. For instance, if we define a property as numeric and try to provide a try to set a string as its value It will throw a nice error saying “The value cannot be converted to a numeric”.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples from Languages that use getters and setters as instance variable references:  ==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== C#: ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;class MyClass&lt;br /&gt;
{&lt;br /&gt;
      private int x;&lt;br /&gt;
      public int X&lt;br /&gt;
      {&lt;br /&gt;
            get&lt;br /&gt;
           {&lt;br /&gt;
             return x;&lt;br /&gt;
           }&lt;br /&gt;
          set&lt;br /&gt;
          {&lt;br /&gt;
             x = value;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
//Invocation&lt;br /&gt;
MyClass mc = new MyClass();&lt;br /&gt;
mc.X = 10;                   // calls set accessor of the property X, and pass 10 as value of the standard field 'value'.&lt;br /&gt;
Console.WriteLine(mc.X);     // displays 10. Calls the get accessor of the property X.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
C# also supports static properties, which belongs to the class rather than to the objects of the class. The properties of a Base class can be inherited to a Derived class and can be overridden polymorphicaly. &lt;br /&gt;
'''&lt;br /&gt;
===Lua===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class 'Test'&lt;br /&gt;
  function  Test : getLength()&lt;br /&gt;
   return # self.value&lt;br /&gt;
  end&lt;br /&gt;
  function  Test : setLength(newLength)&lt;br /&gt;
    for  i = self.length, newLength do&lt;br /&gt;
        table.insert(self.value, false )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
test =  Test({1, 2, 3, 4})&lt;br /&gt;
print(test.length)&lt;br /&gt;
self.length = property( Test.getLength, Test.setLength )    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getter and Setter functions can be implemented in Lua, which is similar to the properties concept in C#. This allows the functions to bind to a property that can be assigned and accessed as a value.&lt;br /&gt;
'''&lt;br /&gt;
===Ruby===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
    def initialize(lname, fname)&lt;br /&gt;
        @lname = lname&lt;br /&gt;
        @fname = fname&lt;br /&gt;
    end&lt;br /&gt;
attr_reader :lname // creates a getter method&lt;br /&gt;
    attr_writer :lname    // creates a setter method&lt;br /&gt;
    attr_accessor :fname // creates both getter and setter method&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x = Person.new(&amp;quot;ABC&amp;quot;, &amp;quot;XYZ&amp;quot;)&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
x.fname = &amp;quot;PQR&amp;quot;&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ruby simplifies the creation of getters and setters with a little metaprogramming and the methods attr, attr_reader, attr_writer, and attr_accessor, all from the Module class. By supplying the attr method, Ruby provides a way to acces the instances directly.&lt;br /&gt;
'''&lt;br /&gt;
===Php===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
class Customer&lt;br /&gt;
{&lt;br /&gt;
   public $name;&lt;br /&gt;
   private $data = array();&lt;br /&gt;
   public function __set($dt, $vl) &lt;br /&gt;
   {&lt;br /&gt;
      $this-&amp;gt;data[$dt] = $vl;&lt;br /&gt;
   }&lt;br /&gt;
   public function __get($dt) &lt;br /&gt;
   {&lt;br /&gt;
      return $this-&amp;gt;data[$dt];&lt;br /&gt;
   }&lt;br /&gt;
} &lt;br /&gt;
$c = new Customer();&lt;br /&gt;
$c-&amp;gt;name = “Sunil”; // $name is set because its public&lt;br /&gt;
$c-&amp;gt;email = “email@domain.com”; //assigning email@domain.com to the $email variable.&lt;br /&gt;
echo $c-&amp;gt;email;&lt;br /&gt;
?&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
An interesting aspect of php worth noting is that we can assign values to undefined variables. Because of the above limitation, PHP engine provides two magic methods __get() and __set(). __get() is used when value from an undefined variable is to be read and __set() is used when a value is to be assigned to a undefined variable of a class.In the above example when email@domain.com is assigned to the undefined variable $email, the magic method __set() is called. To this __set() method the name of the variable is passed into $dt variable of __set() method and the value i.e. email@domain.com is passed to $vl variable of the __set() method.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Objective C===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// public header file&lt;br /&gt;
@interface MyObject : NSObject&lt;br /&gt;
{&lt;br /&gt;
  NSString *make; &lt;br /&gt;
  NSString* model;&lt;br /&gt;
  NSNumber* vin;&lt;br /&gt;
}&lt;br /&gt;
@property (readonly, copy) NSString *language;&lt;br /&gt;
@property(readwrite, retain) NSString* make;&lt;br /&gt;
@property(readwrite, retain) NSString* model;&lt;br /&gt;
@property(readwrite, retain) NSNumber* vin;&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
#import &amp;quot;SimpleCar.h&amp;quot;&lt;br /&gt;
@implementation SimpleCar&lt;br /&gt;
@synthesize make, model, vin;&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Objective C we can define a property using @property directive. @synthesize will create automatically for you a setter and a getter methods for the property which becomes accessible during the run time.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Python ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DoubleIt(object):&lt;br /&gt;
   def _get_value(self):&lt;br /&gt;
       return self._value * 2&lt;br /&gt;
   def _set_value(self, value):&lt;br /&gt;
       self._value = value&lt;br /&gt;
   value = property(_get_value, _set_value)&lt;br /&gt;
&lt;br /&gt;
# Invocation &lt;br /&gt;
x = DoubleIt()&lt;br /&gt;
 &lt;br /&gt;
x.value = 10&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = 'foo'&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = [1,2,3]&lt;br /&gt;
print x.value&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above [http://stefaanlippens.net/python_property_trick python] code, the output is doubled since the getter multiplies the value by 2&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Javascript ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function addDataProperty()&lt;br /&gt;
{&lt;br /&gt;
   var newLine = &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;;&lt;br /&gt;
   var obj = {};&lt;br /&gt;
  &lt;br /&gt;
   // Add a data property to the object.&lt;br /&gt;
   Object.defineProperty(obj, &amp;quot;newDataProperty&amp;quot;, &lt;br /&gt;
   {&lt;br /&gt;
       value: 101,&lt;br /&gt;
       writable: true,&lt;br /&gt;
       enumerable: true,&lt;br /&gt;
       configurable: true&lt;br /&gt;
   });&lt;br /&gt;
&lt;br /&gt;
   // Set the property value.&lt;br /&gt;
   obj.newDataProperty = 102;&lt;br /&gt;
   document.write(&amp;quot;Property value: &amp;quot; + obj.newDataProperty + newLine);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Javascript supports accessing getters and setters as variable as properties. Javascript originally used __defineGetter__ and __defineSetter__ syntax to define properties which is depricated as the language evolved. Object.defineProperty is currently used for creating a property. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Scala ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person() {&lt;br /&gt;
// Private age variable, renamed to _age&lt;br /&gt;
private var _age = 0&lt;br /&gt;
var name = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Getter&lt;br /&gt;
def age = _age&lt;br /&gt;
&lt;br /&gt;
// Setter&lt;br /&gt;
def age_= (value:Int):Unit = _age = value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// We can invoke the setter as follows : &lt;br /&gt;
 can invoke the setter using the following: &lt;br /&gt;
person.age = 99&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Scala has some unconventional ideas that provide a solid, well thought out, and an abbreviated syntax to access object properties. This getter code simply defines a method called “age” and returns the “_age” variable. Scala doesn’t require the return keyword. The setter method name is “age_=”. The underscore is a special character in Scala and in this case, allows for a space in the method name which essentially makes the name “age =”. The parentheses and contents dictate the value and type that needs to be passed in. The “:Unit” code is equivalent to returning void. The remaining code is setting the “_age” variable to “value”.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Smalltalk===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     name                           &amp;quot;gets the value of name&amp;quot;&lt;br /&gt;
     name:aName              &amp;quot;sets name to the value of aName&amp;quot;&lt;br /&gt;
&lt;br /&gt;
     address                        &amp;quot;gets the value of address&amp;quot;&lt;br /&gt;
     address:anAddress     &amp;quot;sets anAddress to the value of anAddress&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In [http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk] the names of getter methods are usually the same as the name of the instance variable. A colon is added to the end of setter method name e.g. colour:&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Actionscript ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public var fullName:String;&lt;br /&gt;
private var _fullName:String;&lt;br /&gt;
&lt;br /&gt;
public function get fullName():String {&lt;br /&gt;
   return _fullName;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public function set fullName(_fullName:String):void {&lt;br /&gt;
   this._fullName = _fullName;&lt;br /&gt;
}&lt;br /&gt;
// getters&lt;br /&gt;
var1 = obj.fullName;&lt;br /&gt;
var2 = obj['fullName'];&lt;br /&gt;
// setters&lt;br /&gt;
obj.fullName = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
obj['fullName'] = &amp;quot;Yes&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getting or setting the property would call the getter and setter functions instead of accessing the property directly&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
==Getters and Setters from a different perspective==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
A fundamental precept of OO systems is that an object should not expose any of its implementation details. This way, you can change the implementation without changing the code that uses the object. It follows then that in OO systems you should avoid getter and setter functions since they mostly provide access to implementation details. For instance if you need change the return type of a gettr method from int to long to accommodate the big numbers you need to change all the invocations of that getter method. This negates the concept of [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html information hiding]. The same issue arises when you need to change the accessed field’s type. You also have to change the getter’s return type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Solution:	 &lt;br /&gt;
Maintainability is inversely proportionate to the amount of data that moves between objects. Thus, its best to minimize data movement as much as possible. The idea is to focus on what you will do rather than how you will do it. Don't ask for the information you need to do the work; ask the object that has the information to do the work for you. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
'''&lt;br /&gt;
Getters and setters provide a convenient method to access the instance variables. A lot of new languages have come up with the support for accessing getters and setters as instance variable reference which improves the readability of the code. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== References ==&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx Understanding properties in C#]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html why getters and setters are evil ]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set php5 OOPS tutorial]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://stefaanlippens.net/python_property_trick python-hiding attribute getters and setters behind standard attribute access]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 Object.defineProperty Function (JavaScript)]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Getters and Setters in Scala]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ ColdFusion 9 : Implicit/Generated CFC Methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.jamesward.com/2010/05/07/flex-and-java-differences-getters-setters/  Flex and Java Differences: Getters &amp;amp; Setters]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.touch-code-magazine.com/objective-c-properties/ Objective C properties]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Properties in Lua]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://docstore.mik.ua/orelly/perl4/porm/ch11_05.htm Creating getters and setters in perl ]&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=49088</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h hs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=49088"/>
		<updated>2011-09-17T22:20:02Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* C++ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
== What are getters and setters ? ==&lt;br /&gt;
''' &lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide getter and setter methods to access/modify object data. When writing new classes, it's a good idea to pay attention to the issue of access control. Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. Because of this naming convention, accessor methods are more often referred to as getter methods. This is a good programming practice, since the data fields are not directly accessible outside the class. Thus 'Getters' and 'Setters' allow us to effectively protect your data. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and setters as method calls ==&lt;br /&gt;
'''&lt;br /&gt;
For each variable, a get method will return its value and a set method will set the value. Here are the advantages of using getter and setter as method calls: &lt;br /&gt;
* Encapsulate the data from accidental / inadvertent modification. The private member variable is not part of the public interface of your class; only the public getter and setter methods are, and you are free to change their implementations without changing the public interface of your class&lt;br /&gt;
* If we decide that some action should be taken every time you change/access the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. For Instance, we can keep track of how many times a variable is accessed. &lt;br /&gt;
* Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and getters as variable references(properties) ==&lt;br /&gt;
'''&lt;br /&gt;
Properties are a robust way to handle object’s data. Properties support accessing the instance variables the same way as calling an instance method. A property communicates the idea of &amp;quot;I will make a value available to you, or accept a value from you.&amp;quot; It's not an implementation concept, it's an interface concept. Different languages follow specific syntax for adding a property to a class. Following are the advantages properties: &lt;br /&gt;
* the code is much cleaner when accessing a property when compared to Java or C++ which uses 2 separate methods for each instance variable. They are very useful in GUI programming which necessitates using a lot of fields for UI elements&lt;br /&gt;
* With properties we have fine-grained access control. For instance we can define a property as abstract thereby forcing the derived class to define that property. &lt;br /&gt;
* The main advantage of using properties is that if the internal implementation of getting or setting the property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class. This allows the interface of the object to stay the same even if the underlying implementation of getting and setting the property changes. &lt;br /&gt;
&lt;br /&gt;
Realizing the importance of getters and setters, popular IDEs like Eclipse, Visual studio has a built in mechanism to add getter and setter for a field or to create a property (in C#) for a given field.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples Languages that use getters and setters as method calls: ==&lt;br /&gt;
'''&lt;br /&gt;
'''&lt;br /&gt;
===C++===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
  int x_value;&lt;br /&gt;
&lt;br /&gt;
  public:&lt;br /&gt;
  // Getters&lt;br /&gt;
  int getx_value()&lt;br /&gt;
  {&lt;br /&gt;
      return x;&lt;br /&gt;
  }&lt;br /&gt;
  // Setters&lt;br /&gt;
  void setx_value( int x )&lt;br /&gt;
  {&lt;br /&gt;
      x_value = x;&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
void main()&lt;br /&gt;
{ &lt;br /&gt;
    A a;&lt;br /&gt;
    '''a.setx_value(5)''';&lt;br /&gt;
    cout&amp;lt;&amp;lt;'''a.getx_value()''';&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class BookStore&lt;br /&gt;
{ &lt;br /&gt;
  String title;&lt;br /&gt;
public String getTitle()&lt;br /&gt;
{&lt;br /&gt;
   return title;&lt;br /&gt;
}&lt;br /&gt;
// a setter method might check that the value that is being assigned to the variable is legal:&lt;br /&gt;
public void setTitle( String newTitle ) &lt;br /&gt;
{&lt;br /&gt;
  if ( newTitle == null )   // Don't allow null strings as titles!&lt;br /&gt;
     title = &amp;quot;(Untitled)&amp;quot;;  // Use an appropriate default value instead.&lt;br /&gt;
  else&lt;br /&gt;
     title = newTitle;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
     BookStore obj;&lt;br /&gt;
     obj. setTitle(&amp;quot;&amp;quot;);&lt;br /&gt;
     System.out.println(obj.getTitle());&lt;br /&gt;
}&lt;br /&gt;
Output:&lt;br /&gt;
(Untitled)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub setName &lt;br /&gt;
{&lt;br /&gt;
   my ( $self, $Name ) = @_;&lt;br /&gt;
   $self-&amp;gt;{_Name} = $Name if defined($Name);&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
sub getName &lt;br /&gt;
{&lt;br /&gt;
   my( $self ) = @_;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
# Now Set first name using helper function.&lt;br /&gt;
$object-&amp;gt;setName( &amp;quot;ABC&amp;quot; );&lt;br /&gt;
# Get name which is set using constructor.&lt;br /&gt;
$Name = $object-&amp;gt;getName();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Perl does not have private variables but we can still use the concept of getter, setter functions methods.&lt;br /&gt;
'''&lt;br /&gt;
=== ColdFusion === &lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Component Person&lt;br /&gt;
{&lt;br /&gt;
   property name&lt;br /&gt;
   property age;&lt;br /&gt;
   property city;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;!--- Once an object is created we can directly call the setters and getters for the properties as ---&amp;gt;&lt;br /&gt;
&amp;lt;cfscript&amp;gt;&lt;br /&gt;
   person = new Person();&lt;br /&gt;
   person.setName(&amp;quot;Brad&amp;quot;);&lt;br /&gt;
   person.setAge(46);&lt;br /&gt;
&lt;br /&gt;
   writeOutput(&amp;quot;Name : #person.getName()#&amp;quot;);&lt;br /&gt;
   writeOutput(&amp;quot;Age : #person.getAge()#&amp;quot;); &lt;br /&gt;
&amp;lt;/cfscript&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want to override the getter and setter method, you just need to define those methods in your CFC and ColdFusion will call our method instead of calling the implicit one.The implicit methods can also do some nice validation if you have given the ‘type’ for properties. For instance, if we define a property as numeric and try to provide a try to set a string as its value It will throw a nice error saying “The value cannot be converted to a numeric”.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples from Languages that use getters and setters as instance variable references:  ==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== C#: ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;class MyClass&lt;br /&gt;
{&lt;br /&gt;
      private int x;&lt;br /&gt;
      public int X&lt;br /&gt;
      {&lt;br /&gt;
            get&lt;br /&gt;
           {&lt;br /&gt;
             return x;&lt;br /&gt;
           }&lt;br /&gt;
          set&lt;br /&gt;
          {&lt;br /&gt;
             x = value;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
//Invocation&lt;br /&gt;
MyClass mc = new MyClass();&lt;br /&gt;
mc.X = 10;                   // calls set accessor of the property X, and pass 10 as value of the standard field 'value'.&lt;br /&gt;
Console.WriteLine(mc.X);     // displays 10. Calls the get accessor of the property X.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
C# also supports static properties, which belongs to the class rather than to the objects of the class. The properties of a Base class can be inherited to a Derived class and can be overridden polymorphicaly. &lt;br /&gt;
'''&lt;br /&gt;
===Lua===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class 'Test'&lt;br /&gt;
  function  Test : getLength()&lt;br /&gt;
   return # self.value&lt;br /&gt;
  end&lt;br /&gt;
  function  Test : setLength(newLength)&lt;br /&gt;
    for  i = self.length, newLength do&lt;br /&gt;
        table.insert(self.value, false )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
test =  Test({1, 2, 3, 4})&lt;br /&gt;
print(test.length)&lt;br /&gt;
self.length = property( Test.getLength, Test.setLength )    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getter and Setter functions can be implemented in Lua, which is similar to the properties concept in C#. This allows the functions to bind to a property that can be assigned and accessed as a value.&lt;br /&gt;
'''&lt;br /&gt;
===Ruby===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
    def initialize(lname, fname)&lt;br /&gt;
        @lname = lname&lt;br /&gt;
        @fname = fname&lt;br /&gt;
    end&lt;br /&gt;
attr_reader :lname // creates a getter method&lt;br /&gt;
    attr_writer :lname    // creates a setter method&lt;br /&gt;
    attr_accessor :fname // creates both getter and setter method&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x = Person.new(&amp;quot;ABC&amp;quot;, &amp;quot;XYZ&amp;quot;)&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
x.fname = &amp;quot;PQR&amp;quot;&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ruby simplifies the creation of getters and setters with a little metaprogramming and the methods attr, attr_reader, attr_writer, and attr_accessor, all from the Module class. By supplying the attr method, Ruby provides a way to acces the instances directly.&lt;br /&gt;
'''&lt;br /&gt;
===Php===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
class Customer&lt;br /&gt;
{&lt;br /&gt;
   public $name;&lt;br /&gt;
   private $data = array();&lt;br /&gt;
   public function __set($dt, $vl) &lt;br /&gt;
   {&lt;br /&gt;
      $this-&amp;gt;data[$dt] = $vl;&lt;br /&gt;
   }&lt;br /&gt;
   public function __get($dt) &lt;br /&gt;
   {&lt;br /&gt;
      return $this-&amp;gt;data[$dt];&lt;br /&gt;
   }&lt;br /&gt;
} &lt;br /&gt;
$c = new Customer();&lt;br /&gt;
$c-&amp;gt;name = “Sunil”; // $name is set because its public&lt;br /&gt;
$c-&amp;gt;email = “email@domain.com”; //assigning email@domain.com to the $email variable.&lt;br /&gt;
echo $c-&amp;gt;email;&lt;br /&gt;
?&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
An interesting aspect of php worth noting is that we can assign values to undefined variables. Because of the above limitation, PHP engine provides two magic methods __get() and __set(). __get() is used when value from an undefined variable is to be read and __set() is used when a value is to be assigned to a undefined variable of a class.In the above example when email@domain.com is assigned to the undefined variable $email, the magic method __set() is called. To this __set() method the name of the variable is passed into $dt variable of __set() method and the value i.e. email@domain.com is passed to $vl variable of the __set() method.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Objective C===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// public header file&lt;br /&gt;
@interface MyObject : NSObject&lt;br /&gt;
{&lt;br /&gt;
  NSString *make; &lt;br /&gt;
  NSString* model;&lt;br /&gt;
  NSNumber* vin;&lt;br /&gt;
}&lt;br /&gt;
@property (readonly, copy) NSString *language;&lt;br /&gt;
@property(readwrite, retain) NSString* make;&lt;br /&gt;
@property(readwrite, retain) NSString* model;&lt;br /&gt;
@property(readwrite, retain) NSNumber* vin;&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
#import &amp;quot;SimpleCar.h&amp;quot;&lt;br /&gt;
@implementation SimpleCar&lt;br /&gt;
@synthesize make, model, vin;&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Objective C we can define a property using @property directive. @synthesize will create automatically for you a setter and a getter methods for the property which becomes accessible during the run time.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Python ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DoubleIt(object):&lt;br /&gt;
   def _get_value(self):&lt;br /&gt;
       return self._value * 2&lt;br /&gt;
   def _set_value(self, value):&lt;br /&gt;
       self._value = value&lt;br /&gt;
   value = property(_get_value, _set_value)&lt;br /&gt;
&lt;br /&gt;
# Invocation &lt;br /&gt;
x = DoubleIt()&lt;br /&gt;
 &lt;br /&gt;
x.value = 10&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = 'foo'&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = [1,2,3]&lt;br /&gt;
print x.value&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above [http://stefaanlippens.net/python_property_trick python] code, the output is doubled since the getter multiplies the value by 2&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Javascript ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function addDataProperty()&lt;br /&gt;
{&lt;br /&gt;
   var newLine = &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;;&lt;br /&gt;
   var obj = {};&lt;br /&gt;
  &lt;br /&gt;
   // Add a data property to the object.&lt;br /&gt;
   Object.defineProperty(obj, &amp;quot;newDataProperty&amp;quot;, &lt;br /&gt;
   {&lt;br /&gt;
       value: 101,&lt;br /&gt;
       writable: true,&lt;br /&gt;
       enumerable: true,&lt;br /&gt;
       configurable: true&lt;br /&gt;
   });&lt;br /&gt;
&lt;br /&gt;
   // Set the property value.&lt;br /&gt;
   obj.newDataProperty = 102;&lt;br /&gt;
   document.write(&amp;quot;Property value: &amp;quot; + obj.newDataProperty + newLine);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Javascript supports accessing getters and setters as variable as properties. Javascript originally used __defineGetter__ and __defineSetter__ syntax to define properties which is depricated as the language evolved. Object.defineProperty is currently used for creating a property. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Scala ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person() {&lt;br /&gt;
// Private age variable, renamed to _age&lt;br /&gt;
private var _age = 0&lt;br /&gt;
var name = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Getter&lt;br /&gt;
def age = _age&lt;br /&gt;
&lt;br /&gt;
// Setter&lt;br /&gt;
def age_= (value:Int):Unit = _age = value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// We can invoke the setter as follows : &lt;br /&gt;
 can invoke the setter using the following: &lt;br /&gt;
person.age = 99&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Scala has some unconventional ideas that provide a solid, well thought out, and an abbreviated syntax to access object properties. This getter code simply defines a method called “age” and returns the “_age” variable. Scala doesn’t require the return keyword. The setter method name is “age_=”. The underscore is a special character in Scala and in this case, allows for a space in the method name which essentially makes the name “age =”. The parentheses and contents dictate the value and type that needs to be passed in. The “:Unit” code is equivalent to returning void. The remaining code is setting the “_age” variable to “value”.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Smalltalk===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     name                           &amp;quot;gets the value of name&amp;quot;&lt;br /&gt;
     name:aName              &amp;quot;sets name to the value of aName&amp;quot;&lt;br /&gt;
&lt;br /&gt;
     address                        &amp;quot;gets the value of address&amp;quot;&lt;br /&gt;
     address:anAddress     &amp;quot;sets anAddress to the value of anAddress&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In [http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk] the names of getter methods are usually the same as the name of the instance variable. A colon is added to the end of setter method name e.g. colour:&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Actionscript ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public var fullName:String;&lt;br /&gt;
private var _fullName:String;&lt;br /&gt;
&lt;br /&gt;
public function get fullName():String {&lt;br /&gt;
   return _fullName;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public function set fullName(_fullName:String):void {&lt;br /&gt;
   this._fullName = _fullName;&lt;br /&gt;
}&lt;br /&gt;
// getters&lt;br /&gt;
var1 = obj.fullName;&lt;br /&gt;
var2 = obj['fullName'];&lt;br /&gt;
// setters&lt;br /&gt;
obj.fullName = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
obj['fullName'] = &amp;quot;Yes&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getting or setting the property would call the getter and setter functions instead of accessing the property directly&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
==Getters and Setters from a different perspective==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
A fundamental precept of OO systems is that an object should not expose any of its implementation details. This way, you can change the implementation without changing the code that uses the object. It follows then that in OO systems you should avoid getter and setter functions since they mostly provide access to implementation details. For instance if you need change the return type of a gettr method from int to long to accommodate the big numbers you need to change all the invocations of that getter method. This negates the concept of [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html information hiding]. The same issue arises when you need to change the accessed field’s type. You also have to change the getter’s return type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Solution:	 &lt;br /&gt;
Maintainability is inversely proportionate to the amount of data that moves between objects. Thus, its best to minimize data movement as much as possible. The idea is to focus on what you will do rather than how you will do it. Don't ask for the information you need to do the work; ask the object that has the information to do the work for you. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
'''&lt;br /&gt;
Getters and setters provide a convenient method to access the instance variables. A lot of new languages have come up with the support for accessing getters and setters as instance variable reference which improves the readability of the code. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== References ==&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx Understanding properties in C#]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html why getters and setters are evil ]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set php5 OOPS tutorial]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://stefaanlippens.net/python_property_trick python-hiding attribute getters and setters behind standard attribute access]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 Object.defineProperty Function (JavaScript)]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Getters and Setters in Scala]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ ColdFusion 9 : Implicit/Generated CFC Methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.jamesward.com/2010/05/07/flex-and-java-differences-getters-setters/  Flex and Java Differences: Getters &amp;amp; Setters]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.touch-code-magazine.com/objective-c-properties/ Objective C properties]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Properties in Lua]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://docstore.mik.ua/orelly/perl4/porm/ch11_05.htm Creating getters and setters in perl ]&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=49087</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h hs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=49087"/>
		<updated>2011-09-17T22:18:34Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: /* Java */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
== What are getters and setters ? ==&lt;br /&gt;
''' &lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide getter and setter methods to access/modify object data. When writing new classes, it's a good idea to pay attention to the issue of access control. Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. Because of this naming convention, accessor methods are more often referred to as getter methods. This is a good programming practice, since the data fields are not directly accessible outside the class. Thus 'Getters' and 'Setters' allow us to effectively protect your data. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and setters as method calls ==&lt;br /&gt;
'''&lt;br /&gt;
For each variable, a get method will return its value and a set method will set the value. Here are the advantages of using getter and setter as method calls: &lt;br /&gt;
* Encapsulate the data from accidental / inadvertent modification. The private member variable is not part of the public interface of your class; only the public getter and setter methods are, and you are free to change their implementations without changing the public interface of your class&lt;br /&gt;
* If we decide that some action should be taken every time you change/access the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. For Instance, we can keep track of how many times a variable is accessed. &lt;br /&gt;
* Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and getters as variable references(properties) ==&lt;br /&gt;
'''&lt;br /&gt;
Properties are a robust way to handle object’s data. Properties support accessing the instance variables the same way as calling an instance method. A property communicates the idea of &amp;quot;I will make a value available to you, or accept a value from you.&amp;quot; It's not an implementation concept, it's an interface concept. Different languages follow specific syntax for adding a property to a class. Following are the advantages properties: &lt;br /&gt;
* the code is much cleaner when accessing a property when compared to Java or C++ which uses 2 separate methods for each instance variable. They are very useful in GUI programming which necessitates using a lot of fields for UI elements&lt;br /&gt;
* With properties we have fine-grained access control. For instance we can define a property as abstract thereby forcing the derived class to define that property. &lt;br /&gt;
* The main advantage of using properties is that if the internal implementation of getting or setting the property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class. This allows the interface of the object to stay the same even if the underlying implementation of getting and setting the property changes. &lt;br /&gt;
&lt;br /&gt;
Realizing the importance of getters and setters, popular IDEs like Eclipse, Visual studio has a built in mechanism to add getter and setter for a field or to create a property (in C#) for a given field.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples Languages that use getters and setters as method calls: ==&lt;br /&gt;
'''&lt;br /&gt;
'''&lt;br /&gt;
===C++===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
  int x_value;&lt;br /&gt;
&lt;br /&gt;
  public:&lt;br /&gt;
  // Getters&lt;br /&gt;
  int getx_value()&lt;br /&gt;
  {&lt;br /&gt;
      return x;&lt;br /&gt;
  }&lt;br /&gt;
  // Setters&lt;br /&gt;
  void setx_value( int x )&lt;br /&gt;
  {&lt;br /&gt;
      x_value = x;&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
void main()&lt;br /&gt;
{ &lt;br /&gt;
    A a;&lt;br /&gt;
    a.setx_value(5);&lt;br /&gt;
    cout&amp;lt;&amp;lt;a.getx_value();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
=== Java ===&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class BookStore&lt;br /&gt;
{ &lt;br /&gt;
  String title;&lt;br /&gt;
public String getTitle()&lt;br /&gt;
{&lt;br /&gt;
   return title;&lt;br /&gt;
}&lt;br /&gt;
// a setter method might check that the value that is being assigned to the variable is legal:&lt;br /&gt;
public void setTitle( String newTitle ) &lt;br /&gt;
{&lt;br /&gt;
  if ( newTitle == null )   // Don't allow null strings as titles!&lt;br /&gt;
     title = &amp;quot;(Untitled)&amp;quot;;  // Use an appropriate default value instead.&lt;br /&gt;
  else&lt;br /&gt;
     title = newTitle;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
     BookStore obj;&lt;br /&gt;
     obj. setTitle(&amp;quot;&amp;quot;);&lt;br /&gt;
     System.out.println(obj.getTitle());&lt;br /&gt;
}&lt;br /&gt;
Output:&lt;br /&gt;
(Untitled)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Perl ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub setName &lt;br /&gt;
{&lt;br /&gt;
   my ( $self, $Name ) = @_;&lt;br /&gt;
   $self-&amp;gt;{_Name} = $Name if defined($Name);&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
sub getName &lt;br /&gt;
{&lt;br /&gt;
   my( $self ) = @_;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
# Now Set first name using helper function.&lt;br /&gt;
$object-&amp;gt;setName( &amp;quot;ABC&amp;quot; );&lt;br /&gt;
# Get name which is set using constructor.&lt;br /&gt;
$Name = $object-&amp;gt;getName();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Perl does not have private variables but we can still use the concept of getter, setter functions methods.&lt;br /&gt;
'''&lt;br /&gt;
=== ColdFusion === &lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Component Person&lt;br /&gt;
{&lt;br /&gt;
   property name&lt;br /&gt;
   property age;&lt;br /&gt;
   property city;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;!--- Once an object is created we can directly call the setters and getters for the properties as ---&amp;gt;&lt;br /&gt;
&amp;lt;cfscript&amp;gt;&lt;br /&gt;
   person = new Person();&lt;br /&gt;
   person.setName(&amp;quot;Brad&amp;quot;);&lt;br /&gt;
   person.setAge(46);&lt;br /&gt;
&lt;br /&gt;
   writeOutput(&amp;quot;Name : #person.getName()#&amp;quot;);&lt;br /&gt;
   writeOutput(&amp;quot;Age : #person.getAge()#&amp;quot;); &lt;br /&gt;
&amp;lt;/cfscript&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want to override the getter and setter method, you just need to define those methods in your CFC and ColdFusion will call our method instead of calling the implicit one.The implicit methods can also do some nice validation if you have given the ‘type’ for properties. For instance, if we define a property as numeric and try to provide a try to set a string as its value It will throw a nice error saying “The value cannot be converted to a numeric”.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples from Languages that use getters and setters as instance variable references:  ==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== C#: ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;class MyClass&lt;br /&gt;
{&lt;br /&gt;
      private int x;&lt;br /&gt;
      public int X&lt;br /&gt;
      {&lt;br /&gt;
            get&lt;br /&gt;
           {&lt;br /&gt;
             return x;&lt;br /&gt;
           }&lt;br /&gt;
          set&lt;br /&gt;
          {&lt;br /&gt;
             x = value;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
//Invocation&lt;br /&gt;
MyClass mc = new MyClass();&lt;br /&gt;
mc.X = 10;                   // calls set accessor of the property X, and pass 10 as value of the standard field 'value'.&lt;br /&gt;
Console.WriteLine(mc.X);     // displays 10. Calls the get accessor of the property X.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
C# also supports static properties, which belongs to the class rather than to the objects of the class. The properties of a Base class can be inherited to a Derived class and can be overridden polymorphicaly. &lt;br /&gt;
'''&lt;br /&gt;
===Lua===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class 'Test'&lt;br /&gt;
  function  Test : getLength()&lt;br /&gt;
   return # self.value&lt;br /&gt;
  end&lt;br /&gt;
  function  Test : setLength(newLength)&lt;br /&gt;
    for  i = self.length, newLength do&lt;br /&gt;
        table.insert(self.value, false )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
test =  Test({1, 2, 3, 4})&lt;br /&gt;
print(test.length)&lt;br /&gt;
self.length = property( Test.getLength, Test.setLength )    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getter and Setter functions can be implemented in Lua, which is similar to the properties concept in C#. This allows the functions to bind to a property that can be assigned and accessed as a value.&lt;br /&gt;
'''&lt;br /&gt;
===Ruby===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
    def initialize(lname, fname)&lt;br /&gt;
        @lname = lname&lt;br /&gt;
        @fname = fname&lt;br /&gt;
    end&lt;br /&gt;
attr_reader :lname // creates a getter method&lt;br /&gt;
    attr_writer :lname    // creates a setter method&lt;br /&gt;
    attr_accessor :fname // creates both getter and setter method&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x = Person.new(&amp;quot;ABC&amp;quot;, &amp;quot;XYZ&amp;quot;)&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
x.fname = &amp;quot;PQR&amp;quot;&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ruby simplifies the creation of getters and setters with a little metaprogramming and the methods attr, attr_reader, attr_writer, and attr_accessor, all from the Module class. By supplying the attr method, Ruby provides a way to acces the instances directly.&lt;br /&gt;
'''&lt;br /&gt;
===Php===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
class Customer&lt;br /&gt;
{&lt;br /&gt;
   public $name;&lt;br /&gt;
   private $data = array();&lt;br /&gt;
   public function __set($dt, $vl) &lt;br /&gt;
   {&lt;br /&gt;
      $this-&amp;gt;data[$dt] = $vl;&lt;br /&gt;
   }&lt;br /&gt;
   public function __get($dt) &lt;br /&gt;
   {&lt;br /&gt;
      return $this-&amp;gt;data[$dt];&lt;br /&gt;
   }&lt;br /&gt;
} &lt;br /&gt;
$c = new Customer();&lt;br /&gt;
$c-&amp;gt;name = “Sunil”; // $name is set because its public&lt;br /&gt;
$c-&amp;gt;email = “email@domain.com”; //assigning email@domain.com to the $email variable.&lt;br /&gt;
echo $c-&amp;gt;email;&lt;br /&gt;
?&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
An interesting aspect of php worth noting is that we can assign values to undefined variables. Because of the above limitation, PHP engine provides two magic methods __get() and __set(). __get() is used when value from an undefined variable is to be read and __set() is used when a value is to be assigned to a undefined variable of a class.In the above example when email@domain.com is assigned to the undefined variable $email, the magic method __set() is called. To this __set() method the name of the variable is passed into $dt variable of __set() method and the value i.e. email@domain.com is passed to $vl variable of the __set() method.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Objective C===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// public header file&lt;br /&gt;
@interface MyObject : NSObject&lt;br /&gt;
{&lt;br /&gt;
  NSString *make; &lt;br /&gt;
  NSString* model;&lt;br /&gt;
  NSNumber* vin;&lt;br /&gt;
}&lt;br /&gt;
@property (readonly, copy) NSString *language;&lt;br /&gt;
@property(readwrite, retain) NSString* make;&lt;br /&gt;
@property(readwrite, retain) NSString* model;&lt;br /&gt;
@property(readwrite, retain) NSNumber* vin;&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
#import &amp;quot;SimpleCar.h&amp;quot;&lt;br /&gt;
@implementation SimpleCar&lt;br /&gt;
@synthesize make, model, vin;&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Objective C we can define a property using @property directive. @synthesize will create automatically for you a setter and a getter methods for the property which becomes accessible during the run time.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Python ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DoubleIt(object):&lt;br /&gt;
   def _get_value(self):&lt;br /&gt;
       return self._value * 2&lt;br /&gt;
   def _set_value(self, value):&lt;br /&gt;
       self._value = value&lt;br /&gt;
   value = property(_get_value, _set_value)&lt;br /&gt;
&lt;br /&gt;
# Invocation &lt;br /&gt;
x = DoubleIt()&lt;br /&gt;
 &lt;br /&gt;
x.value = 10&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = 'foo'&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = [1,2,3]&lt;br /&gt;
print x.value&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above [http://stefaanlippens.net/python_property_trick python] code, the output is doubled since the getter multiplies the value by 2&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Javascript ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function addDataProperty()&lt;br /&gt;
{&lt;br /&gt;
   var newLine = &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;;&lt;br /&gt;
   var obj = {};&lt;br /&gt;
  &lt;br /&gt;
   // Add a data property to the object.&lt;br /&gt;
   Object.defineProperty(obj, &amp;quot;newDataProperty&amp;quot;, &lt;br /&gt;
   {&lt;br /&gt;
       value: 101,&lt;br /&gt;
       writable: true,&lt;br /&gt;
       enumerable: true,&lt;br /&gt;
       configurable: true&lt;br /&gt;
   });&lt;br /&gt;
&lt;br /&gt;
   // Set the property value.&lt;br /&gt;
   obj.newDataProperty = 102;&lt;br /&gt;
   document.write(&amp;quot;Property value: &amp;quot; + obj.newDataProperty + newLine);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Javascript supports accessing getters and setters as variable as properties. Javascript originally used __defineGetter__ and __defineSetter__ syntax to define properties which is depricated as the language evolved. Object.defineProperty is currently used for creating a property. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Scala ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person() {&lt;br /&gt;
// Private age variable, renamed to _age&lt;br /&gt;
private var _age = 0&lt;br /&gt;
var name = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Getter&lt;br /&gt;
def age = _age&lt;br /&gt;
&lt;br /&gt;
// Setter&lt;br /&gt;
def age_= (value:Int):Unit = _age = value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// We can invoke the setter as follows : &lt;br /&gt;
 can invoke the setter using the following: &lt;br /&gt;
person.age = 99&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Scala has some unconventional ideas that provide a solid, well thought out, and an abbreviated syntax to access object properties. This getter code simply defines a method called “age” and returns the “_age” variable. Scala doesn’t require the return keyword. The setter method name is “age_=”. The underscore is a special character in Scala and in this case, allows for a space in the method name which essentially makes the name “age =”. The parentheses and contents dictate the value and type that needs to be passed in. The “:Unit” code is equivalent to returning void. The remaining code is setting the “_age” variable to “value”.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Smalltalk===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     name                           &amp;quot;gets the value of name&amp;quot;&lt;br /&gt;
     name:aName              &amp;quot;sets name to the value of aName&amp;quot;&lt;br /&gt;
&lt;br /&gt;
     address                        &amp;quot;gets the value of address&amp;quot;&lt;br /&gt;
     address:anAddress     &amp;quot;sets anAddress to the value of anAddress&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In [http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk] the names of getter methods are usually the same as the name of the instance variable. A colon is added to the end of setter method name e.g. colour:&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Actionscript ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public var fullName:String;&lt;br /&gt;
private var _fullName:String;&lt;br /&gt;
&lt;br /&gt;
public function get fullName():String {&lt;br /&gt;
   return _fullName;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public function set fullName(_fullName:String):void {&lt;br /&gt;
   this._fullName = _fullName;&lt;br /&gt;
}&lt;br /&gt;
// getters&lt;br /&gt;
var1 = obj.fullName;&lt;br /&gt;
var2 = obj['fullName'];&lt;br /&gt;
// setters&lt;br /&gt;
obj.fullName = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
obj['fullName'] = &amp;quot;Yes&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getting or setting the property would call the getter and setter functions instead of accessing the property directly&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
==Getters and Setters from a different perspective==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
A fundamental precept of OO systems is that an object should not expose any of its implementation details. This way, you can change the implementation without changing the code that uses the object. It follows then that in OO systems you should avoid getter and setter functions since they mostly provide access to implementation details. For instance if you need change the return type of a gettr method from int to long to accommodate the big numbers you need to change all the invocations of that getter method. This negates the concept of [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html information hiding]. The same issue arises when you need to change the accessed field’s type. You also have to change the getter’s return type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Solution:	 &lt;br /&gt;
Maintainability is inversely proportionate to the amount of data that moves between objects. Thus, its best to minimize data movement as much as possible. The idea is to focus on what you will do rather than how you will do it. Don't ask for the information you need to do the work; ask the object that has the information to do the work for you. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
'''&lt;br /&gt;
Getters and setters provide a convenient method to access the instance variables. A lot of new languages have come up with the support for accessing getters and setters as instance variable reference which improves the readability of the code. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== References ==&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx Understanding properties in C#]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html why getters and setters are evil ]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set php5 OOPS tutorial]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://stefaanlippens.net/python_property_trick python-hiding attribute getters and setters behind standard attribute access]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 Object.defineProperty Function (JavaScript)]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Getters and Setters in Scala]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ ColdFusion 9 : Implicit/Generated CFC Methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.jamesward.com/2010/05/07/flex-and-java-differences-getters-setters/  Flex and Java Differences: Getters &amp;amp; Setters]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.touch-code-magazine.com/objective-c-properties/ Objective C properties]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Properties in Lua]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://docstore.mik.ua/orelly/perl4/porm/ch11_05.htm Creating getters and setters in perl ]&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=48744</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h hs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=48744"/>
		<updated>2011-09-16T01:59:49Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
== What are getters and setters ? ==&lt;br /&gt;
''' &lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide getter and setter methods to access/modify object data. When writing new classes, it's a good idea to pay attention to the issue of access control. Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. Because of this naming convention, accessor methods are more often referred to as getter methods. This is a good programming practice, since the data fields are not directly accessible outside the class. Thus 'Getters' and 'Setters' allow us to effectively protect your data. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and setters as method calls ==&lt;br /&gt;
'''&lt;br /&gt;
For each variable, a get method will return its value and a set method will set the value. Here are the advantages of using getter and setter as method calls: &lt;br /&gt;
* Encapsulate the data from accidental / inadvertent modification. The private member variable is not part of the public interface of your class; only the public getter and setter methods are, and you are free to change their implementations without changing the public interface of your class&lt;br /&gt;
* If we decide that some action should be taken every time you change/access the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. For Instance, we can keep track of how many times a variable is accessed. &lt;br /&gt;
* Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and getters as variable references(properties) ==&lt;br /&gt;
'''&lt;br /&gt;
Properties are a robust way to handle object’s data. Properties support accessing the instance variables the same way as calling an instance method. A property communicates the idea of &amp;quot;I will make a value available to you, or accept a value from you.&amp;quot; It's not an implementation concept, it's an interface concept. Different languages follow specific syntax for adding a property to a class. Following are the advantages properties: &lt;br /&gt;
* the code is much cleaner when accessing a property when compared to Java or C++ which uses 2 separate methods for each instance variable. They are very useful in GUI programming which necessitates using a lot of fields for UI elements&lt;br /&gt;
* With properties we have fine-grained access control. For instance we can define a property as abstract thereby forcing the derived class to define that property. &lt;br /&gt;
* The main advantage of using properties is that if the internal implementation of getting or setting the property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class. This allows the interface of the object to stay the same even if the underlying implementation of getting and setting the property changes. &lt;br /&gt;
&lt;br /&gt;
Realizing the importance of getters and setters, popular IDEs like Eclipse, Visual studio has a built in mechanism to add getter and setter for a field or to create a property (in C#) for a given field.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples Languages that use getters and setters as method calls: ==&lt;br /&gt;
'''&lt;br /&gt;
'''&lt;br /&gt;
===C++===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
  int x_value;&lt;br /&gt;
&lt;br /&gt;
  public:&lt;br /&gt;
  // Getters&lt;br /&gt;
  int getx_value()&lt;br /&gt;
  {&lt;br /&gt;
      return x;&lt;br /&gt;
  }&lt;br /&gt;
  // Setters&lt;br /&gt;
  void setx_value( int x )&lt;br /&gt;
  {&lt;br /&gt;
      x_value = x;&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
void main()&lt;br /&gt;
{ &lt;br /&gt;
    A a;&lt;br /&gt;
    a.setx_value(5);&lt;br /&gt;
    cout&amp;lt;&amp;lt;a.getx_value();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
=== Java ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class BookStore&lt;br /&gt;
{ &lt;br /&gt;
  String title;&lt;br /&gt;
public String getTitle()&lt;br /&gt;
{&lt;br /&gt;
   return title;&lt;br /&gt;
}&lt;br /&gt;
// a setter method might check that the value that is being assigned to the variable is legal:&lt;br /&gt;
public void setTitle( String newTitle ) &lt;br /&gt;
{&lt;br /&gt;
  if ( newTitle == null )   // Don't allow null strings as titles!&lt;br /&gt;
     title = &amp;quot;(Untitled)&amp;quot;;  // Use an appropriate default value instead.&lt;br /&gt;
  else&lt;br /&gt;
     title = newTitle;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
     BookStore obj;&lt;br /&gt;
     obj. setTitle(&amp;quot;&amp;quot;);&lt;br /&gt;
     System.out.println(obj.getTitle());&lt;br /&gt;
}&lt;br /&gt;
Output:&lt;br /&gt;
(Untitled)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
=== Perl ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub setName &lt;br /&gt;
{&lt;br /&gt;
   my ( $self, $Name ) = @_;&lt;br /&gt;
   $self-&amp;gt;{_Name} = $Name if defined($Name);&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
sub getName &lt;br /&gt;
{&lt;br /&gt;
   my( $self ) = @_;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
# Now Set first name using helper function.&lt;br /&gt;
$object-&amp;gt;setName( &amp;quot;ABC&amp;quot; );&lt;br /&gt;
# Get name which is set using constructor.&lt;br /&gt;
$Name = $object-&amp;gt;getName();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Perl does not have private variables but we can still use the concept of getter, setter functions methods.&lt;br /&gt;
'''&lt;br /&gt;
=== ColdFusion === &lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Component Person&lt;br /&gt;
{&lt;br /&gt;
   property name&lt;br /&gt;
   property age;&lt;br /&gt;
   property city;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;!--- Once an object is created we can directly call the setters and getters for the properties as ---&amp;gt;&lt;br /&gt;
&amp;lt;cfscript&amp;gt;&lt;br /&gt;
   person = new Person();&lt;br /&gt;
   person.setName(&amp;quot;Brad&amp;quot;);&lt;br /&gt;
   person.setAge(46);&lt;br /&gt;
&lt;br /&gt;
   writeOutput(&amp;quot;Name : #person.getName()#&amp;quot;);&lt;br /&gt;
   writeOutput(&amp;quot;Age : #person.getAge()#&amp;quot;); &lt;br /&gt;
&amp;lt;/cfscript&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want to override the getter and setter method, you just need to define those methods in your CFC and ColdFusion will call our method instead of calling the implicit one.The implicit methods can also do some nice validation if you have given the ‘type’ for properties. For instance, if we define a property as numeric and try to provide a try to set a string as its value It will throw a nice error saying “The value cannot be converted to a numeric”.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples from Languages that use getters and setters as instance variable references:  ==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== C#: ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;class MyClass&lt;br /&gt;
{&lt;br /&gt;
      private int x;&lt;br /&gt;
      public int X&lt;br /&gt;
      {&lt;br /&gt;
            get&lt;br /&gt;
           {&lt;br /&gt;
             return x;&lt;br /&gt;
           }&lt;br /&gt;
          set&lt;br /&gt;
          {&lt;br /&gt;
             x = value;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
//Invocation&lt;br /&gt;
MyClass mc = new MyClass();&lt;br /&gt;
mc.X = 10;                   // calls set accessor of the property X, and pass 10 as value of the standard field 'value'.&lt;br /&gt;
Console.WriteLine(mc.X);     // displays 10. Calls the get accessor of the property X.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
C# also supports static properties, which belongs to the class rather than to the objects of the class. The properties of a Base class can be inherited to a Derived class and can be overridden polymorphicaly. &lt;br /&gt;
'''&lt;br /&gt;
===Lua===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class 'Test'&lt;br /&gt;
  function  Test : getLength()&lt;br /&gt;
   return # self.value&lt;br /&gt;
  end&lt;br /&gt;
  function  Test : setLength(newLength)&lt;br /&gt;
    for  i = self.length, newLength do&lt;br /&gt;
        table.insert(self.value, false )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
test =  Test({1, 2, 3, 4})&lt;br /&gt;
print(test.length)&lt;br /&gt;
self.length = property( Test.getLength, Test.setLength )    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getter and Setter functions can be implemented in Lua, which is similar to the properties concept in C#. This allows the functions to bind to a property that can be assigned and accessed as a value.&lt;br /&gt;
'''&lt;br /&gt;
===Ruby===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
    def initialize(lname, fname)&lt;br /&gt;
        @lname = lname&lt;br /&gt;
        @fname = fname&lt;br /&gt;
    end&lt;br /&gt;
attr_reader :lname // creates a getter method&lt;br /&gt;
    attr_writer :lname    // creates a setter method&lt;br /&gt;
    attr_accessor :fname // creates both getter and setter method&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x = Person.new(&amp;quot;ABC&amp;quot;, &amp;quot;XYZ&amp;quot;)&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
x.fname = &amp;quot;PQR&amp;quot;&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ruby simplifies the creation of getters and setters with a little metaprogramming and the methods attr, attr_reader, attr_writer, and attr_accessor, all from the Module class. By supplying the attr method, Ruby provides a way to acces the instances directly.&lt;br /&gt;
'''&lt;br /&gt;
===Php===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
class Customer&lt;br /&gt;
{&lt;br /&gt;
   public $name;&lt;br /&gt;
   private $data = array();&lt;br /&gt;
   public function __set($dt, $vl) &lt;br /&gt;
   {&lt;br /&gt;
      $this-&amp;gt;data[$dt] = $vl;&lt;br /&gt;
   }&lt;br /&gt;
   public function __get($dt) &lt;br /&gt;
   {&lt;br /&gt;
      return $this-&amp;gt;data[$dt];&lt;br /&gt;
   }&lt;br /&gt;
} &lt;br /&gt;
$c = new Customer();&lt;br /&gt;
$c-&amp;gt;name = “Sunil”; // $name is set because its public&lt;br /&gt;
$c-&amp;gt;email = “email@domain.com”; //assigning email@domain.com to the $email variable.&lt;br /&gt;
echo $c-&amp;gt;email;&lt;br /&gt;
?&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
An interesting aspect of php worth noting is that we can assign values to undefined variables. Because of the above limitation, PHP engine provides two magic methods __get() and __set(). __get() is used when value from an undefined variable is to be read and __set() is used when a value is to be assigned to a undefined variable of a class.In the above example when email@domain.com is assigned to the undefined variable $email, the magic method __set() is called. To this __set() method the name of the variable is passed into $dt variable of __set() method and the value i.e. email@domain.com is passed to $vl variable of the __set() method.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Objective C===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// public header file&lt;br /&gt;
@interface MyObject : NSObject&lt;br /&gt;
{&lt;br /&gt;
  NSString *make; &lt;br /&gt;
  NSString* model;&lt;br /&gt;
  NSNumber* vin;&lt;br /&gt;
}&lt;br /&gt;
@property (readonly, copy) NSString *language;&lt;br /&gt;
@property(readwrite, retain) NSString* make;&lt;br /&gt;
@property(readwrite, retain) NSString* model;&lt;br /&gt;
@property(readwrite, retain) NSNumber* vin;&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
#import &amp;quot;SimpleCar.h&amp;quot;&lt;br /&gt;
@implementation SimpleCar&lt;br /&gt;
@synthesize make, model, vin;&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Objective C we can define a property using @property directive. @synthesize will create automatically for you a setter and a getter methods for the property which becomes accessible during the run time.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Python ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DoubleIt(object):&lt;br /&gt;
   def _get_value(self):&lt;br /&gt;
       return self._value * 2&lt;br /&gt;
   def _set_value(self, value):&lt;br /&gt;
       self._value = value&lt;br /&gt;
   value = property(_get_value, _set_value)&lt;br /&gt;
&lt;br /&gt;
# Invocation &lt;br /&gt;
x = DoubleIt()&lt;br /&gt;
 &lt;br /&gt;
x.value = 10&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = 'foo'&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = [1,2,3]&lt;br /&gt;
print x.value&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above [http://stefaanlippens.net/python_property_trick python] code, the output is doubled since the getter multiplies the value by 2&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Javascript ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function addDataProperty()&lt;br /&gt;
{&lt;br /&gt;
   var newLine = &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;;&lt;br /&gt;
   var obj = {};&lt;br /&gt;
  &lt;br /&gt;
   // Add a data property to the object.&lt;br /&gt;
   Object.defineProperty(obj, &amp;quot;newDataProperty&amp;quot;, &lt;br /&gt;
   {&lt;br /&gt;
       value: 101,&lt;br /&gt;
       writable: true,&lt;br /&gt;
       enumerable: true,&lt;br /&gt;
       configurable: true&lt;br /&gt;
   });&lt;br /&gt;
&lt;br /&gt;
   // Set the property value.&lt;br /&gt;
   obj.newDataProperty = 102;&lt;br /&gt;
   document.write(&amp;quot;Property value: &amp;quot; + obj.newDataProperty + newLine);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Javascript supports accessing getters and setters as variable as properties. Javascript originally used __defineGetter__ and __defineSetter__ syntax to define properties which is depricated as the language evolved. Object.defineProperty is currently used for creating a property. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Scala ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person() {&lt;br /&gt;
// Private age variable, renamed to _age&lt;br /&gt;
private var _age = 0&lt;br /&gt;
var name = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Getter&lt;br /&gt;
def age = _age&lt;br /&gt;
&lt;br /&gt;
// Setter&lt;br /&gt;
def age_= (value:Int):Unit = _age = value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// We can invoke the setter as follows : &lt;br /&gt;
 can invoke the setter using the following: &lt;br /&gt;
person.age = 99&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Scala has some unconventional ideas that provide a solid, well thought out, and an abbreviated syntax to access object properties. This getter code simply defines a method called “age” and returns the “_age” variable. Scala doesn’t require the return keyword. The setter method name is “age_=”. The underscore is a special character in Scala and in this case, allows for a space in the method name which essentially makes the name “age =”. The parentheses and contents dictate the value and type that needs to be passed in. The “:Unit” code is equivalent to returning void. The remaining code is setting the “_age” variable to “value”.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Smalltalk===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     name                           &amp;quot;gets the value of name&amp;quot;&lt;br /&gt;
     name:aName              &amp;quot;sets name to the value of aName&amp;quot;&lt;br /&gt;
&lt;br /&gt;
     address                        &amp;quot;gets the value of address&amp;quot;&lt;br /&gt;
     address:anAddress     &amp;quot;sets anAddress to the value of anAddress&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In [http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk] the names of getter methods are usually the same as the name of the instance variable. A colon is added to the end of setter method name e.g. colour:&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Actionscript ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public var fullName:String;&lt;br /&gt;
private var _fullName:String;&lt;br /&gt;
&lt;br /&gt;
public function get fullName():String {&lt;br /&gt;
   return _fullName;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public function set fullName(_fullName:String):void {&lt;br /&gt;
   this._fullName = _fullName;&lt;br /&gt;
}&lt;br /&gt;
// getters&lt;br /&gt;
var1 = obj.fullName;&lt;br /&gt;
var2 = obj['fullName'];&lt;br /&gt;
// setters&lt;br /&gt;
obj.fullName = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
obj['fullName'] = &amp;quot;Yes&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getting or setting the property would call the getter and setter functions instead of accessing the property directly&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
==Getters and Setters from a different perspective==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
A fundamental precept of OO systems is that an object should not expose any of its implementation details. This way, you can change the implementation without changing the code that uses the object. It follows then that in OO systems you should avoid getter and setter functions since they mostly provide access to implementation details. For instance if you need change the return type of a gettr method from int to long to accommodate the big numbers you need to change all the invocations of that getter method. This negates the concept of [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html information hiding]. The same issue arises when you need to change the accessed field’s type. You also have to change the getter’s return type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Solution:	 &lt;br /&gt;
Maintainability is inversely proportionate to the amount of data that moves between objects. Thus, its best to minimize data movement as much as possible. The idea is to focus on what you will do rather than how you will do it. Don't ask for the information you need to do the work; ask the object that has the information to do the work for you. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
'''&lt;br /&gt;
Getters and setters provide a convenient method to access the instance variables. A lot of new languages have come up with the support for accessing getters and setters as instance variable reference which improves the readability of the code. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== References ==&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx Understanding properties in C#]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html why getters and setters are evil ]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set php5 OOPS tutorial]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://stefaanlippens.net/python_property_trick python-hiding attribute getters and setters behind standard attribute access]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 Object.defineProperty Function (JavaScript)]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Getters and Setters in Scala]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ ColdFusion 9 : Implicit/Generated CFC Methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.jamesward.com/2010/05/07/flex-and-java-differences-getters-setters/  Flex and Java Differences: Getters &amp;amp; Setters]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.touch-code-magazine.com/objective-c-properties/ Objective C properties]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Properties in Lua]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://docstore.mik.ua/orelly/perl4/porm/ch11_05.htm Creating getters and setters in perl ]&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=48732</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h hs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=48732"/>
		<updated>2011-09-16T01:54:42Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
== What are getters and setters ? ==&lt;br /&gt;
''' &lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide getter and setter methods to access/modify object data. When writing new classes, it's a good idea to pay attention to the issue of access control. Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. Because of this naming convention, accessor methods are more often referred to as getter methods. This is a good programming practice, since the data fields are not directly accessible outside the class. Thus 'Getters' and 'Setters' allow us to effectively protect your data. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and setters as method calls ==&lt;br /&gt;
'''&lt;br /&gt;
For each variable, a get method will return its value and a set method will set the value. Here are the advantages of using getter and setter as method calls: &lt;br /&gt;
* Encapsulate the data from accidental / inadvertent modification. The private member variable is not part of the public interface of your class; only the public getter and setter methods are, and you are free to change their implementations without changing the public interface of your class&lt;br /&gt;
* If we decide that some action should be taken every time you change/access the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. For Instance, we can keep track of how many times a variable is accessed. &lt;br /&gt;
* Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and getters as variable references(properties) ==&lt;br /&gt;
'''&lt;br /&gt;
Properties are a robust way to handle object’s data. Properties support accessing the instance variables the same way as calling an instance method. A property communicates the idea of &amp;quot;I will make a value available to you, or accept a value from you.&amp;quot; It's not an implementation concept, it's an interface concept. Different languages follow specific syntax for adding a property to a class. Following are the advantages properties: &lt;br /&gt;
* the code is much cleaner when accessing a property when compared to Java or C++ which uses 2 separate methods for each instance variable. They are very useful in GUI programming which necessitates using a lot of fields for UI elements&lt;br /&gt;
* With properties we have fine-grained access control. For instance we can define a property as abstract thereby forcing the derived class to define that property. &lt;br /&gt;
* The main advantage of using properties is that if the internal implementation of getting or setting the property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class. This allows the interface of the object to stay the same even if the underlying implementation of getting and setting the property changes. &lt;br /&gt;
&lt;br /&gt;
Realizing the importance of getters and setters, popular IDEs like Eclipse, Visual studio has a built in mechanism to add getter and setter for a field or to create a property (in C#) for a given field.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples Languages that use getters and setters as method calls: ==&lt;br /&gt;
'''&lt;br /&gt;
'''&lt;br /&gt;
===C++===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
  int x_value;&lt;br /&gt;
&lt;br /&gt;
  public:&lt;br /&gt;
  // Getters&lt;br /&gt;
  int getx_value()&lt;br /&gt;
  {&lt;br /&gt;
      return x;&lt;br /&gt;
  }&lt;br /&gt;
  // Setters&lt;br /&gt;
  void setx_value( int x )&lt;br /&gt;
  {&lt;br /&gt;
      x_value = x;&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
void main()&lt;br /&gt;
{ &lt;br /&gt;
    A a;&lt;br /&gt;
    a.setx_value(5);&lt;br /&gt;
    cout&amp;lt;&amp;lt;a.getx_value();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
=== Java ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class BookStore&lt;br /&gt;
{ &lt;br /&gt;
  String title;&lt;br /&gt;
public String getTitle()&lt;br /&gt;
{&lt;br /&gt;
   return title;&lt;br /&gt;
}&lt;br /&gt;
// a setter method might check that the value that is being assigned to the variable is legal:&lt;br /&gt;
public void setTitle( String newTitle ) &lt;br /&gt;
{&lt;br /&gt;
  if ( newTitle == null )   // Don't allow null strings as titles!&lt;br /&gt;
     title = &amp;quot;(Untitled)&amp;quot;;  // Use an appropriate default value instead.&lt;br /&gt;
  else&lt;br /&gt;
     title = newTitle;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
     BookStore obj;&lt;br /&gt;
     obj. setTitle(&amp;quot;&amp;quot;);&lt;br /&gt;
     System.out.println(obj.getTitle());&lt;br /&gt;
}&lt;br /&gt;
Output:&lt;br /&gt;
(Untitled)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
=== Perl ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub setName &lt;br /&gt;
{&lt;br /&gt;
   my ( $self, $Name ) = @_;&lt;br /&gt;
   $self-&amp;gt;{_Name} = $Name if defined($Name);&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
sub getName &lt;br /&gt;
{&lt;br /&gt;
   my( $self ) = @_;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
# Now Set first name using helper function.&lt;br /&gt;
$object-&amp;gt;setName( &amp;quot;ABC&amp;quot; );&lt;br /&gt;
# Get name which is set using constructor.&lt;br /&gt;
$Name = $object-&amp;gt;getName();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Perl does not have private variables but we can still use the concept of getter, setter functions methods.&lt;br /&gt;
'''&lt;br /&gt;
=== ColdFusion === &lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Component Person&lt;br /&gt;
{&lt;br /&gt;
   property name&lt;br /&gt;
   property age;&lt;br /&gt;
   property city;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;!--- Once an object is created we can directly call the setters and getters for the properties as ---&amp;gt;&lt;br /&gt;
&amp;lt;cfscript&amp;gt;&lt;br /&gt;
   person = new Person();&lt;br /&gt;
   person.setName(&amp;quot;Brad&amp;quot;);&lt;br /&gt;
   person.setAge(46);&lt;br /&gt;
&lt;br /&gt;
   writeOutput(&amp;quot;Name : #person.getName()#&amp;quot;);&lt;br /&gt;
   writeOutput(&amp;quot;Age : #person.getAge()#&amp;quot;); &lt;br /&gt;
&amp;lt;/cfscript&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want to override the getter and setter method, you just need to define those methods in your CFC and ColdFusion will call our method instead of calling the implicit one.The implicit methods can also do some nice validation if you have given the ‘type’ for properties. For instance, if we define a property as numeric and try to provide a try to set a string as its value It will throw a nice error saying “The value cannot be converted to a numeric”.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples from Languages that use getters and setters as instance variable references:  ==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== C#: ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;class MyClass&lt;br /&gt;
{&lt;br /&gt;
      private int x;&lt;br /&gt;
      public int X&lt;br /&gt;
      {&lt;br /&gt;
            get&lt;br /&gt;
           {&lt;br /&gt;
             return x;&lt;br /&gt;
           }&lt;br /&gt;
          set&lt;br /&gt;
          {&lt;br /&gt;
             x = value;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
//Invocation&lt;br /&gt;
MyClass mc = new MyClass();&lt;br /&gt;
mc.X = 10;                   // calls set accessor of the property X, and pass 10 as value of the standard field 'value'.&lt;br /&gt;
Console.WriteLine(mc.X);     // displays 10. Calls the get accessor of the property X.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
C# also supports static properties, which belongs to the class rather than to the objects of the class. The properties of a Base class can be inherited to a Derived class and can be overridden polymorphicaly. &lt;br /&gt;
'''&lt;br /&gt;
===Lua===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class 'Test'&lt;br /&gt;
  function  Test : getLength()&lt;br /&gt;
   return # self.value&lt;br /&gt;
  end&lt;br /&gt;
  function  Test : setLength(newLength)&lt;br /&gt;
    for  i = self.length, newLength do&lt;br /&gt;
        table.insert(self.value, false )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
test =  Test({1, 2, 3, 4})&lt;br /&gt;
print(test.length)&lt;br /&gt;
self.length = property( Test.getLength, Test.setLength )    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getter and Setter functions can be implemented in Lua, which is similar to the properties concept in C#. This allows the functions to bind to a property that can be assigned and accessed as a value.&lt;br /&gt;
'''&lt;br /&gt;
===Ruby===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
    def initialize(lname, fname)&lt;br /&gt;
        @lname = lname&lt;br /&gt;
        @fname = fname&lt;br /&gt;
    end&lt;br /&gt;
attr_reader :lname // creates a getter method&lt;br /&gt;
    attr_writer :lname    // creates a setter method&lt;br /&gt;
    attr_accessor :fname // creates both getter and setter method&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x = Person.new(&amp;quot;ABC&amp;quot;, &amp;quot;XYZ&amp;quot;)&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
x.fname = &amp;quot;PQR&amp;quot;&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ruby simplifies the creation of getters and setters with a little metaprogramming and the methods attr, attr_reader, attr_writer, and attr_accessor, all from the Module class. By supplying the attr method, Ruby provides a way to acces the instances directly.&lt;br /&gt;
'''&lt;br /&gt;
===Php===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
class Customer&lt;br /&gt;
{&lt;br /&gt;
   public $name;&lt;br /&gt;
   private $data = array();&lt;br /&gt;
   public function __set($dt, $vl) &lt;br /&gt;
   {&lt;br /&gt;
      $this-&amp;gt;data[$dt] = $vl;&lt;br /&gt;
   }&lt;br /&gt;
   public function __get($dt) &lt;br /&gt;
   {&lt;br /&gt;
      return $this-&amp;gt;data[$dt];&lt;br /&gt;
   }&lt;br /&gt;
} &lt;br /&gt;
$c = new Customer();&lt;br /&gt;
$c-&amp;gt;name = “Sunil”; // $name is set because its public&lt;br /&gt;
$c-&amp;gt;email = “email@domain.com”; //assigning email@domain.com to the $email variable.&lt;br /&gt;
echo $c-&amp;gt;email;&lt;br /&gt;
?&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
An interesting aspect of php worth noting is that we can assign values to undefined variables. Because of the above limitation, PHP engine provides two magic methods __get() and __set(). __get() is used when value from an undefined variable is to be read and __set() is used when a value is to be assigned to a undefined variable of a class.In the above example when email@domain.com is assigned to the undefined variable $email, the magic method __set() is called. To this __set() method the name of the variable is passed into $dt variable of __set() method and the value i.e. email@domain.com is passed to $vl variable of the __set() method.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Objective C===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// public header file&lt;br /&gt;
@interface MyObject : NSObject&lt;br /&gt;
{&lt;br /&gt;
  NSString *make; &lt;br /&gt;
  NSString* model;&lt;br /&gt;
  NSNumber* vin;&lt;br /&gt;
}&lt;br /&gt;
@property (readonly, copy) NSString *language;&lt;br /&gt;
@property(readwrite, retain) NSString* make;&lt;br /&gt;
@property(readwrite, retain) NSString* model;&lt;br /&gt;
@property(readwrite, retain) NSNumber* vin;&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
#import &amp;quot;SimpleCar.h&amp;quot;&lt;br /&gt;
@implementation SimpleCar&lt;br /&gt;
@synthesize make, model, vin;&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Objective C we can define a property using @property directive. @synthesize will create automatically for you a setter and a getter methods for the property which becomes accessible during the run time.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Python ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DoubleIt(object):&lt;br /&gt;
   def _get_value(self):&lt;br /&gt;
       return self._value * 2&lt;br /&gt;
   def _set_value(self, value):&lt;br /&gt;
       self._value = value&lt;br /&gt;
   value = property(_get_value, _set_value)&lt;br /&gt;
&lt;br /&gt;
# Invocation &lt;br /&gt;
x = DoubleIt()&lt;br /&gt;
 &lt;br /&gt;
x.value = 10&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = 'foo'&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = [1,2,3]&lt;br /&gt;
print x.value&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here the output is doubled since the getter multiplies the value by 2&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Javascript ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function addDataProperty()&lt;br /&gt;
{&lt;br /&gt;
   var newLine = &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;;&lt;br /&gt;
   var obj = {};&lt;br /&gt;
  &lt;br /&gt;
   // Add a data property to the object.&lt;br /&gt;
   Object.defineProperty(obj, &amp;quot;newDataProperty&amp;quot;, &lt;br /&gt;
   {&lt;br /&gt;
       value: 101,&lt;br /&gt;
       writable: true,&lt;br /&gt;
       enumerable: true,&lt;br /&gt;
       configurable: true&lt;br /&gt;
   });&lt;br /&gt;
&lt;br /&gt;
   // Set the property value.&lt;br /&gt;
   obj.newDataProperty = 102;&lt;br /&gt;
   document.write(&amp;quot;Property value: &amp;quot; + obj.newDataProperty + newLine);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Javascript supports accessing getters and setters as variable as properties. Javascript originally used __defineGetter__ and __defineSetter__ syntax to define properties which is depricated as the language evolved. Object.defineProperty is currently used for creating a property. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Scala ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person() {&lt;br /&gt;
// Private age variable, renamed to _age&lt;br /&gt;
private var _age = 0&lt;br /&gt;
var name = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Getter&lt;br /&gt;
def age = _age&lt;br /&gt;
&lt;br /&gt;
// Setter&lt;br /&gt;
def age_= (value:Int):Unit = _age = value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// We can invoke the setter as follows : &lt;br /&gt;
 can invoke the setter using the following: &lt;br /&gt;
person.age = 99&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Scala has some unconventional ideas that provide a solid, well thought out, and an abbreviated syntax to access object properties. This getter code simply defines a method called “age” and returns the “_age” variable. Scala doesn’t require the return keyword. The setter method name is “age_=”. The underscore is a special character in Scala and in this case, allows for a space in the method name which essentially makes the name “age =”. The parentheses and contents dictate the value and type that needs to be passed in. The “:Unit” code is equivalent to returning void. The remaining code is setting the “_age” variable to “value”.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Smalltalk===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     name                           &amp;quot;gets the value of name&amp;quot;&lt;br /&gt;
     name:aName              &amp;quot;sets name to the value of aName&amp;quot;&lt;br /&gt;
&lt;br /&gt;
     address                        &amp;quot;gets the value of address&amp;quot;&lt;br /&gt;
     address:anAddress     &amp;quot;sets anAddress to the value of anAddress&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The names of getter methods are usually the same as the name of the instance variable. A colon is added to the end of setter method name e.g. colour:&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Actionscript ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public var fullName:String;&lt;br /&gt;
private var _fullName:String;&lt;br /&gt;
&lt;br /&gt;
public function get fullName():String {&lt;br /&gt;
   return _fullName;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public function set fullName(_fullName:String):void {&lt;br /&gt;
   this._fullName = _fullName;&lt;br /&gt;
}&lt;br /&gt;
// getters&lt;br /&gt;
var1 = obj.fullName;&lt;br /&gt;
var2 = obj['fullName'];&lt;br /&gt;
// setters&lt;br /&gt;
obj.fullName = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
obj['fullName'] = &amp;quot;Yes&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getting or setting the property would call the getter and setter functions instead of accessing the property directly&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
==Getters and Setters from a different perspective==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
A fundamental precept of OO systems is that an object should not expose any of its implementation details. This way, you can change the implementation without changing the code that uses the object. It follows then that in OO systems you should avoid getter and setter functions since they mostly provide access to implementation details. For instance if you need change the return type of a gettr method from int to long to accommodate the big numbers you need to change all the invocations of that getter method. This negates the concept of [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html information hiding]. The same issue arises when you need to change the accessed field’s type. You also have to change the getter’s return type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Solution:	 &lt;br /&gt;
Maintainability is inversely proportionate to the amount of data that moves between objects. Thus, its best to minimize data movement as much as possible. The idea is to focus on what you will do rather than how you will do it. Don't ask for the information you need to do the work; ask the object that has the information to do the work for you. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
'''&lt;br /&gt;
Getters and setters provide a convenient method to access the instance variables. A lot of new languages have come up with the support for accessing getters and setters as instance variable reference which improves the readability of the code. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== References ==&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx Understanding properties in C#]&lt;br /&gt;
&amp;lt;li&amp;gt; [h ttp://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html why getters and setters are evil ]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set php5 OOPS tutorial]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://stefaanlippens.net/python_property_trick python-hiding attribute getters and setters behind standard attribute access]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 Object.defineProperty Function (JavaScript)]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Getters and Setters in Scala]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ ColdFusion 9 : Implicit/Generated CFC Methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.jamesward.com/2010/05/07/flex-and-java-differences-getters-setters/  Flex and Java Differences: Getters &amp;amp; Setters]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.touch-code-magazine.com/objective-c-properties/ Objective C properties]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Properties in Lua]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://docstore.mik.ua/orelly/perl4/porm/ch11_05.htm Creating getters and setters in perl ]&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011&amp;diff=48355</id>
		<title>CSC/ECE 517 Fall 2011</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011&amp;diff=48355"/>
		<updated>2011-09-09T00:41:59Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Link title]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1a ms]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1a cs]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1a ri]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1a lj]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1b sa]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1b ds]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1b tj]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1c cm]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1c sj]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1c ka]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1d sr]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 1e vs]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e aa]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1a sc]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e dm]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e an]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e sa]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e lm]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1g vn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1f rs]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1f sv]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1g jn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1h ps]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1e sm]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1i zf]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1g rn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1i cl]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1d ss]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1i lj]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2011/ch1 1h hs]]&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=48354</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1h hs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1h_hs&amp;diff=48354"/>
		<updated>2011-09-09T00:40:52Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: CSC/ECE 517 Fall 2010/ch1 1h hs&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
== What are getters and setters ==&lt;br /&gt;
''' &lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide getter and setter methods to access/modify object data. When writing new classes, it's a good idea to pay attention to the issue of access control. Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. Because of this naming convention, accessor methods are more often referred to as getter methods. This is a good programming practice, since the data fields are not directly accessible outside the class. Thus 'Getters' and 'Setters' allow us to effectively protect your data. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and setters as method calls ==&lt;br /&gt;
'''&lt;br /&gt;
For each variable, a get method will return its value and a set method will set the value. Here are the advantages of using getter and setter as method calls: &lt;br /&gt;
* Encapsulate the data from accidental / inadvertent modification. The private member variable is not part of the public interface of your class; only the public getter and setter methods are, and you are free to change their implementations without changing the public interface of your class&lt;br /&gt;
* If we decide that some action should be taken every time you change/access the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. For Instance, we can keep track of how many times a variable is accessed. &lt;br /&gt;
* Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and getters as variable references(properties) ==&lt;br /&gt;
'''&lt;br /&gt;
Properties are a robust way to handle object’s data. Properties support accessing the instance variables the same way as calling an instance method. A property communicates the idea of &amp;quot;I will make a value available to you, or accept a value from you.&amp;quot; It's not an implementation concept, it's an interface concept. Different languages follow specific syntax for adding a property to a class. Following are the advantages properties: &lt;br /&gt;
* the code is much cleaner when accessing a property when compared to Java or C++ which uses 2 separate methods for each instance variable. They are very useful in GUI programming which necessitates using a lot of fields for UI elements&lt;br /&gt;
* With properties we have fine-grained access control. For instance we can define a property as abstract thereby forcing the derived class to define that property. &lt;br /&gt;
* The main advantage of using properties is that if the internal implementation of getting or setting the property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class. This allows the interface of the object to stay the same even if the underlying implementation of getting and setting the property changes. &lt;br /&gt;
&lt;br /&gt;
Realizing the importance of getters and setters, popular IDEs like Eclipse, Visual studio has a built in mechanism to add getter and setter for a field or to create a property (in C#) for a given field.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples Languages that use getters and setters as method calls: ==&lt;br /&gt;
'''&lt;br /&gt;
'''&lt;br /&gt;
===C++===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
  int x_value;&lt;br /&gt;
&lt;br /&gt;
  public:&lt;br /&gt;
  // Getters&lt;br /&gt;
  int getx_value()&lt;br /&gt;
  {&lt;br /&gt;
      return x;&lt;br /&gt;
  }&lt;br /&gt;
  // Setters&lt;br /&gt;
  void setx_value( int x )&lt;br /&gt;
  {&lt;br /&gt;
      x_value = x;&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
void main()&lt;br /&gt;
{ &lt;br /&gt;
    A a;&lt;br /&gt;
    a.setx_value(5);&lt;br /&gt;
    cout&amp;lt;&amp;lt;a.getx_value();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
=== Java ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class BookStore&lt;br /&gt;
{ &lt;br /&gt;
  String title;&lt;br /&gt;
public String getTitle()&lt;br /&gt;
{&lt;br /&gt;
   return title;&lt;br /&gt;
}&lt;br /&gt;
// a setter method might check that the value that is being assigned to the variable is legal:&lt;br /&gt;
public void setTitle( String newTitle ) &lt;br /&gt;
{&lt;br /&gt;
  if ( newTitle == null )   // Don't allow null strings as titles!&lt;br /&gt;
     title = &amp;quot;(Untitled)&amp;quot;;  // Use an appropriate default value instead.&lt;br /&gt;
  else&lt;br /&gt;
     title = newTitle;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
     BookStore obj;&lt;br /&gt;
     obj. setTitle(&amp;quot;&amp;quot;);&lt;br /&gt;
     System.out.println(obj.getTitle());&lt;br /&gt;
}&lt;br /&gt;
Output:&lt;br /&gt;
(Untitled)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
=== Perl ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub setName &lt;br /&gt;
{&lt;br /&gt;
   my ( $self, $Name ) = @_;&lt;br /&gt;
   $self-&amp;gt;{_Name} = $Name if defined($Name);&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
sub getName &lt;br /&gt;
{&lt;br /&gt;
   my( $self ) = @_;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
# Now Set first name using helper function.&lt;br /&gt;
$object-&amp;gt;setName( &amp;quot;ABC&amp;quot; );&lt;br /&gt;
# Get name which is set using constructor.&lt;br /&gt;
$Name = $object-&amp;gt;getName();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Perl does not have private variables but we can still use the concept of getter, setter functions methods.&lt;br /&gt;
'''&lt;br /&gt;
=== ColdFusion === &lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Component Person&lt;br /&gt;
{&lt;br /&gt;
   property name&lt;br /&gt;
   property age;&lt;br /&gt;
   property city;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;!--- Once an object is created we can directly call the setters and getters for the properties as ---&amp;gt;&lt;br /&gt;
&amp;lt;cfscript&amp;gt;&lt;br /&gt;
   person = new Person();&lt;br /&gt;
   person.setName(&amp;quot;Brad&amp;quot;);&lt;br /&gt;
   person.setAge(46);&lt;br /&gt;
&lt;br /&gt;
   writeOutput(&amp;quot;Name : #person.getName()#&amp;quot;);&lt;br /&gt;
   writeOutput(&amp;quot;Age : #person.getAge()#&amp;quot;); &lt;br /&gt;
&amp;lt;/cfscript&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want to override the getter and setter method, you just need to define those methods in your CFC and ColdFusion will call our method instead of calling the implicit one.The implicit methods can also do some nice validation if you have given the ‘type’ for properties. For instance, if we define a property as numeric and try to provide a try to set a string as its value It will throw a nice error saying “The value cannot be converted to a numeric”.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples from Languages that use getters and setters as instance variable references:  ==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== C#: ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;class MyClass&lt;br /&gt;
{&lt;br /&gt;
      private int x;&lt;br /&gt;
      public int X&lt;br /&gt;
      {&lt;br /&gt;
            get&lt;br /&gt;
           {&lt;br /&gt;
             return x;&lt;br /&gt;
           }&lt;br /&gt;
          set&lt;br /&gt;
          {&lt;br /&gt;
             x = value;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
//Invocation&lt;br /&gt;
MyClass mc = new MyClass();&lt;br /&gt;
mc.X = 10;                   // calls set accessor of the property X, and pass 10 as value of the standard field 'value'.&lt;br /&gt;
Console.WriteLine(mc.X);     // displays 10. Calls the get accessor of the property X.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
C# also supports static properties, which belongs to the class rather than to the objects of the class. The properties of a Base class can be inherited to a Derived class and can be overridden polymorphicaly. &lt;br /&gt;
'''&lt;br /&gt;
===Lua===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class 'Test'&lt;br /&gt;
  function  Test : getLength()&lt;br /&gt;
   return # self.value&lt;br /&gt;
  end&lt;br /&gt;
  function  Test : setLength(newLength)&lt;br /&gt;
    for  i = self.length, newLength do&lt;br /&gt;
        table.insert(self.value, false )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
test =  Test({1, 2, 3, 4})&lt;br /&gt;
print(test.length)&lt;br /&gt;
self.length = property( Test.getLength, Test.setLength )    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getter and Setter functions can be implemented in Lua, which is similar to the properties concept in C#. This allows the functions to bind to a property that can be assigned and accessed as a value.&lt;br /&gt;
'''&lt;br /&gt;
===Ruby===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
    def initialize(lname, fname)&lt;br /&gt;
        @lname = lname&lt;br /&gt;
        @fname = fname&lt;br /&gt;
    end&lt;br /&gt;
attr_reader :lname // creates a getter method&lt;br /&gt;
    attr_writer :lname    // creates a setter method&lt;br /&gt;
    attr_accessor :fname // creates both getter and setter method&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x = Person.new(&amp;quot;ABC&amp;quot;, &amp;quot;XYZ&amp;quot;)&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
x.fname = &amp;quot;PQR&amp;quot;&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ruby simplifies the creation of getters and setters with a little metaprogramming and the methods attr, attr_reader, attr_writer, and attr_accessor, all from the Module class. By supplying the attr method, Ruby provides a way to acces the instances directly.&lt;br /&gt;
'''&lt;br /&gt;
===Php===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
class Customer&lt;br /&gt;
{&lt;br /&gt;
   public $name;&lt;br /&gt;
   private $data = array();&lt;br /&gt;
   public function __set($dt, $vl) &lt;br /&gt;
   {&lt;br /&gt;
      $this-&amp;gt;data[$dt] = $vl;&lt;br /&gt;
   }&lt;br /&gt;
   public function __get($dt) &lt;br /&gt;
   {&lt;br /&gt;
      return $this-&amp;gt;data[$dt];&lt;br /&gt;
   }&lt;br /&gt;
} &lt;br /&gt;
$c = new Customer();&lt;br /&gt;
$c-&amp;gt;name = “Sunil”; // $name is set because its public&lt;br /&gt;
$c-&amp;gt;email = “email@domain.com”; //assigning email@domain.com to the $email variable.&lt;br /&gt;
echo $c-&amp;gt;email;&lt;br /&gt;
?&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
An interesting aspect of php worth noting is that we can assign values to undefined variables. Because of the above limitation, PHP engine provides two magic methods __get() and __set(). __get() is used when value from an undefined variable is to be read and __set() is used when a value is to be assigned to a undefined variable of a class.In the above example when email@domain.com is assigned to the undefined variable $email, the magic method __set() is called. To this __set() method the name of the variable is passed into $dt variable of __set() method and the value i.e. email@domain.com is passed to $vl variable of the __set() method.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Objective C===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// public header file&lt;br /&gt;
@interface MyObject : NSObject&lt;br /&gt;
{&lt;br /&gt;
  NSString *make; &lt;br /&gt;
  NSString* model;&lt;br /&gt;
  NSNumber* vin;&lt;br /&gt;
}&lt;br /&gt;
@property (readonly, copy) NSString *language;&lt;br /&gt;
@property(readwrite, retain) NSString* make;&lt;br /&gt;
@property(readwrite, retain) NSString* model;&lt;br /&gt;
@property(readwrite, retain) NSNumber* vin;&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
#import &amp;quot;SimpleCar.h&amp;quot;&lt;br /&gt;
@implementation SimpleCar&lt;br /&gt;
@synthesize make, model, vin;&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Objective C we can define a property using @property directive. @synthesize will create automatically for you a setter and a getter methods for the property which becomes accessible during the run time.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Python ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DoubleIt(object):&lt;br /&gt;
   def _get_value(self):&lt;br /&gt;
       return self._value * 2&lt;br /&gt;
   def _set_value(self, value):&lt;br /&gt;
       self._value = value&lt;br /&gt;
   value = property(_get_value, _set_value)&lt;br /&gt;
&lt;br /&gt;
# Invocation &lt;br /&gt;
x = DoubleIt()&lt;br /&gt;
 &lt;br /&gt;
x.value = 10&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = 'foo'&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = [1,2,3]&lt;br /&gt;
print x.value&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here the output is doubled since the getter multiplies the value by 2&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Javascript ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function addDataProperty()&lt;br /&gt;
{&lt;br /&gt;
   var newLine = &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;;&lt;br /&gt;
   var obj = {};&lt;br /&gt;
  &lt;br /&gt;
   // Add a data property to the object.&lt;br /&gt;
   Object.defineProperty(obj, &amp;quot;newDataProperty&amp;quot;, &lt;br /&gt;
   {&lt;br /&gt;
       value: 101,&lt;br /&gt;
       writable: true,&lt;br /&gt;
       enumerable: true,&lt;br /&gt;
       configurable: true&lt;br /&gt;
   });&lt;br /&gt;
&lt;br /&gt;
   // Set the property value.&lt;br /&gt;
   obj.newDataProperty = 102;&lt;br /&gt;
   document.write(&amp;quot;Property value: &amp;quot; + obj.newDataProperty + newLine);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Javascript supports accessing getters and setters as variable as properties. Javascript originally used __defineGetter__ and __defineSetter__ syntax to define properties which is depricated as the language evolved. Object.defineProperty is currently used for creating a property. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Scala ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person() {&lt;br /&gt;
// Private age variable, renamed to _age&lt;br /&gt;
private var _age = 0&lt;br /&gt;
var name = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Getter&lt;br /&gt;
def age = _age&lt;br /&gt;
&lt;br /&gt;
// Setter&lt;br /&gt;
def age_= (value:Int):Unit = _age = value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// We can invoke the setter as follows : &lt;br /&gt;
 can invoke the setter using the following: &lt;br /&gt;
person.age = 99&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Scala has some unconventional ideas that provide a solid, well thought out, and an abbreviated syntax to access object properties. This getter code simply defines a method called “age” and returns the “_age” variable. Scala doesn’t require the return keyword. The setter method name is “age_=”. The underscore is a special character in Scala and in this case, allows for a space in the method name which essentially makes the name “age =”. The parentheses and contents dictate the value and type that needs to be passed in. The “:Unit” code is equivalent to returning void. The remaining code is setting the “_age” variable to “value”.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Smalltalk===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     name                           &amp;quot;gets the value of name&amp;quot;&lt;br /&gt;
     name:aName              &amp;quot;sets name to the value of aName&amp;quot;&lt;br /&gt;
&lt;br /&gt;
     address                        &amp;quot;gets the value of address&amp;quot;&lt;br /&gt;
     address:anAddress     &amp;quot;sets anAddress to the value of anAddress&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The names of getter methods are usually the same as the name of the instance variable. A colon is added to the end of setter method name e.g. colour:&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Actionscript ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public var fullName:String;&lt;br /&gt;
private var _fullName:String;&lt;br /&gt;
&lt;br /&gt;
public function get fullName():String {&lt;br /&gt;
   return _fullName;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public function set fullName(_fullName:String):void {&lt;br /&gt;
   this._fullName = _fullName;&lt;br /&gt;
}&lt;br /&gt;
// getters&lt;br /&gt;
var1 = obj.fullName;&lt;br /&gt;
var2 = obj['fullName'];&lt;br /&gt;
// setters&lt;br /&gt;
obj.fullName = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
obj['fullName'] = &amp;quot;Yes&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getting or setting the property would call the getter and setter functions instead of accessing the property directly&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
==Getters and Setters from a different perspective==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
A fundamental precept of OO systems is that an object should not expose any of its implementation details. This way, you can change the implementation without changing the code that uses the object. It follows then that in OO systems you should avoid getter and setter functions since they mostly provide access to implementation details. For instance if you need change the return type of a getter method from int to long to accommodate the big numbers you need to change all the invocations of that getter method. This negates the concept of information hiding. The same issue arises when you need to change the accessed field’s type. You also have to change the getter’s return type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Solution:	 &lt;br /&gt;
Maintainability is inversely proportionate to the amount of data that moves between objects. Thus, its best to minimize data movement as much as possible. The idea is to focus on what you will do rather than how you will do it. Don't ask for the information you need to do the work; ask the object that has the information to do the work for you. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
'''&lt;br /&gt;
Getters and setters provide a convenient method to access the instance variables. A lot of new languages have come up with the support for accessing getters and setters as instance variable reference which improves the readability of the code. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== References ==&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx Understanding properties in C#]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html why getters and setters are evil ]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set php5 OOPS tutorial]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://stefaanlippens.net/python_property_trick python-hiding attribute getters and setters behind standard attribute access]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 Object.defineProperty Function (JavaScript)]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Getters and Setters in Scala]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ ColdFusion 9 : Implicit/Generated CFC Methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.jamesward.com/2010/05/07/flex-and-java-differences-getters-setters/  Flex and Java Differences: Getters &amp;amp; Setters]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.touch-code-magazine.com/objective-c-properties/ Objective C properties]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Properties in Lua]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://docstore.mik.ua/orelly/perl4/porm/ch11_05.htm Creating getters and setters in perl ]&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Hudaiya&amp;diff=48316</id>
		<title>User:Hudaiya</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Hudaiya&amp;diff=48316"/>
		<updated>2011-09-09T00:19:17Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: CSC/ECE 517 Fall 2010/ch1 1h hs&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
== What are getters and setters ==&lt;br /&gt;
''' &lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide getter and setter methods to access/modify object data. When writing new classes, it's a good idea to pay attention to the issue of access control. Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. Because of this naming convention, accessor methods are more often referred to as getter methods. This is a good programming practice, since the data fields are not directly accessible outside the class. Thus 'Getters' and 'Setters' allow us to effectively protect your data. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and setters as method calls ==&lt;br /&gt;
'''&lt;br /&gt;
For each variable, a get method will return its value and a set method will set the value. Here are the advantages of using getter and setter as method calls: &lt;br /&gt;
* Encapsulate the data from accidental / inadvertent modification. The private member variable is not part of the public interface of your class; only the public getter and setter methods are, and you are free to change their implementations without changing the public interface of your class&lt;br /&gt;
* If we decide that some action should be taken every time you change/access the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. For Instance, we can keep track of how many times a variable is accessed. &lt;br /&gt;
* Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and getters as variable references(properties) ==&lt;br /&gt;
'''&lt;br /&gt;
Properties are a robust way to handle object’s data. Properties support accessing the instance variables the same way as calling an instance method. A property communicates the idea of &amp;quot;I will make a value available to you, or accept a value from you.&amp;quot; It's not an implementation concept, it's an interface concept. Different languages follow specific syntax for adding a property to a class. Following are the advantages properties: &lt;br /&gt;
* the code is much cleaner when accessing a property when compared to Java or C++ which uses 2 separate methods for each instance variable. They are very useful in GUI programming which necessitates using a lot of fields for UI elements&lt;br /&gt;
* With properties we have fine-grained access control. For instance we can define a property as abstract thereby forcing the derived class to define that property. &lt;br /&gt;
* The main advantage of using properties is that if the internal implementation of getting or setting the property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class. This allows the interface of the object to stay the same even if the underlying implementation of getting and setting the property changes. &lt;br /&gt;
&lt;br /&gt;
Realizing the importance of getters and setters, popular IDEs like Eclipse, Visual studio has a built in mechanism to add getter and setter for a field or to create a property (in C#) for a given field.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples Languages that use getters and setters as method calls: ==&lt;br /&gt;
'''&lt;br /&gt;
'''&lt;br /&gt;
===C++===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
  int x_value;&lt;br /&gt;
&lt;br /&gt;
  public:&lt;br /&gt;
  // Getters&lt;br /&gt;
  int getx_value()&lt;br /&gt;
  {&lt;br /&gt;
      return x;&lt;br /&gt;
  }&lt;br /&gt;
  // Setters&lt;br /&gt;
  void setx_value( int x )&lt;br /&gt;
  {&lt;br /&gt;
      x_value = x;&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
void main()&lt;br /&gt;
{ &lt;br /&gt;
    A a;&lt;br /&gt;
    a.setx_value(5);&lt;br /&gt;
    cout&amp;lt;&amp;lt;a.getx_value();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
=== Java ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class BookStore&lt;br /&gt;
{ &lt;br /&gt;
  String title;&lt;br /&gt;
public String getTitle()&lt;br /&gt;
{&lt;br /&gt;
   return title;&lt;br /&gt;
}&lt;br /&gt;
// a setter method might check that the value that is being assigned to the variable is legal:&lt;br /&gt;
public void setTitle( String newTitle ) &lt;br /&gt;
{&lt;br /&gt;
  if ( newTitle == null )   // Don't allow null strings as titles!&lt;br /&gt;
     title = &amp;quot;(Untitled)&amp;quot;;  // Use an appropriate default value instead.&lt;br /&gt;
  else&lt;br /&gt;
     title = newTitle;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
     BookStore obj;&lt;br /&gt;
     obj. setTitle(&amp;quot;&amp;quot;);&lt;br /&gt;
     System.out.println(obj.getTitle());&lt;br /&gt;
}&lt;br /&gt;
Output:&lt;br /&gt;
(Untitled)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
=== Perl ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub setName &lt;br /&gt;
{&lt;br /&gt;
   my ( $self, $Name ) = @_;&lt;br /&gt;
   $self-&amp;gt;{_Name} = $Name if defined($Name);&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
sub getName &lt;br /&gt;
{&lt;br /&gt;
   my( $self ) = @_;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
# Now Set first name using helper function.&lt;br /&gt;
$object-&amp;gt;setName( &amp;quot;ABC&amp;quot; );&lt;br /&gt;
# Get name which is set using constructor.&lt;br /&gt;
$Name = $object-&amp;gt;getName();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Perl does not have private variables but we can still use the concept of getter, setter functions methods.&lt;br /&gt;
'''&lt;br /&gt;
=== ColdFusion === &lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Component Person&lt;br /&gt;
{&lt;br /&gt;
   property name&lt;br /&gt;
   property age;&lt;br /&gt;
   property city;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;!--- Once an object is created we can directly call the setters and getters for the properties as ---&amp;gt;&lt;br /&gt;
&amp;lt;cfscript&amp;gt;&lt;br /&gt;
   person = new Person();&lt;br /&gt;
   person.setName(&amp;quot;Brad&amp;quot;);&lt;br /&gt;
   person.setAge(46);&lt;br /&gt;
&lt;br /&gt;
   writeOutput(&amp;quot;Name : #person.getName()#&amp;quot;);&lt;br /&gt;
   writeOutput(&amp;quot;Age : #person.getAge()#&amp;quot;); &lt;br /&gt;
&amp;lt;/cfscript&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want to override the getter and setter method, you just need to define those methods in your CFC and ColdFusion will call our method instead of calling the implicit one.The implicit methods can also do some nice validation if you have given the ‘type’ for properties. For instance, if we define a property as numeric and try to provide a try to set a string as its value It will throw a nice error saying “The value cannot be converted to a numeric”.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples from Languages that use getters and setters as instance variable references:  ==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== C#: ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;class MyClass&lt;br /&gt;
{&lt;br /&gt;
      private int x;&lt;br /&gt;
      public int X&lt;br /&gt;
      {&lt;br /&gt;
            get&lt;br /&gt;
           {&lt;br /&gt;
             return x;&lt;br /&gt;
           }&lt;br /&gt;
          set&lt;br /&gt;
          {&lt;br /&gt;
             x = value;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
//Invocation&lt;br /&gt;
MyClass mc = new MyClass();&lt;br /&gt;
mc.X = 10;                   // calls set accessor of the property X, and pass 10 as value of the standard field 'value'.&lt;br /&gt;
Console.WriteLine(mc.X);     // displays 10. Calls the get accessor of the property X.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
C# also supports static properties, which belongs to the class rather than to the objects of the class. The properties of a Base class can be inherited to a Derived class and can be overridden polymorphicaly. &lt;br /&gt;
'''&lt;br /&gt;
===Lua===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class 'Test'&lt;br /&gt;
  function  Test : getLength()&lt;br /&gt;
   return # self.value&lt;br /&gt;
  end&lt;br /&gt;
  function  Test : setLength(newLength)&lt;br /&gt;
    for  i = self.length, newLength do&lt;br /&gt;
        table.insert(self.value, false )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
test =  Test({1, 2, 3, 4})&lt;br /&gt;
print(test.length)&lt;br /&gt;
self.length = property( Test.getLength, Test.setLength )    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getter and Setter functions can be implemented in Lua, which is similar to the properties concept in C#. This allows the functions to bind to a property that can be assigned and accessed as a value.&lt;br /&gt;
'''&lt;br /&gt;
===Ruby===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
    def initialize(lname, fname)&lt;br /&gt;
        @lname = lname&lt;br /&gt;
        @fname = fname&lt;br /&gt;
    end&lt;br /&gt;
attr_reader :lname // creates a getter method&lt;br /&gt;
    attr_writer :lname    // creates a setter method&lt;br /&gt;
    attr_accessor :fname // creates both getter and setter method&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x = Person.new(&amp;quot;ABC&amp;quot;, &amp;quot;XYZ&amp;quot;)&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
x.fname = &amp;quot;PQR&amp;quot;&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ruby simplifies the creation of getters and setters with a little metaprogramming and the methods attr, attr_reader, attr_writer, and attr_accessor, all from the Module class. By supplying the attr method, Ruby provides a way to acces the instances directly.&lt;br /&gt;
'''&lt;br /&gt;
===Php===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
class Customer&lt;br /&gt;
{&lt;br /&gt;
   public $name;&lt;br /&gt;
   private $data = array();&lt;br /&gt;
   public function __set($dt, $vl) &lt;br /&gt;
   {&lt;br /&gt;
      $this-&amp;gt;data[$dt] = $vl;&lt;br /&gt;
   }&lt;br /&gt;
   public function __get($dt) &lt;br /&gt;
   {&lt;br /&gt;
      return $this-&amp;gt;data[$dt];&lt;br /&gt;
   }&lt;br /&gt;
} &lt;br /&gt;
$c = new Customer();&lt;br /&gt;
$c-&amp;gt;name = “Sunil”; // $name is set because its public&lt;br /&gt;
$c-&amp;gt;email = “email@domain.com”; //assigning email@domain.com to the $email variable.&lt;br /&gt;
echo $c-&amp;gt;email;&lt;br /&gt;
?&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
An interesting aspect of php worth noting is that we can assign values to undefined variables. Because of the above limitation, PHP engine provides two magic methods __get() and __set(). __get() is used when value from an undefined variable is to be read and __set() is used when a value is to be assigned to a undefined variable of a class.In the above example when email@domain.com is assigned to the undefined variable $email, the magic method __set() is called. To this __set() method the name of the variable is passed into $dt variable of __set() method and the value i.e. email@domain.com is passed to $vl variable of the __set() method.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Objective C===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// public header file&lt;br /&gt;
@interface MyObject : NSObject&lt;br /&gt;
{&lt;br /&gt;
  NSString *make; &lt;br /&gt;
  NSString* model;&lt;br /&gt;
  NSNumber* vin;&lt;br /&gt;
}&lt;br /&gt;
@property (readonly, copy) NSString *language;&lt;br /&gt;
@property(readwrite, retain) NSString* make;&lt;br /&gt;
@property(readwrite, retain) NSString* model;&lt;br /&gt;
@property(readwrite, retain) NSNumber* vin;&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
#import &amp;quot;SimpleCar.h&amp;quot;&lt;br /&gt;
@implementation SimpleCar&lt;br /&gt;
@synthesize make, model, vin;&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Objective C we can define a property using @property directive. @synthesize will create automatically for you a setter and a getter methods for the property which becomes accessible during the run time.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Python ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DoubleIt(object):&lt;br /&gt;
   def _get_value(self):&lt;br /&gt;
       return self._value * 2&lt;br /&gt;
   def _set_value(self, value):&lt;br /&gt;
       self._value = value&lt;br /&gt;
   value = property(_get_value, _set_value)&lt;br /&gt;
&lt;br /&gt;
# Invocation &lt;br /&gt;
x = DoubleIt()&lt;br /&gt;
 &lt;br /&gt;
x.value = 10&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = 'foo'&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = [1,2,3]&lt;br /&gt;
print x.value&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here the output is doubled since the getter multiplies the value by 2&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Javascript ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function addDataProperty()&lt;br /&gt;
{&lt;br /&gt;
   var newLine = &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;;&lt;br /&gt;
   var obj = {};&lt;br /&gt;
  &lt;br /&gt;
   // Add a data property to the object.&lt;br /&gt;
   Object.defineProperty(obj, &amp;quot;newDataProperty&amp;quot;, &lt;br /&gt;
   {&lt;br /&gt;
       value: 101,&lt;br /&gt;
       writable: true,&lt;br /&gt;
       enumerable: true,&lt;br /&gt;
       configurable: true&lt;br /&gt;
   });&lt;br /&gt;
&lt;br /&gt;
   // Set the property value.&lt;br /&gt;
   obj.newDataProperty = 102;&lt;br /&gt;
   document.write(&amp;quot;Property value: &amp;quot; + obj.newDataProperty + newLine);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Javascript supports accessing getters and setters as variable as properties. Javascript originally used __defineGetter__ and __defineSetter__ syntax to define properties which is depricated as the language evolved. Object.defineProperty is currently used for creating a property. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Scala ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person() {&lt;br /&gt;
// Private age variable, renamed to _age&lt;br /&gt;
private var _age = 0&lt;br /&gt;
var name = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Getter&lt;br /&gt;
def age = _age&lt;br /&gt;
&lt;br /&gt;
// Setter&lt;br /&gt;
def age_= (value:Int):Unit = _age = value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// We can invoke the setter as follows : &lt;br /&gt;
 can invoke the setter using the following: &lt;br /&gt;
person.age = 99&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Scala has some unconventional ideas that provide a solid, well thought out, and an abbreviated syntax to access object properties. This getter code simply defines a method called “age” and returns the “_age” variable. Scala doesn’t require the return keyword. The setter method name is “age_=”. The underscore is a special character in Scala and in this case, allows for a space in the method name which essentially makes the name “age =”. The parentheses and contents dictate the value and type that needs to be passed in. The “:Unit” code is equivalent to returning void. The remaining code is setting the “_age” variable to “value”.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Smalltalk===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     name                           &amp;quot;gets the value of name&amp;quot;&lt;br /&gt;
     name:aName              &amp;quot;sets name to the value of aName&amp;quot;&lt;br /&gt;
&lt;br /&gt;
     address                        &amp;quot;gets the value of address&amp;quot;&lt;br /&gt;
     address:anAddress     &amp;quot;sets anAddress to the value of anAddress&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The names of getter methods are usually the same as the name of the instance variable. A colon is added to the end of setter method name e.g. colour:&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Actionscript ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public var fullName:String;&lt;br /&gt;
private var _fullName:String;&lt;br /&gt;
&lt;br /&gt;
public function get fullName():String {&lt;br /&gt;
   return _fullName;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public function set fullName(_fullName:String):void {&lt;br /&gt;
   this._fullName = _fullName;&lt;br /&gt;
}&lt;br /&gt;
// getters&lt;br /&gt;
var1 = obj.fullName;&lt;br /&gt;
var2 = obj['fullName'];&lt;br /&gt;
// setters&lt;br /&gt;
obj.fullName = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
obj['fullName'] = &amp;quot;Yes&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getting or setting the property would call the getter and setter functions instead of accessing the property directly&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
==Getters and Setters from a different perspective==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
A fundamental precept of OO systems is that an object should not expose any of its implementation details. This way, you can change the implementation without changing the code that uses the object. It follows then that in OO systems you should avoid getter and setter functions since they mostly provide access to implementation details. For instance if you need change the return type of a getter method from int to long to accommodate the big numbers you need to change all the invocations of that getter method. This negates the concept of information hiding. The same issue arises when you need to change the accessed field’s type. You also have to change the getter’s return type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Solution:	 &lt;br /&gt;
Maintainability is inversely proportionate to the amount of data that moves between objects. Thus, its best to minimize data movement as much as possible. The idea is to focus on what you will do rather than how you will do it. Don't ask for the information you need to do the work; ask the object that has the information to do the work for you. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
'''&lt;br /&gt;
Getters and setters provide a convenient method to access the instance variables. A lot of new languages have come up with the support for accessing getters and setters as instance variable reference which improves the readability of the code. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== References ==&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx Understanding properties in C#]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html why getters and setters are evil ]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set php5 OOPS tutorial]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://stefaanlippens.net/python_property_trick python-hiding attribute getters and setters behind standard attribute access]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 Object.defineProperty Function (JavaScript)]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Getters and Setters in Scala]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ ColdFusion 9 : Implicit/Generated CFC Methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.jamesward.com/2010/05/07/flex-and-java-differences-getters-setters/  Flex and Java Differences: Getters &amp;amp; Setters]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.touch-code-magazine.com/objective-c-properties/ Objective C properties]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Properties in Lua]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://docstore.mik.ua/orelly/perl4/porm/ch11_05.htm Creating getters and setters in perl ]&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Hudaiya&amp;diff=48294</id>
		<title>User:Hudaiya</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Hudaiya&amp;diff=48294"/>
		<updated>2011-09-09T00:11:40Z</updated>

		<summary type="html">&lt;p&gt;Hudaiya: CSC/ECE 517 Fall 2011/ch1 1h hs&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''&lt;br /&gt;
== What are getters and setters ==&lt;br /&gt;
''' &lt;br /&gt;
Object-oriented languages have the concept of security of data to prevent a programmer from changing an object data directly and so provide getter and setter methods to access/modify object data. When writing new classes, it's a good idea to pay attention to the issue of access control. Usually inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields. Because of this naming convention, accessor methods are more often referred to as getter methods. This is a good programming practice, since the data fields are not directly accessible outside the class. Thus 'Getters' and 'Setters' allow us to effectively protect your data. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and setters as method calls ==&lt;br /&gt;
'''&lt;br /&gt;
For each variable, a get method will return its value and a set method will set the value. Here are the advantages of using getter and setter as method calls: &lt;br /&gt;
* Encapsulate the data from accidental / inadvertent modification. The private member variable is not part of the public interface of your class; only the public getter and setter methods are, and you are free to change their implementations without changing the public interface of your class&lt;br /&gt;
* If we decide that some action should be taken every time you change/access the value of a particular variable, you only need to edit the set method instead of looking for every place you change the variable. For Instance, we can keep track of how many times a variable is accessed. &lt;br /&gt;
* Another reason is that a person using the code can look for all methods starting with get or set instead of looking for specific variables that they need to remember.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Advantages of getters and getters as variable references(properties) ==&lt;br /&gt;
'''&lt;br /&gt;
Properties are a robust way to handle object’s data. Properties support accessing the instance variables the same way as calling an instance method. A property communicates the idea of &amp;quot;I will make a value available to you, or accept a value from you.&amp;quot; It's not an implementation concept, it's an interface concept. Different languages follow specific syntax for adding a property to a class. Following are the advantages properties: &lt;br /&gt;
* the code is much cleaner when accessing a property when compared to Java or C++ which uses 2 separate methods for each instance variable. They are very useful in GUI programming which necessitates using a lot of fields for UI elements&lt;br /&gt;
* With properties we have fine-grained access control. For instance we can define a property as abstract thereby forcing the derived class to define that property. &lt;br /&gt;
* The main advantage of using properties is that if the internal implementation of getting or setting the property needs to change, then the class can be adapted to have getter and setter functions without changing the external interface of the class. This allows the interface of the object to stay the same even if the underlying implementation of getting and setting the property changes. &lt;br /&gt;
&lt;br /&gt;
Realizing the importance of getters and setters, popular IDEs like Eclipse, Visual studio has a built in mechanism to add getter and setter for a field or to create a property (in C#) for a given field.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples Languages that use getters and setters as method calls: ==&lt;br /&gt;
'''&lt;br /&gt;
'''&lt;br /&gt;
===C++===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
  int x_value;&lt;br /&gt;
&lt;br /&gt;
  public:&lt;br /&gt;
  // Getters&lt;br /&gt;
  int getx_value()&lt;br /&gt;
  {&lt;br /&gt;
      return x;&lt;br /&gt;
  }&lt;br /&gt;
  // Setters&lt;br /&gt;
  void setx_value( int x )&lt;br /&gt;
  {&lt;br /&gt;
      x_value = x;&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
void main()&lt;br /&gt;
{ &lt;br /&gt;
    A a;&lt;br /&gt;
    a.setx_value(5);&lt;br /&gt;
    cout&amp;lt;&amp;lt;a.getx_value();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
=== Perl ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sub setName &lt;br /&gt;
{&lt;br /&gt;
   my ( $self, $Name ) = @_;&lt;br /&gt;
   $self-&amp;gt;{_Name} = $Name if defined($Name);&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
sub getName &lt;br /&gt;
{&lt;br /&gt;
   my( $self ) = @_;&lt;br /&gt;
   return $self-&amp;gt;{_Name};&lt;br /&gt;
}&lt;br /&gt;
# Now Set first name using helper function.&lt;br /&gt;
$object-&amp;gt;setName( &amp;quot;ABC&amp;quot; );&lt;br /&gt;
# Get name which is set using constructor.&lt;br /&gt;
$Name = $object-&amp;gt;getName();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Perl does not have private variables but we can still use the concept of getter, setter functions methods.&lt;br /&gt;
'''&lt;br /&gt;
=== ColdFusion === &lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Component Person&lt;br /&gt;
{&lt;br /&gt;
   property name&lt;br /&gt;
   property age;&lt;br /&gt;
   property city;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;!--- Once an object is created we can directly call the setters and getters for the properties as ---&amp;gt;&lt;br /&gt;
&amp;lt;cfscript&amp;gt;&lt;br /&gt;
   person = new Person();&lt;br /&gt;
   person.setName(&amp;quot;Brad&amp;quot;);&lt;br /&gt;
   person.setAge(46);&lt;br /&gt;
&lt;br /&gt;
   writeOutput(&amp;quot;Name : #person.getName()#&amp;quot;);&lt;br /&gt;
   writeOutput(&amp;quot;Age : #person.getAge()#&amp;quot;); &lt;br /&gt;
&amp;lt;/cfscript&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want to override the getter and setter method, you just need to define those methods in your CFC and ColdFusion will call our method instead of calling the implicit one.The implicit methods can also do some nice validation if you have given the ‘type’ for properties. For instance, if we define a property as numeric and try to provide a try to set a string as its value It will throw a nice error saying “The value cannot be converted to a numeric”.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Examples from Languages that use getters and setters as instance variable references:  ==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== C#: ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;class MyClass&lt;br /&gt;
{&lt;br /&gt;
      private int x;&lt;br /&gt;
      public int X&lt;br /&gt;
      {&lt;br /&gt;
            get&lt;br /&gt;
           {&lt;br /&gt;
             return x;&lt;br /&gt;
           }&lt;br /&gt;
          set&lt;br /&gt;
          {&lt;br /&gt;
             x = value;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
//Invocation&lt;br /&gt;
MyClass mc = new MyClass();&lt;br /&gt;
mc.X = 10;                   // calls set accessor of the property X, and pass 10 as value of the standard field 'value'.&lt;br /&gt;
Console.WriteLine(mc.X);     // displays 10. Calls the get accessor of the property X.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
C# also supports static properties, which belongs to the class rather than to the objects of the class. The properties of a Base class can be inherited to a Derived class and can be overridden polymorphicaly. &lt;br /&gt;
'''&lt;br /&gt;
===Lua===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class 'Test'&lt;br /&gt;
  function  Test : getLength()&lt;br /&gt;
   return # self.value&lt;br /&gt;
  end&lt;br /&gt;
  function  Test : setLength(newLength)&lt;br /&gt;
    for  i = self.length, newLength do&lt;br /&gt;
        table.insert(self.value, false )&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
test =  Test({1, 2, 3, 4})&lt;br /&gt;
print(test.length)&lt;br /&gt;
self.length = property( Test.getLength, Test.setLength )    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getter and Setter functions can be implemented in Lua, which is similar to the properties concept in C#. This allows the functions to bind to a property that can be assigned and accessed as a value.&lt;br /&gt;
'''&lt;br /&gt;
===Ruby===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person&lt;br /&gt;
    def initialize(lname, fname)&lt;br /&gt;
        @lname = lname&lt;br /&gt;
        @fname = fname&lt;br /&gt;
    end&lt;br /&gt;
attr_reader :lname // creates a getter method&lt;br /&gt;
    attr_writer :lname    // creates a setter method&lt;br /&gt;
    attr_accessor :fname // creates both getter and setter method&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
x = Person.new(&amp;quot;ABC&amp;quot;, &amp;quot;XYZ&amp;quot;)&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
x.fname = &amp;quot;PQR&amp;quot;&lt;br /&gt;
print &amp;quot;My name is &amp;quot;, x.fname, &amp;quot; &amp;quot;, x.lname, &amp;quot;.\n&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Ruby simplifies the creation of getters and setters with a little metaprogramming and the methods attr, attr_reader, attr_writer, and attr_accessor, all from the Module class. By supplying the attr method, Ruby provides a way to acces the instances directly.&lt;br /&gt;
'''&lt;br /&gt;
===Php===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;?php&lt;br /&gt;
class Customer&lt;br /&gt;
{&lt;br /&gt;
   public $name;&lt;br /&gt;
   private $data = array();&lt;br /&gt;
   public function __set($dt, $vl) &lt;br /&gt;
   {&lt;br /&gt;
      $this-&amp;gt;data[$dt] = $vl;&lt;br /&gt;
   }&lt;br /&gt;
   public function __get($dt) &lt;br /&gt;
   {&lt;br /&gt;
      return $this-&amp;gt;data[$dt];&lt;br /&gt;
   }&lt;br /&gt;
} &lt;br /&gt;
$c = new Customer();&lt;br /&gt;
$c-&amp;gt;name = “Sunil”; // $name is set because its public&lt;br /&gt;
$c-&amp;gt;email = “email@domain.com”; //assigning email@domain.com to the $email variable.&lt;br /&gt;
echo $c-&amp;gt;email;&lt;br /&gt;
?&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
An interesting aspect of php worth noting is that we can assign values to undefined variables. Because of the above limitation, PHP engine provides two magic methods __get() and __set(). __get() is used when value from an undefined variable is to be read and __set() is used when a value is to be assigned to a undefined variable of a class.In the above example when email@domain.com is assigned to the undefined variable $email, the magic method __set() is called. To this __set() method the name of the variable is passed into $dt variable of __set() method and the value i.e. email@domain.com is passed to $vl variable of the __set() method.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Objective C===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// public header file&lt;br /&gt;
@interface MyObject : NSObject&lt;br /&gt;
{&lt;br /&gt;
  NSString *make; &lt;br /&gt;
  NSString* model;&lt;br /&gt;
  NSNumber* vin;&lt;br /&gt;
}&lt;br /&gt;
@property (readonly, copy) NSString *language;&lt;br /&gt;
@property(readwrite, retain) NSString* make;&lt;br /&gt;
@property(readwrite, retain) NSString* model;&lt;br /&gt;
@property(readwrite, retain) NSNumber* vin;&lt;br /&gt;
@end&lt;br /&gt;
&lt;br /&gt;
#import &amp;quot;SimpleCar.h&amp;quot;&lt;br /&gt;
@implementation SimpleCar&lt;br /&gt;
@synthesize make, model, vin;&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Objective C we can define a property using @property directive. @synthesize will create automatically for you a setter and a getter methods for the property which becomes accessible during the run time.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Python ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class DoubleIt(object):&lt;br /&gt;
   def _get_value(self):&lt;br /&gt;
       return self._value * 2&lt;br /&gt;
   def _set_value(self, value):&lt;br /&gt;
       self._value = value&lt;br /&gt;
   value = property(_get_value, _set_value)&lt;br /&gt;
&lt;br /&gt;
# Invocation &lt;br /&gt;
x = DoubleIt()&lt;br /&gt;
 &lt;br /&gt;
x.value = 10&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = 'foo'&lt;br /&gt;
print x.value&lt;br /&gt;
 &lt;br /&gt;
x.value = [1,2,3]&lt;br /&gt;
print x.value&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here the output is doubled since the getter multiplies the value by 2&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Javascript ===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function addDataProperty()&lt;br /&gt;
{&lt;br /&gt;
   var newLine = &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;;&lt;br /&gt;
   var obj = {};&lt;br /&gt;
  &lt;br /&gt;
   // Add a data property to the object.&lt;br /&gt;
   Object.defineProperty(obj, &amp;quot;newDataProperty&amp;quot;, &lt;br /&gt;
   {&lt;br /&gt;
       value: 101,&lt;br /&gt;
       writable: true,&lt;br /&gt;
       enumerable: true,&lt;br /&gt;
       configurable: true&lt;br /&gt;
   });&lt;br /&gt;
&lt;br /&gt;
   // Set the property value.&lt;br /&gt;
   obj.newDataProperty = 102;&lt;br /&gt;
   document.write(&amp;quot;Property value: &amp;quot; + obj.newDataProperty + newLine);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Javascript supports accessing getters and setters as variable as properties. Javascript originally used __defineGetter__ and __defineSetter__ syntax to define properties which is depricated as the language evolved. Object.defineProperty is currently used for creating a property. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Scala ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person() {&lt;br /&gt;
// Private age variable, renamed to _age&lt;br /&gt;
private var _age = 0&lt;br /&gt;
var name = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
// Getter&lt;br /&gt;
def age = _age&lt;br /&gt;
&lt;br /&gt;
// Setter&lt;br /&gt;
def age_= (value:Int):Unit = _age = value&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// We can invoke the setter as follows : &lt;br /&gt;
 can invoke the setter using the following: &lt;br /&gt;
person.age = 99&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Scala has some unconventional ideas that provide a solid, well thought out, and an abbreviated syntax to access object properties. This getter code simply defines a method called “age” and returns the “_age” variable. Scala doesn’t require the return keyword. The setter method name is “age_=”. The underscore is a special character in Scala and in this case, allows for a space in the method name which essentially makes the name “age =”. The parentheses and contents dictate the value and type that needs to be passed in. The “:Unit” code is equivalent to returning void. The remaining code is setting the “_age” variable to “value”.&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
===Smalltalk===&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     name                           &amp;quot;gets the value of name&amp;quot;&lt;br /&gt;
     name:aName              &amp;quot;sets name to the value of aName&amp;quot;&lt;br /&gt;
&lt;br /&gt;
     address                        &amp;quot;gets the value of address&amp;quot;&lt;br /&gt;
     address:anAddress     &amp;quot;sets anAddress to the value of anAddress&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The names of getter methods are usually the same as the name of the instance variable. A colon is added to the end of setter method name e.g. colour:&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
=== Actionscript ===&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public var fullName:String;&lt;br /&gt;
private var _fullName:String;&lt;br /&gt;
&lt;br /&gt;
public function get fullName():String {&lt;br /&gt;
   return _fullName;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public function set fullName(_fullName:String):void {&lt;br /&gt;
   this._fullName = _fullName;&lt;br /&gt;
}&lt;br /&gt;
// getters&lt;br /&gt;
var1 = obj.fullName;&lt;br /&gt;
var2 = obj['fullName'];&lt;br /&gt;
// setters&lt;br /&gt;
obj.fullName = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
obj['fullName'] = &amp;quot;Yes&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Getting or setting the property would call the getter and setter functions instead of accessing the property directly&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
==Getters and Setters from a different perspective==&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
A fundamental precept of OO systems is that an object should not expose any of its implementation details. This way, you can change the implementation without changing the code that uses the object. It follows then that in OO systems you should avoid getter and setter functions since they mostly provide access to implementation details. For instance if you need change the return type of a getter method from int to long to accommodate the big numbers you need to change all the invocations of that getter method. This negates the concept of information hiding. The same issue arises when you need to change the accessed field’s type. You also have to change the getter’s return type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Solution:	 &lt;br /&gt;
Maintainability is inversely proportionate to the amount of data that moves between objects. Thus, its best to minimize data movement as much as possible. The idea is to focus on what you will do rather than how you will do it. Don't ask for the information you need to do the work; ask the object that has the information to do the work for you. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
'''&lt;br /&gt;
Getters and setters provide a convenient method to access the instance variables. A lot of new languages have come up with the support for accessing getters and setters as instance variable reference which improves the readability of the code. &lt;br /&gt;
&lt;br /&gt;
'''&lt;br /&gt;
== References ==&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx Understanding properties in C#]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html why getters and setters are evil ]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.sunilb.com/php/php5-oops-tutorial-__get-and-__set php5 OOPS tutorial]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://stefaanlippens.net/python_property_trick python-hiding attribute getters and setters behind standard attribute access]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://msdn.microsoft.com/en-us/library/dd548687%28v=vs.94%29.aspx#Y2204 Object.defineProperty Function (JavaScript)]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.dustinmartin.net/2009/10/getters-and-setters-in-scala/ Getters and Setters in Scala]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.rupeshk.org/blog/index.php/2009/07/coldfusion-9-implicitgenerated-cfc-methods/ ColdFusion 9 : Implicit/Generated CFC Methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.jamesward.com/2010/05/07/flex-and-java-differences-getters-setters/  Flex and Java Differences: Getters &amp;amp; Setters]&lt;br /&gt;
&amp;lt;li&amp;gt; [http://www.touch-code-magazine.com/objective-c-properties/ Objective C properties]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.tutorials4u.com/smalltalk/smalltalk-tutorial-01.htm#Setter Smalltalk methods]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.gamedev.net/topic/590548-luabind-properties-within-lua/ Properties in Lua]&lt;br /&gt;
&amp;lt;li&amp;gt;[http://docstore.mik.ua/orelly/perl4/porm/ch11_05.htm Creating getters and setters in perl ]&lt;/div&gt;</summary>
		<author><name>Hudaiya</name></author>
	</entry>
</feed>