Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am learning oops concepts and find some content on below site.

OOPS Concepts, Features & Fundamentals

http://www.aspneto.com/oop-concepts-object-oriented-programming-concepts-with-examples.html[OOPS Concepts, Features & Fundamentals]

and completely confused with below information provided by the above link.

C#
Note: Abstraction and Encapsulation are related features in object oriented programming. Abstraction allows making relevant information visible and Encapsulation enables a programmer to implement the desired level of abstraction. That means hidden part of class acts like Encapsulation and exposed part of class acts like Abstraction. 


it seems like that there is one glass and which is half filled with water when two person see this glass one say the glass is half full and second one says that the glass is half empty.

Please help me regarding this encapsulation and abstraction and data hiding i have read others blogs also but did not find something valuable it is getting me in more confusion as i read more . Please help me two understand these concepts in terms of c# .

Thank you in advance , please help me i deadly need it.
Posted
Comments
Foothill 30-Nov-15 13:58pm    
I always looked at this as a fancy way to describe Public vs. Private variables and methods.
185149 30-Nov-15 14:27pm    
Thanks for the reply Foothill , Please help me to better understanding in this.
Foothill 30-Nov-15 15:54pm    
I'll try to be brief.

To me, abstraction in OOP is taking something complicated and wrapping it up in a simple to understand public method. With this, the programmer doesn't need to care how the result is achieved and only needs to be concerned with the result that they get.

Encapsulation is like an extension to abstraction as you can have one or two public facing functions that call dozens of private functions which do all the work. Once again, the end user doesn't need to be concerned with the 'how' just the result.

Quick example pseudo code (C#):

public class AppSettings
{
public static AppSettings LoadSettingsFile(string fileName);
private static FileStream OpenConfigFile(string fileName);
private static bool IsXmlFile(FileStream configFile);
private static XmlReader LoadXml(FileStream configFile);
private static LoadWebSettings(XmlReader xml);
private static LoadThemeSettings(XmlReader xml);
...
}

Here, the user is only concerned with getting an AppSettings object from a config file or getting error when something goes wrong (abstraction). Knowing all the steps taken would only make the process more difficult to understand and are hidden from the user (encapsulation).
Sergey Alexandrovich Kryukov 30-Nov-15 14:04pm    
Sorry, this is not a question. It's hardly possible to figure out what help do you possibly need. Encapsulation and abstraction are fundamental concepts not limited to OOP. Asking about such concepts is roughly equivalent to asking "what is programming?". Reading just, words, "definitions", as well as some forum answers, no matter how good, won't be enough. You need to learn programming in general, which should bring you to understanding. Even if I decided to try to explain these concepts to you, the fact that you could not grasp the concepts makes this initiative quite questionable.
—SA
185149 30-Nov-15 14:24pm    
Thanks for the reply Sergey ,You are right but I need it . That would be great if you explain to me .

1 solution

Please see my comment to the question.

Yes, I already tried to explain you that reading short definitions would be reading just words. But on next step I looked through the article you referenced and found that the situation is much worse. The problem is: this article is nothing serious, frankly, this is total trash, especially the "explanation" of "abstraction". It's pretty apparent that the author himself is pretty much clueless about those concepts. I rarely saw more of gibberish than that "Abstraction and Encapsulation are related features…" quote.

And the fact that the "Interview questions" links (notoriously useless and misleading topic) are referenced in the article, tells the tale. Stop reading trash articles, and you will be much less confused.

You can find a lot more reliable source of explanation of the concepts (but, jumping to the conclusion, this is not the main device you have to use). Before talking about abstraction in programming, you have to get at least general understanding of the most common understanding if this term: https://en.wikipedia.org/wiki/Abstraction[^].

It can really help you to understand what is that in programming. In fact, the programming is all about abstractions. Please see: https://en.wikipedia.org/wiki/Abstraction_%28computer_science%29[^].

Pay attention for the striking difference between this explanation and the "explanation" you found in the article you referenced. Likewise, you can read on encapsulation: https://en.wikipedia.org/wiki/Encapsulation_%28computer_programming%29[^].

And now let me return to my main point. Reading just the definitions and general explanations will be majorly useless. To learn these abstract and very important fundamental concepts, you have to learn computer science, practical programming itself and programming technology as a kind of human activity. Through the process of learning, you can learn how these fundamental concepts really work. Another problem with learning these concepts is: learning them without learning a number of other fundamental concepts would also be useless. You really need holistic understanding of programming, which can only come with effort and iterative learning process, not at once.

What to read? I'm afraid to confuse you. There is a lot of literature, but, at the same time, there is a lot of popular misconceptions which are also widely represented in various publications. This can be very confusing. I want to give you just one example. There is a popular didactic approach claiming that there are four OOP "pillars": abstraction, encapsulation, inheritance and polymorphism, and such claim is usually followed by the "explanation" of each. This is nothing but a big "beautiful" lie, but the lie of that kind when the author believes in it. This approach is, to say the least, counter-productive, because 1) these concepts are of different non-matching levels, 2) one concept represents the feature serving as the prerequisite for another one, for example, it's impossible to talk about OOP polymorphism without inheritance. And so on… Here, again, learning the body of computer science can help you to develop critical thinking on the concept. The prerequisite for such thinking is first-hand understanding of how things work.

—SA
 
Share this answer
 
v3
Comments
George Jonsson 30-Nov-15 22:44pm    
Good explanation. +6 (a little typo)
+5
Sergey Alexandrovich Kryukov 1-Dec-15 0:20am    
Appreciate your extra +1 in 6, even as a typo. :-)
—SA
George Jonsson 1-Dec-15 1:00am    
Well, I felt generous today. :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900