Questions tagged [abstraction]

Abstraction is a computer science concept in which an implementation is separated from its interface.

Abstraction is a computer science concept in which an implementation is separated from its interface. Abstraction allows an implementation to be modified without changing the interface, so that other code which relies on this interface does not have to be modified.

For instance, a function prototype in C would be considered the function's interface, and its definition is considered the implementation. The function definition can change (for instance, to improve performance or fix a bug), but as long as the function signature (as specified by the prototype) is the same, any code calling the function can remain the same.

1026 questions
1652
votes
40 answers

Why use getters and setters/accessors?

What's the advantage of using getters and setters - that only get and set - instead of simply using public fields for those variables? If getters and setters are ever doing more than just the simple get/set, I can figure this one out very quickly,…
Dean J
  • 35,669
  • 13
  • 61
  • 92
366
votes
39 answers

Difference between abstraction and encapsulation?

What is the precise difference between encapsulation and abstraction?
Rocky
  • 3,671
  • 3
  • 16
  • 5
176
votes
22 answers

Abstraction VS Information Hiding VS Encapsulation

Can you tell me what is the difference between abstraction and information hiding in software development? I am confused. Abstraction hides detail implementation and information hiding abstracts whole details of something. Update: I found a good…
popopome
  • 11,420
  • 14
  • 40
  • 36
121
votes
4 answers

Compiling vs Transpiling

While searching about the difference, I came across these definitions: Compiling is the general term for taking source code written in one language and transforming into another. Transpiling is a specific term for taking source code written in one…
Nishi Mahto
  • 1,333
  • 2
  • 8
  • 6
120
votes
16 answers

What is the difference between an interface and a class, and why I should use an interface when I can implement the methods directly in the class?

I am aware that this is a very basic question, but an interviewer asked me in a very trick way and I was helpless :( I know only material or theoretical definition for an interface and also implemented it in many projects I worked on. But I really…
Jasmine
  • 4,876
  • 13
  • 48
  • 100
103
votes
18 answers

Difference between Encapsulation and Abstraction

I had an interview today. I had a question from OOP, about the difference between Encapsulation & Abstraction? I replied her to my knowledge that Encapsulation is basically to bind data members & member functions into a single unit called Class.…
WpfBee
  • 2,307
  • 6
  • 20
  • 26
96
votes
6 answers

What does "abstract over" mean?

Often in the Scala literature, I encounter the phrase "abstract over", but I don't understand the intent. For example, Martin Odersky writes You can pass methods (or "functions") as parameters, or you can abstract over them. You can specify types…
Morgan Creighton
  • 1,238
  • 11
  • 13
95
votes
11 answers

Meaning of Leaky Abstraction?

What does the term "Leaky Abstraction" mean? (Please explain with examples. I often have a hard time grokking a mere theory.)
80
votes
5 answers

Is returning IList worse than returning T[] or List?

The answers to questions like this: List or IList always seem to agree that returning an interface is better than returning a concrete implementation of a collection. But I'm struggling with this. Instantiating an interface is impossible, so…
Alexander Derck
  • 11,742
  • 4
  • 43
  • 73
78
votes
8 answers

How much abstraction is too much?

In an object-oriented program: How much abstraction is too much? How much is just right? I have always been a nuts and bolts kind of guy. I understood the concept behind high levels of encapsulation and abstraction, but always felt instinctively…
Daniel Bingham
  • 11,111
  • 16
  • 63
  • 91
77
votes
13 answers

How abstraction and encapsulation differ?

I am preparing for an interview and decided to brush up my OOP concepts. There are hundreds of articles available, but it seems each describes them differently. Some says Abstraction is "the process of identifying common patterns that have …
Aparan
  • 1,227
  • 3
  • 12
  • 17
75
votes
16 answers

Simple way to understand Encapsulation and Abstraction

Learning OOP concepts especially interested to understand Abstraction and Encapsulation in depth. Checked out the below already Abstraction VS Information Hiding VS Encapsulation difference between abstraction and encapsulation? I found very hard to…
Billa
  • 4,856
  • 21
  • 55
  • 99
56
votes
7 answers

Why is Haskell missing "obvious" Typeclasses

Consider the Object-Oriented Languages: Most people coming from an object-oriented programming background, are familiar with the common and intuitive interfaces in various languages that capture the essence of Java's Collection & List interfaces.…
recursion.ninja
  • 4,968
  • 7
  • 42
  • 76
55
votes
24 answers

Why should I use a human readable file format?

Why should I use a human readable file format in preference to a binary one? Is there ever a situation when this isn't the case? EDIT: I did have this as an explanation when initially posting the question, but it's not so relevant now: When…
Nick Fortescue
  • 40,193
  • 23
  • 99
  • 131
53
votes
24 answers

What's the difference between abstraction and encapsulation?

In interviews I have been asked to explain the difference between abstraction and encapsulation. My answer has been along the lines of Abstraction allows us to represent complex real world in simplest manner. It is the process of identifying the…
vishu minhas
  • 1,552
  • 1
  • 17
  • 30
1
2 3
68 69