How encapsulation and abstraction defined/used in C#.NET.

Answer Posted / sanjay vishwakarma

Encapsulation:
Encapsulation is a process of binding the data members and
member functions into a single unit.
Example for encapsulation is class. A class can contain data
structures and methods.
Consider the following class
public class Aperture
{
public Aperture ()
{
}
protected double height;
protected double width;
protected double thickness;
public double get volume()
{
Double volume=height * width * thickness;
if (volume<0)
return 0;
return volume;
}
}
In this example we encapsulate some data such as height,
width, thickness and method Get Volume. Other methods or
objects can interact with this object through methods that
have public access modifier

Abstraction:
Abstraction is a process of hiding the implementation
details and displaying the essential features.
Example1: A Laptop consists of many things such as
processor, motherboard, RAM, keyboard, LCD screen, wireless
antenna, web camera, usb ports, battery, speakers etc. To
use it, you don't need to know how internally LCD screens,
keyboard, web camera, battery, wireless antenna, speaker’s
works. You just need to know how to operate the laptop by
switching it on. Think about if you would have to call to
the engineer who knows all internal details of the laptop
before operating it. This would have highly expensive as
well as not easy to use everywhere by everyone.
So here the Laptop is an object that is designed to hide its
complexity.

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is datetime value type c#?

481


How do you comment in c#?

493


How do I format in c#?

499


How do I unload an application domain?

521


What are strong name assemblies?

552






What kind of the information stored inside the assembly?

551


What is stringbuilder c#?

507


Can abstract class be sealed in c#?

470


Is arraylist type safe in c#?

498


What floating point types is supported in C#?

592


What is the difference between ienumerable and icollection?

468


What is the namespcae generally given to the webpage of the .NET Framework ?

596


Is exe is machine dependent?

496


What is the difference between serialization and deserialization in c#?

450


In a C# class we have a SortedList member m_addinProjects we want to provide an iterator to allow the consumer of this class access to the items in the collection. Please provide an iterator method for the AnalyzeAddinsDLL class below and an example of how it would be used. namespace AnalyzeAddinsDLL { public class AllAddInProjects { private SortedList m_addinProjects; public AllAddInProjects() { m_addinProjects = new SortedList(); } } }

1810