What is Encapsulation?

1)Encapsulation is one of the fundamental principles of object-oriented programming.
2)Encapsulation is a process of hiding all the internal details of an object from the outside world
3)Encapsulation is the ability to hide its data and methods from outside the world and only expose data and methods that are required
4)Encapsulation is a protective barrier that prevents the code and data being randomly accessed by other code or by outside the class
5)Encapsulation gives us maintainability, flexibility and extensibility to our code.
6)Encapsulation makes implementation inaccessible to other parts of the program and protect from whatever actions might be taken outside the function or class.
7)Encapsulation provides a way to protect data from accidental corruption
8)Encapsulation hides information within an object
9)Encapsulation is the technique or process of making the fields in a class private and providing access to the fields using public methods
10)Encapsulation gives you the ability to validate the values before the object user change or obtain the value
11)Encapsulation allows us to create a "black box" and protects an objects internal state from corruption by its clients.


Comments

Author: Phagu Mahato06 Jan 2014 Member Level: Gold   Points : 3

Encapsulation is a procedure of covering up of the data & functions into a single unit called as class . An Application is nothing but combination of classes working as units to accomplish task.In Encapsulation fields of a class can be read-only or can be write-only.


using System;

class AccountDetails
{
private string mob_CustName;

public string bankCustomertName
{
get { return mob_CustName ; }
set { mob_CustName = value; }
}
}

Author: sudhanshu pal28 Jan 2014 Member Level: Silver   Points : 5

Hello all,

Pillars of OOPS:
Encapsulation:
Introduction
In object oriented programming systems, we have lots of concepts which we have to think of when designing systems. A few of them are very important and a few of them are considered pillars of object oriented programming systems. Here I start with the first pillar of object oriented programming systems and that is encapsulation.

Definition
Encapsulation is the first pillar or principle of object-oriented programming. In simple words, “Encapsulation is a process of binding data members (variables, properties) and member functions (methods) into a single unit”. And Class is the best example of encapsulation.

Important points
Through encapsulation a class can hide the internal details of how an object does something. Encapsulation solves the problem at the implementation level.
A class or structure can specify how accessible each of its members (variables, properties, and methods) is to code outside of the class or structure. Encapsulation simplifies the interaction between objects. An object can use another object without knowing all its data or how its data is maintained. For example, a Client object might have name, address, company, and department properties. If a Bank object wants to use a Client object, it can request the name and address for the bank without needing to know the company and department details of the Client object.
With the help of encapsulation, a class can change the internal implementation without hurting the overall functionality of the system.
Encapsulation protects abstraction.
Need or purpose of encapsulation
To hide and prevent code (data) from the outside world (here the world means other classes and assemblies).
To prevent code (data) from accidental corruption due to programming errors so that we can deliver expected output. Due to programming mistakes, code may not behave properly and it has an effect on data and then it will affect the functionality of the system. With encapsulation we can make variables, properties, and methods private so it is not accessible to all but accessible through proper channels only to protect it from accidental corruption from other classes.
To have a class better control over its fields (validating values etc…).



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: