-2

I'm trying to learn advanced topics of C#, I'm currently 16 years old and self taught so I never really learnt about the advanced topics of C#, although I don't really see this as an advanced topic.

I was wondering if anyone could explain to me what abstraction is? I've made my own conclusion so if somebody could ready that and maybe pick up on the parts I may have wrong?

There aren't much resources online that make sense to me right now, but looking at lots of different ones sort of painted me a vague but fairly conclusive picture.

Abstraction is simply hiding methods, properties, fields and everything else in a class that the programmer never calls and the programmer really doesn't care about. I guess this means everything that should be hidden should be private? I don't really see this as a topic that you need to learn because this is what everyone does anyway, am I missing something? I also don't understand the reasoning for hiding it, it should be hidden anyway, abstraction is simply a coding convention / coding practice that everyone should follow, not a topic, am I right? If so, I don't see why its so important, is it personal preference? Is this just because the programmer doesn't want to see irrelevant things that they'll never use? Hopefully someone can help me.

My thought of the word "abstract" which I feel I have right.

Sort of exists but then sort of doesn't, it exists but as a thought, in code it exists but isn't visible.

Jan Edan
  • 69
  • 6
  • In the first quote, are the questions yours, or are they original questions in the quote? – Jim W Mar 19 '18 at 19:24
  • 1
    Look up FileStream, NetworkStream and then their abstract base class Stream. – H H Mar 19 '18 at 19:24
  • Their my questions, the first quote is simply my thoughts on it, I'm asking if I have it right, and if not for someone to maybe help me understand the parts I have wrong. – Jan Edan Mar 19 '18 at 19:25
  • You can have a `Person` class that is your base class and a `Farmer` class that is your abstract class – Taylor Ackley Mar 19 '18 at 19:26
  • 1
    Maybe look at [https://stackoverflow.com/questions/16938667/how-abstraction-and-encapsulation-differ](https://stackoverflow.com/questions/16938667/how-abstraction-and-encapsulation-differ) – Ryan Gunn Mar 19 '18 at 19:26
  • 4
    Possible duplicate of [What is abstraction?](https://stackoverflow.com/questions/7028242/what-is-abstraction) – NightOwl888 Mar 19 '18 at 19:27
  • Look at the [language specification](https://msdn.microsoft.com/en-us/library/ms228593(v=vs.120).aspx) and examples to understand programming concepts. Do not try to apply natural language concepts to programming terms or you will become very very confused. – Dour High Arch Mar 19 '18 at 19:32
  • I think you learn the value of abstractions through practice, rather than trying to fit into a nice definition – Jonesopolis Mar 19 '18 at 19:33
  • It is another tool for solving problems. Once you find the problem (or the problem finds you?), the solution will be obvious. – FCin Mar 19 '18 at 19:35
  • 1
    @JimW this question is a _very_ poor fit at "Programmers" for the same reasons as here. Please abstain of recommending sites you're not familiar with (you even got the site name wrong) – gnat Mar 19 '18 at 20:50
  • @gnat He asked the question on 'programmers.stackexchange.com' (the old name I guess) and it was marked as a duplicate of a very similar question that has 32 upvotes, 19 stars and 32k views - ok it was closed as broad too, but clearly a lot of people thought it was a good question. – Jim W Mar 20 '18 at 00:13

1 Answers1

2

The general concept of abstraction (in programming at least) is making something easier than it appears. Take a complex process or class, wrap it up in something that's easier to use, and you've created an abstraction. You've abstracted away the ugly details and just have to work with the nice surface instead. In OOP, the definition is a bit more specific, but generally speaking that's what you're talking about. Abstracting away the stuff you don't need.

Look at the Win32 API for opening a file dialog or ShellExecute for example. Then look at similar C# code to do the same thing (pick a UI platform), and you'll see that the Win32 API code is much more complex (but also much more powerful). The C# versions can be considered an abstraction which in turn calls the Win32 API versions. In the same light, any modern programming language can be considered an abstraction over writing assembly/machine code.

I recommend some reading by Joel Spolsky, in this case the Law of Leaky Abstractions: https://www.joelonsoftware.com/2002/11/11/the-law-of-leaky-abstractions/

jleach
  • 7,410
  • 3
  • 33
  • 60