Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
What is Encapsulation & how it is implement in my project
Posted 17-Dec-12 17:59pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Definition - What does Encapsulation mean?
 
Encapsulation, in the context of C#, refers to an object's ability to hide data and behavior that are not necessary to its user. Encapsulation enables a group of properties, methods and other members to be considered a single unit or object.
 
The following are the benefits of encapsulation:
•Protection of data from accidental corruption
•Specification of the accessibility of each of the members of a class to the code outside the class
•Flexibility and extensibility of the code and reduction in complexity
•Lower coupling between objects and hence improvement in code maintainability
 
Encapsulation is used to restrict access to the members of a class so as to prevent the user of a given class from manipulating objects in ways that are not intended by the designer. While encapsulation hides the internal implementation of the functionalities of class without affecting the overall functioning of the system, it allows the class to service a request for functionality and add or modify its internal structure (data or methods) to suit changing requirements.
 
Encapsulation is also known as information hiding.
 
but it different from Abstraction
Encapsulation and Abstraction in c# example with difference[^]
 
Lesson 19 : Encapsulation[^]
What is Encapsulation?[^]
Encapsulation in C#[^]
.
and Google[^] is your best friend.
 

Hope it helped you.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

public class Employee {
private BigDecimal salary = new BigDecimal(50000.00);

public BigDecimal getSalary() {
return salary;
}

public static void main() {
Employee e = new Employee();
BigDecimal sal = e.getSalary();
}
}
  Permalink  
Comments
CHill60 at 13-Oct-14 6:38am
   
This does not answer the 2 year old question!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 424
1 CHill60 410
2 OriginalGriff 355
3 PIEBALDconsult 245
4 BillWoodruff 208


Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 13 Oct 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100