what is the diff bw abstraction and encapsuation how the implementaion will be done

Posted by Kishore22 under C# on 11/21/2013 | Points: 10 | Views : 1911 | Status : [Member] | Replies : 5
what is the diff bw abstraction and encapsuation how the implementaion will be done give me a simple exaple????




Responses

Posted by: Bandi on: 11/22/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Read Encapsulation at http://www.dotnetfunda.com/articles/article511-what-is-encapsulation-.aspx

Read Abstraction at http://www.dotnetfunda.com/articles/article632-what-is-an-abstraction-.aspx

Real Life Difference Between Encapsulation and Abstraction

Encapsulate means to hide. Encapsulation is also called data hiding.You can think Encapsulation like a capsule (medicine tablet) which hides medicine inside it. Encapsulation is wrapping, just hiding properties and methods. Encapsulation is used for hide the code and data in a single unit to protect the data from the outside the world. Class is the best example of encapsulation.

Abstraction refers to showing only the necessary details to the intended user. As the name suggests, abstraction is the "abstract form of anything". We use abstraction in programming languages to make abstract class. Abstract class represents abstract view of methods and properties of class.

Implementation Difference Between Encapsulation and Abstraction

1. Abstraction is implemented using interface and abstract class while Encapsulation is implemented using private and protected access modifier.

2. OOPS makes use of encapsulation to enforce the integrity of a type (i.e. to make sure data is used in an appropriate manner) by preventing programmers from accessing data in a non-intended manner. Through encapsulation, only a predetermined group of functions can access the data. The collective term for datatypes and operations (methods) bundled together with access restrictions (public/private, etc.) is a class.

3. Example of Encapsulation

Class Encapsulation

{
private int marks;

public int Marks
{
get { return marks; }
set { marks = value;}
}
}


4. Example of Abstraction

abstract class Abstraction

{
public abstract void doAbstraction();
}

public class AbstractionImpl: Abstraction
{
public void doAbstraction()
{
//Implement it
}
}



Difference between Encapsulation and Abstraction
1. Abstraction solves the problem in the design level
1. Encapsulation solves the problem in the implementation level

2. Abstraction is used for hiding the unwanted data and giving relevant data
2. Encapsulation means hiding the code and data in to a single unit to protect the data from outside world

3. Abstraction is a technique that helps to identify which specific information should be visible and which information should be hidden.
3. Encapsulation is the technique for packaging the information in such a way as to hide what should be hidden, and make visible what is intended to be visible.


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Kishore22, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 11/22/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Dear Kishore,

Abstraction:
1. Abstraction is "To represent the essential feature without representing the background details."
2. Abstraction lets you focus on what the object does instead of how it does it.
3. Abstraction provides you a generalized view of your classes or objects by providing relevant information.
4. Abstraction is the process of hiding the working style of an object, and showing the information of an object in an understandable manner.

Real-world Example of Abstraction:

Suppose you have 3 mobile phones as in the following:
Nokia 1400 (Features: Calling, SMS)
Nokia 2700 (Features: Calling, SMS, FM Radio, MP3, Camera)
Black Berry (Features:Calling, SMS, FM Radio, MP3, Camera, Video Recording, Reading E-mails)

Abstract information (necessary and common information) for the object "Mobile Phone" is that it makes a call to any number and can send SMS.

So that, for a mobile phone object you will have the abstract class as in the following:

abstract class MobilePhone

{
public void Calling();
public void SendSMS();
}

public class Nokia1400 : MobilePhone
{
}

public class Nokia2700 : MobilePhone
{
public void FMRadio();
public void MP3();
public void Camera();
}

public class BlackBerry : MobilePhone
{
public void FMRadio();
public void MP3();
public void Camera();
public void Recording();
public void ReadAndSendEmails();
}



Encapsulation:
1. Wrapping up a data member and a method together into a single unit (in other words class) is called Encapsulation.
2. Encapsulation is like enclosing in a capsule. That is enclosing the related operations and data related to an object into that object.
3. Encapsulation means hiding the internal details of an object, in other words how an object does something.
4. Encapsulation prevents clients from seeing its inside view, where the behaviour of the abstraction is implemented.
5. Encapsulation is a technique used to protect the information in an object from another object.
6. Hide the data for security such as making the variables private, and expose the property to access the private data that will be public.
7.. Encapsulation is like your bag in which you can keep your pen, book etcetera. It means this is the property of encapsulating members and functions.
class Bag

{
string book;
string pen;
ReadBook();
}


Real-world Example of Encapsulation:

Let's use as an example Mobile Phones and Mobile Phone Manufacturers.
Suppose you are a Mobile Phone Manufacturer and you have designed and developed a Mobile Phone design (a class). Now by using machinery you are manufacturing Mobile Phones (objects) for selling, when you sell your Mobile Phone the user only learns how to use the Mobile Phone but not how the Mobile Phone works.

This means that you are creating the class with functions and by with objects (capsules) of which you are making available the functionality of your class by that object and without the interference in the original class.

Links:-

http://theprofessionalspoint.blogspot.in/2013/05/difference-between-encapsulation-and.html


Happy Coding,
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Kishore22, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 11/22/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Another differences:-

1. -> Abstraction solves the problem at the design level.
-> Encapsulation solves the problem in the implementation level.
2. -> Abstraction hides unwanted data and provides relevant data.
-> Encapsulation means hiding the code and data into a single unit to protect the data from the outside world.
3. -> Abstraction lets you focus on what the object does instead of how it does it
-> Encapsulation means hiding the internal details or mechanics of how an object does something.
4. -> Abstraction: Outer layout, used in terms of design.
For example:
An external of a Mobile Phone, like it has a display screen and keypad buttons to dial a number.
-> Encapsulation- Inner layout, used in terms of implementation.
For example: the internal details of a Mobile Phone, how the keypad button and display screen are connected with each other using circuits.

Happy Coding,
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Kishore22, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 11/22/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Refer
http://www.codeproject.com/Questions/298285/difference-between-data-hidding-encapsulation-abst


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Kishore22, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vamc on: 12/17/2013 [Member] Starter | Points: 25

Up
0
Down
Click the below link to find abstraction and encapsulation with example programs

http://www.dotnetchallengers.com/App_Folder/Content/Tutorials/abstraction/Abstraction.aspx
http://www.dotnetchallengers.com/App_Folder/Content/Tutorials/Encapsulation/Encapsulation.aspx

Kishore22, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response