Linked Questions
12 questions linked to/from Understanding "programming to an interface"
-2
votes
1
answer
326
views
Programming to an Interface and Keep Testability in Unique Classes [duplicate]
I try to program to an interface whenever possible, but when I have a class that fulfills a very specific and unique purpose, one that can't be abstracted. Is it correct for me to say that I've ...
0
votes
0
answers
111
views
Heuristics/rules for programming to an interface [duplicate]
I am struggling with applying the "programming to an interface" guideline because I can't seem to decide in which situations it is necessary and in which ones it's overkill (or even counter productive)...
176
votes
19
answers
174k
views
Why are interfaces useful?
I have been studying and coding in C# for some time now. But still, I can't figure the usefulness of Interfaces. They bring too little to the table. Other than providing the signatures of function, ...
38
votes
7
answers
17k
views
Should I still follow "programming to an interface not implementation" even if I think using concrete class members is the simpler solution?
According to Understanding "programming to an interface", as I understand, I think I should depend on abstract class only. However, in some case, for example, Student:
public class Student {...
36
votes
6
answers
14k
views
What's the point of implementing a Stack using two queues?
I have the following homework question:
Implement the stack methods push(x) and pop() using two queues.
This seems odd to me because:
A Stack is a (LIFO) queue
I don't see why you would need two ...
8
votes
4
answers
6k
views
Why instantiate an object to a base class rather than a specific subclass?
For example:
URL blogFeedUrl = new URL("http://manishmaharzan.com.np/getJSON/json.json");
HttpURLConnection connection = (HttpURLConnection) blogFeedUrl.openConnection();
connection.connect();
...
9
votes
4
answers
5k
views
How to force "program to an interface" without using a java Interface in java 1.6
In java 1.8 they have wonderful new "default interface methods". In 1.6 how close can we come? The goal: use code to keep clients from being able to tell that a class is not a java interface. If we ...
3
votes
3
answers
544
views
How to "program to an interface"
I've read these questions:
Understanding "programming to an interface"
What is the point of an interface?
Does it always make sense to "program to an interface" in Java?
I don't ...
4
votes
3
answers
2k
views
Preemptive interfaces in Java - good, bad or "a matter of taste"
I frequently come across projects that strictly define an interface for each and every class. 90% of those interfaces feature only a single implementation. Proponents of these "preemptive interfacs" ...
0
votes
2
answers
1k
views
What is the difference when create Set<T> in java [closed]
When creating a Set in Java, what's the difference between the following? Which one should I use, and why?
Set< T > set = new HashSet<>();
HashSet< T > set = new HashSet<>();
3
votes
3
answers
564
views
Fruit obj=new Orange(); and Orange obj=new Orange(); if both works identically in my code, which is the less coupling one?
Suppose I have 2 classes (which don't show methods to look simpler):
public interface Fruit{
}
public class Orange implements Fruit{
}
, and assume I can use 2 ways to initialize Orange without ...
0
votes
2
answers
414
views
Declaration Types in OOP
I would like know opinions about the next sentence:
"In a object oriented static typed language you should declare variables and parameters as broad as possible and return types as narrow as possible"...