Abstraction is the process of hiding the low priority class members and showing the required features only.
Let us suppose, we are using a mobile phone. As an end user, we should know better on outer parts like screen, battery and design. Dont need to know much about the inner parts like connections between the hard ware etc..
On the same way, while developing a class, we should show only the required features to the users who uses our class.
For example we are creating a time sheet page. For that we need to work two things.
1)whether the user exists or not?
2)Inserting the hrs into the database.
Please see the example below
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace InheritenceDiscussion
{
class Employeeinformation
{
public int validateuser(int uid)
{
int[] userid = { 200, 300, 400 };
int iVal = 0;
if (userid.Contains(uid))
{
iVal = 1;
}
return iVal;
}
public void InsertupdateHrs(int hrs)
{
Console.WriteLine("Employee information updated.");
}
}
class Encapsulation
{
Employeeinformation e = new Employeeinformation();
void Evalidate()
{
int ivaliedate =e.validateuser(200);
if (ivaliedate==1)
{
e.InsertupdateHrs(8);
}
else
{
Console.WriteLine("No user exists with the supplied userID.");
}
}
static void Main()
{
Encapsulation e = new Encapsulation();
e.Evalidate();
Console.Read();
}
}
}
In the above example Employeeinformation contains two methods validateuser() and InsertupdateHrs(). Here validateuser() checks whether the user exists or not and InsertupdateHrs() inserts the hours into the database.
The user who access this class need to use two methods to insert hours. To minimize the user efforts we can write the code as below,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace InheritenceDiscussion
{
class Employeeinformation
{
public int validateuser(int uid,int hrs)
{
int[] userid = { 200,300,400 };
int iVal = 0;
{
if(userid.Contains(uid))
{
InsertupdateHrs(hrs);
}
}
return iVal;
}
private void InsertupdateHrs(int hrs)
{
Console.WriteLine("Employee information updated.");
}
}
class Encapsulation
{
Employeeinformation e = new Employeeinformation();
void Evalidate()
{
e.validateuser(200,8);
}
static void Main()
{
Encapsulation e=new Encapsulation();
e.Evalidate();
Console.Read();
}
}
}
Here I made InsertupdateHrs() method private and called under validateuser() method. So, it is not accessible (hided) to the user out side the class but it is invoked via validateuser() method.
This is called abstraction.




SQL Server
C#.Net
ASP.Net
ADO.Net
jQuery
I got lot of ideas after reading this. Share more as similar to this. Thank you for shared this.
ReplyDeleteC C++ Training in Chennai
C Training in Chennai
C++ Training in Chennai
JMeter Training in Chennai
JMeter Training Institute in Chennai
Appium Training in Chennai
javascript training in chennai
core java training in chennai
Thanks for your feedback
DeleteI have finally found a worth able content to read, your information in this blog is impressive. Keep sharing more like this.
ReplyDeleteData Science Course in Chennai
Data Science Training in Chennai
R Training in Chennai
R Programming Training in Chennai
Machine Learning Course in Chennai
Machine Learning institute in Chennai
Data Science Training in Anna Nagar
Thanks for your feedback :)
DeleteThanks for sharing an informative blog keep rocking bring more details.I like the helpful info you provide in your articles. I’ll bookmark your weblog and check again here regularly. I am quite sure I will learn much new stuff right here! Good luck for the next!
ReplyDeleteWeb Designing Training Institute in Chennai | web design training class in chennai | web designing course in chennai with placement
Mobile Application Development Courses in chennai
Data Science Training in Chennai | Data Science courses in Chennai
Professional packers and movers in chennai | PDY Packers | Household Goods Shifting
Web Designing Training Institute in Chennai | Web Designing courses in Chennai
Google ads services | Google Ads Management agency
Web Designing Course in Chennai | Web Designing Training in Chennai
Nice post. Thanks for sharing! I want people to know just how good this information is in your article. It’s interesting content and Great work.
ReplyDeleteappium online training
appium training centres in chennai
best appium training institute in chennnai
apppium course
mobile appium in chennnai
mobile training in chennnai
appium training institute in chennnai
Thanks for the interesting blog that you have implemented here. Very helpful and innovative. Waiting for your next upcoming article.
ReplyDeleteDigital Marketing Course In Kolkata
Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end. great work
ReplyDeleteAi & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai