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.

1121 questions
1844
votes
37 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
  • 39,360
  • 16
  • 67
  • 93
446
votes
40 answers

Difference between abstraction and encapsulation?

What is the precise difference between encapsulation and abstraction?
Rocky
  • 4,471
  • 3
  • 18
  • 5
213
votes
8 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
  • 2,261
  • 2
  • 10
  • 6
185
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
  • 12,250
  • 15
  • 44
  • 36
144
votes
22 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 to my knowledge that Encapsulation is basically binding data members & member functions into a single unit called Class. Whereas…
WpfBee
  • 2,837
  • 6
  • 23
  • 29
122
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
  • 5,186
  • 16
  • 62
  • 114
117
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.)
98
votes
7 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,348
  • 11
  • 13
93
votes
9 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
  • 12,414
  • 18
  • 67
  • 93
82
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
  • 5,226
  • 23
  • 61
  • 105
81
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
  • 13,818
  • 5
  • 54
  • 76
81
votes
15 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,263
  • 3
  • 12
  • 17
60
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
  • 5,377
  • 7
  • 46
  • 78
57
votes
25 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…
Vishvadeep singh
  • 1,624
  • 1
  • 19
  • 31
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
  • 43,045
  • 26
  • 106
  • 134
1
2 3
74 75