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