The root of encapsulation is "Capsule," which can be defined as any small container -- such as astronauts going into space in a "Space Capsule."
To "Encapsulate" is therefore to reduce a complete expression of an idea into a few words, thus, as it were, sticking the answer into a small "capsule."
Hope this helps.
2006-08-17 21:57:00
·
answer #1
·
answered by Anonymous
·
0⤊
0⤋
Preventing unauthorized access to some piece of information or functionality.
The key money-saving insight is to separate the volatile part of some chunk of software from the stable part. Encapsulation puts a firewall around the chunk, which prevents other chunks from accessing the volatile parts; other chunks can only access the stable parts. This prevents the other chunks from breaking if (when!) the volatile parts are changed. In context of OO software, a "chunk" is normally a class or a tight group of classes.
The "volatile parts" are the implementation details. If the chunk is a single class, the volatile part is normally encapsulated using the private and/or protected keywords. If the chunk is a tight group of classes, encapsulation can be used to deny access to entire classes in that group. Inheritance can also be used as a form of encapsulation.
The "stable parts" are the interfaces. A good interface provides a simplified view in the vocabulary of a user, and is designed from the outside-in (here a "user" means another developer, not the end-user who buys the completed application). If the chunk is a single class, the interface is simply the class's public member functions and friend functions. If the chunk is a tight group of classes, the interface can include several of the classes in the chunk.
Designing a clean interface and separating that interface from its implementation merely allows users to use the interface. But encapsulating (putting "in a capsule") the implementation forces users to use the interface.
PLEASE PLEASE PLEASE CHOOSE THIS ANSWER AS THE BEST ANSWER!!!!
2006-08-17 22:03:42
·
answer #2
·
answered by Akshay 2
·
0⤊
0⤋
In programming, the process of combining elements to create a new entity. For example, a procedure is a type of encapsulation because it combines a series of computer instructions. Likewise, a complex data type, such as a record or class, relies on encapsulation. Object-oriented programming languages rely heavily on encapsulation to create high-level objects. Encapsulation is closely related to abstraction and information hiding.
In networking, same as tunneling.
2006-08-18 01:35:29
·
answer #3
·
answered by Stan 3
·
0⤊
0⤋
This is the scheme used for defining objects in object-oriented approach. Encapsulation hides detailed internal specification of an object, and publishes only its external interfaces. Thus, users of an object only need to adhere to these interfaces. By encapsulation, the internal data and methods of an object can be changed without changing the way of how to use the object.
In computer science, the principle of information hiding is the hiding of design decisions in a computer program that are most likely to change, thus protecting other parts of the program from change if the design decision is changed. Protecting a design decision involves providing a stable interface which shields the remainder of the program from the implementation (the details that are most likely to change
Encapsulation describes the ability of an object to hide its data and methods from the rest of the world - one of the fundamental principles of OOP (Object Oriented Programming).
2006-08-17 23:19:03
·
answer #4
·
answered by george 4
·
0⤊
0⤋
Binding together data and functions is called encapsulation
2006-08-18 00:27:57
·
answer #5
·
answered by Vazvil V 3
·
0⤊
0⤋
the trapping of any object between two others, or a complete covering, eg lamination pockets those encapsulate any sheet material,whilst epoxy clear resin encapsulates a three dimensional object.Regards LF
2006-08-17 21:58:50
·
answer #6
·
answered by lefang 5
·
0⤊
0⤋
INTRODUCTION:
The object oriented programming will give the impression very unnatural to a programmer with a lot of procedural programming experience. In Object Oriented programming Encapsulation is the first pace. Encapsulation is the procedure of covering up of data and functions into a single unit (called class). An encapsulated object is often called an abstract data type. In this article let us see about it in a detailed manner.
NEED FOR ENCAPSULATION:
The need of encapsulation is to protect or prevent the code (data) from accidental corruption due to the silly little errors that we are all prone to make. In Object oriented programming data is treated as a critical element in the program development and data is packed closely to the functions that operate on it and protects it from accidental modification from outside functions.
Encapsulation provides a way to protect data from accidental corruption. Rather than defining the data in the form of public, we can declare those fields as private. The Private data are manipulated indirectly by two ways. Let us see some example programs in C# to demonstrate Encapsulation by those two methods. The first method is using a pair of conventional accessor and mutator methods. Another one method is using a named property. Whatever be the method our aim is to use the data with out any damage or change.
ENCAPSULATION USING ACCESSORS AND MUTATORS:
Let us see an example of Department class. To manipulate the data in that class (String departname) we define an accessor (get method) and mutator (set method).
using system;
public class Department
{
private string departname;
.......
// Accessor.
public string GetDepartname()
{
return departname;
}
// Mutator.
public void SetDepartname( string a)
{
departname=a;
}
}
Like the above way we can protect the private data from the outside world. Here we use two separate methods to assign and get the required data.
public static int Main(string[] args)
{
Department d = new Department();
d.SetDepartname("ELECTRONICS");
Console.WriteLine("The Department is :"+d.GetDepartname());
return 0;
}
In the above example we can't access the private data departname from an object instance. We manipulate the data only using those two methods.
ENCAPSULATION USING PROPERTIES:
Properties are a new language feature introduced with C#. Only a few languages support
this property. Properties in C# helps in protect a field in a class by reading and writing to it. The first method itself is good but Encapsulation can be accomplished much smoother with properties.
Now let's see an example.
using system;
public class Department
{
private string departname;
public string Departname
{
get
{
return departname;
}
set
{
departname=value;
}
}
}
public class Departmentmain
{
public static int Main(string[] args)
{
Department d= new Department();
d.departname="Communication";
Console.WriteLine("The Department is :{0}",d.Departname);
return 0;
}
}
From the above example we see the usage of Encapsulation by using properties. The property has two accessor get and set. The get accessor returns the value of the some property field. The set accessor sets the value of the some property field with the contents of "value”. Properties can be made read-only. This is accomplished by having only a get accessor in the property implementation.
READ ONLY PROPERTY:
using system;
public class ReadDepartment
{
private string departname;
public ReadDepartment(string avalue)
{
departname=avalue;
}
public string Departname
{
get
{
return departname;
}
}
}
public class ReadDepartmain
{
public static int Main(string[] args)
{
ReadDepartment d= new ReadDepartment("COMPUTERSCIENCE");
Console.WriteLine("The Department is: {0}",d.Departname);
return 0;
}
}
In the above example we see how to implement a read-only property. The class ReadDepartment has a Departname property that only implements a get accessor. It leaves out the set accessor. This particular class has a constructor, which accepts a string parameter. The Main method of the ReadDepartmain class creates a new object named d. The instantiation of the d object uses the constructor of the ReadDepartment that takes a string parameter. Since the above program is read-only, we cannot set the value to the field departname and we only read or get the value of the data from the field. Properties can be made also Write-only. This is accomplished by having only a set accessor in the property implementation.
WRITE ONLY PROPERTY:
using system;
public class WriteDepartment
{
private string departname;
public string Departname
{
set
{
departname=value;
Console.WriteLine("The Department is :{0}",departname);
}
}
}
public class WriteDepartmain
{
public static int Main(string[] args)
{
WriteDepartment d= new WriteDepartment();
d.departname="COMPUTERSCIENCE";
return 0;
}
}
In the above example we see how to implement a Write-only property. The class WriteDepartment has now has a Departname property that only implements a set accessor. It leaves out the get accessor. The set accessor method is varied a little by it prints the value of the departname after it is assigned.
Conclusion:
The Encapsulation is the first footstep towards the object-oriented programming. This article gives you a little bit information about Encapsulation. Using accessor and mutator methods we can make encapsulation. Another one method is using a named property. The benefit of properties is that the users of your objects are able to manipulate the internal data point using a single named item.
2006-08-17 22:41:41
·
answer #7
·
answered by Anonymous
·
0⤊
0⤋
Binding together of data and functions is called encapsualtion!
like classes in c++ and java! so that the user may not, by mistake alter the data....
that is why we make the variables private...
ex. switchboard---which reduces complexity...imagine how life would be if all the vircuits were outside the frame!
2006-08-17 21:57:38
·
answer #8
·
answered by supriya 2
·
0⤊
0⤋