Difference between revisions of "Encapsulation"
From Logic Wiki
m |
m (1 revision imported) |
(No difference)
| |
Latest revision as of 14:27, 9 May 2016
Closing some part of the classes to object users. By using private access modifier some variables can be closed to outer world.
property usage is an example of encapsulation
public class Computer
{
private ushort ram;
public ushort Ram
{
get {return ram;}
set {ram=value;}
}
}
Here in this example ram is encapsulated and access is restricted.
Advantages
- This allows the private data of an object to be hidden from the rest of the program
- Keep code clean
- Easy to understand
- allows classes to be reused in other programs