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
49
votes
7 answers

What does the quote "An extra level of indirection solves every problem" mean?

What does the quote "Level of Indirection solves every Problem" mean in Computer Science?
Vicky
  • 11,077
  • 11
  • 35
  • 29
44
votes
11 answers

What is the difference between Abstraction and Polymorphism

I seem to not understand two OOP concepts very well. Could you explain what abstraction and polymorphism are, preferably with real examples and code? Thank you.
Sambath Prum
  • 1,858
  • 9
  • 25
  • 33
44
votes
9 answers

What's the difference between abstraction and generalization?

I understand that abstraction is about taking something more concrete and making it more abstract. That something may be either a data structure or a procedure. For example: Data abstraction: A rectangle is an abstraction of a square. It…
Aadit M Shah
  • 72,912
  • 30
  • 168
  • 299
43
votes
8 answers

Is it better to use List or Collection?

I have an object that stores some data in a list. The implementation could change later, and I don't want to expose the internal implementation to the end user. However, the user must have the ability to modify and access this collection of data.…
Vivin Paliath
  • 94,126
  • 40
  • 223
  • 295
41
votes
7 answers

Is an ORM redundant with a NoSQL API?

with MongoDB (and I assume other NoSQL database APIs worth their salt) the ways of querying the database are much more simplistic than SQL. There is no tedious SQL queries to generate and such. For instance take this from mongodb-csharp: using…
Earlz
  • 62,085
  • 98
  • 303
  • 499
40
votes
8 answers

Should I use public or private variables?

I am doing a large project for the first time. I have lots of classes and some of them have public variables, some have private variables with setter and getter methods and same have both types. I decided to rewrite this code to use primarily only…
Marek Čačko
  • 980
  • 2
  • 21
  • 31
38
votes
23 answers

Why are interfaces preferred to abstract classes?

I recently attended an interview and they asked me the question "Why Interfaces are preferred over Abstract classes?" I tried giving a few answers like: We can get only one Extends functionality they are 100% Abstract Implementation is not…
Techmaddy
  • 4,586
  • 5
  • 28
  • 33
38
votes
6 answers

What's the difference between a sequence and a collection in Clojure

I am a Java programmer and am new to Clojure. From different places, I saw sequence and collection are used in different cases. However, I have no idea what the exact difference is between them. For some examples: 1) In Clojure's documentation for…
nybon
  • 8,894
  • 9
  • 59
  • 67
37
votes
3 answers

What is Google's Dremel? How is it different from Mapreduce?

Google's Dremel is described here. What's the difference between Dremel and Mapreduce?
Yktula
  • 14,179
  • 14
  • 48
  • 71
35
votes
4 answers

Abstract private functions

The following code will have PHP unhappy that customMethod() is private. Why is this the case? Is visibility determined by where something is declared rather than defined? If I wanted to make customMethod only visible to boilerplate code in the…
jontyc
  • 3,445
  • 6
  • 29
  • 36
28
votes
12 answers

When should I return the Interface and when the concrete class?

when programming in Java I practically always, just out of habit, write something like this: public List foo() { return new ArrayList(); } Most of the time without even thinking about it. Now, the question is: should I always…
n3rd
  • 5,989
  • 4
  • 39
  • 56
28
votes
4 answers

How to get the name of the calling class (in PHP)

define('anActionType', 1); $actionTypes = array(anActionType => 'anActionType'); class core { public $callbacks = array(); public $plugins = array(); public function __construct() { $this->plugins[] = new admin(); …
Mark Tomlin
  • 8,593
  • 11
  • 57
  • 72
28
votes
4 answers

Why can't an abstract method be synchronized?

I was reading a thread from CodeRanch saying that abstract methods could not be synchronized due to the fact that an abstract class cannot be instantiated, meaning no object to lock. This doesn't make sense since an abstract class is a definition…
ahodder
  • 11,353
  • 14
  • 71
  • 114
27
votes
13 answers

Clean Code: Should Objects have public properties?

I'm reading the book "Clean Code" and am struggling with a concept. When discussing Objects and Data Structures, it states the following: Objects hide their data behind abstractions and expose functions that operate on that data. Data Structures…
JSprang
  • 12,481
  • 7
  • 30
  • 32
27
votes
3 answers

Is HttpContextWrapper all that....useful?

I've been going through the process of cleaning up our controller code to make each action as testable. Generally speaking, this hasn't been too difficult--where we have opportunity to use a fixed object, like say FormsAuthentication, we generally…
bakasan
  • 2,262
  • 2
  • 26
  • 33
1
2
3
74 75