Encapsulate Field

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
m (Reverted edits by Ebybymic (Talk); changed back to last version by Johannes Pagwiwoko)
 
Line 1: Line 1:
----
 
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
 
----
 
=[http://ehyloxame.co.cc Under Construction! Please Visit Reserve Page. Page Will Be Available Shortly]=
 
----
 
=[http://ehyloxame.co.cc CLICK HERE]=
 
----
 
</div>
 
 
This is a common refactoring method suggested by [[Martin Fowler]]'s in his [[Refactoring]] book. Encapsulate Field states that we should ''Replace public fields (instance variables) with private fields and provide public accessors.''  
 
This is a common refactoring method suggested by [[Martin Fowler]]'s in his [[Refactoring]] book. Encapsulate Field states that we should ''Replace public fields (instance variables) with private fields and provide public accessors.''  
  

Latest revision as of 03:18, 25 November 2010

This is a common refactoring method suggested by Martin Fowler's in his Refactoring book. Encapsulate Field states that we should Replace public fields (instance variables) with private fields and provide public accessors.

For instance, if we have a particular code/class like this:

 public class Person {
   public String name;
 }

After we refactor the class using Encapsulate Field, we will have:

 public class Person {
   private String name;
   
   public void setName(String newName) {
       name = newName;
   }
   
   public String getName() {
       return name;
   }
 }
Personal tools