Abstraction and Encapsulation in c# [Resolved]

Posted by Programmer123 under C# on 9/30/2013 | Points: 10 | Views : 10128 | Status : [Member] | Replies : 4
Can any one give me the example where how to use abstraction and encapsulation in c#. The real world example will be useful.




Responses

Posted by: Bandi on: 9/30/2013 [Member] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Encapsulation and abstraction is the advanced mechanism in C# that lets your program to hide unwanted code within a capsule and shows only essential features of an object. Encapsulation is used to hide its members from outside class or interface, whereas abstraction is used to show only essential features.In C# programming, Encapsulation uses five types of modifier to encapsulate data. These modifiers are public, private, internal, protected and protected internal. These all includes different types of characteristics and makes different types of boundary of code.

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

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

Posted by: Bandi on: 9/30/2013 [Member] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
http://theprofessionalspoint.blogspot.in/2013/05/difference-between-encapsulation-and.html
http://stackoverflow.com/questions/16938667/how-abstraction-and-encapsulation-differ
http://theprofessionalspoint.blogspot.in/2013/05/difference-between-encapsulation-and.html


http://www.c-sharpcorner.com/Blogs/9442/
http://www.dotnetfunda.com/forums/show/3226/real-time-example-of-encapsulation-and-abstraction
http://social.msdn.microsoft.com/Forums/vstudio/en-US/0f0cfd61-24d3-4b7c-b480-b1c912164548/how-do-we-use-abstraction-and-encapsulation-in-net

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

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

Posted by: Allemahesh on: 10/1/2013 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
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.


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

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

Posted by: Bandi on: 9/30/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
refer this link
http://www.completecsharptutorial.com/basic/understanding-concepts.php

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

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

Login to post response