Encapsulation in Object Oriented Programming (OOPS) Concept
Encapsulation , Abstraction and Inheritance are 3 key concepts in Object Oriented Programming (OOPS) C#.Net . Encapsulation allows an object to separate its interface from its implementation. The data and the implementation code for the object are hidden behind its interface.
Encapsulation hides internal implementation details from users.
Labels : GridviewPaging , GridviewSorting , SessionState , ViewState.
Example:
A Customer may issue a check and now know how it is processed. The internal processing is hidden from the customer. Similarly, the inessential attributes of a class are hidden from users by using encapsulation. The hidden attributes of a class are called protected attributes.
A Customer may issue a check and now know how it is processed. The internal processing is hidden from the customer. Similarly, the inessential attributes of a class are hidden from users by using encapsulation. The hidden attributes of a class are called protected attributes.
It ensures that an object supplies only the requested information to another object and hides inessential information.
Example: When a user selects a command from a menu in an application, the code used to perform the actions of that command is hidden from the user.
Encapsulation packages the data and method of an object and provides protection from external tampering by users. It implies that there is visibility to the functionalities offered by an object, and no visibility to its data. The best application of encapsulation is making the data fields private and using public accessor methods.
However, you cannot hide an entire object. To use an object, a part of it needs to be accessed by users. To provide this access, abstraction is used. Abstraction provides access to a specific part of data while encapsulation hides the data. Therefore, abstraction and encapsulation compliment each other.public class Employee
{
private string EmpName;
// Accessor.
public string GetEmpName()
{
return EmpName;
}
// Mutator.
public void SetEmpName(string a)
{
EmpName = a;
}
}
public static int Main(string[] args)
{
Employee d = new Employee();
d.SetEmpName("kapil");
Console.WriteLine("The Employee Name is :" + d.GetEmpName());
return 0;
}
In the above example we can't access the private data EmpName from an object instance. We manipulate the data only using those two methods.
Encapsulation defines the access levels for elements of that class. These access levels define the access rights to the data, allowing us to access the data by a method of that particular class itself, from an inheritance class, or even from any other class. There are three levels of access:
· public: functions of all classes may access the data or methods of a class that is defined with the public access level. This is the lowest level of data protection
· protected: data access is restricted to functions of inheritance classes, i.e. member functions of that class and all sub-classes
· private: data access is restricted to methods of that particular class only. This is the highest level of data protection
Conclusion:
Encapsulation hides internal implementation details from users.
Subscribe to:
Post Comments (Atom)
Labels
- Abstraction in Object Oriented Programming (OOPS) Concept (1)
- Access ChildControls in Gridview using Javascript (1)
- Add a WCF Service Reference to the Client (1)
- ASP.Net GridView Highlight Row onmouseover (1)
- ASP.NET View State And ViewStateEncryptionModes Overview (1)
- Calling Javascript From Any Part Of Code Behind Page By Registering The Script (1)
- Check And UnCheck CheckBoxes In Gridview using javascript (1)
- contact your server administrator. (1)
- DataControlField class (1)
- DataKeys ID (Identity Column) in Child Controls events in GridView (1)
- DataList Paging With PagedDataSource (1)
- Declaring Session in Asp.Net (1)
- Difference between Struct and Class (1)
- Displaying Images In GridView From DataBase (1)
- Dynamic Sitemaps in ASP.NET (1)
- Err: You must install Office SharePoint Server 2007 – Please read Microsoft Knowledge Base article: 962935 with the most recent service pack (1)
- GridView Class (1)
- Gridview Inside GridView (1)
- Gridview Paging using C# (1)
- Gridview Sorting Using C# (1)
- GridView.RowDataBound EventEvent (1)
- GridViewRow (1)
- Inserting Images To Database And Display in GridView (1)
- Microsoft Office Sharepoint Server 2007 on Windows Server 2008 – This Program is blocked due to compatibility issues (1)
- ModalPopUp Using CSS and Div To Reduce the Weight On WebPage (1)
- Session State in Asp.Net OverView (1)
- SharePoint 2010 – The form cannot be rendered. This may be due to a misconfiguration of the Microsoft SharePoint Server State Service. For more information (1)
- Tooltip GridView Header (1)
- Tree View Menu Control (1)
- WCF Service (12)
- What is Encapsulation in OOPS? (1)
Topics
- Abstraction in Object Oriented Programming (OOPS) Concept (1)
- Access ChildControls in Gridview using Javascript (1)
- Add a WCF Service Reference to the Client (1)
- ASP.Net GridView Highlight Row onmouseover (1)
- ASP.NET View State And ViewStateEncryptionModes Overview (1)
- Calling Javascript From Any Part Of Code Behind Page By Registering The Script (1)
- Check And UnCheck CheckBoxes In Gridview using javascript (1)
- contact your server administrator. (1)
- DataControlField class (1)
- DataKeys ID (Identity Column) in Child Controls events in GridView (1)
- DataList Paging With PagedDataSource (1)
- Declaring Session in Asp.Net (1)
- Difference between Struct and Class (1)
- Displaying Images In GridView From DataBase (1)
- Dynamic Sitemaps in ASP.NET (1)
- Err: You must install Office SharePoint Server 2007 – Please read Microsoft Knowledge Base article: 962935 with the most recent service pack (1)
- GridView Class (1)
- Gridview Inside GridView (1)
- Gridview Paging using C# (1)
- Gridview Sorting Using C# (1)
- GridView.RowDataBound EventEvent (1)
- GridViewRow (1)
- Inserting Images To Database And Display in GridView (1)
- Microsoft Office Sharepoint Server 2007 on Windows Server 2008 – This Program is blocked due to compatibility issues (1)
- ModalPopUp Using CSS and Div To Reduce the Weight On WebPage (1)
- Session State in Asp.Net OverView (1)
- SharePoint 2010 – The form cannot be rendered. This may be due to a misconfiguration of the Microsoft SharePoint Server State Service. For more information (1)
- Tooltip GridView Header (1)
- Tree View Menu Control (1)
- WCF Service (12)
- What is Encapsulation in OOPS? (1)
0 Responses to “Encapsulation in Object Oriented Programming (OOPS) Concept”
Post a Comment