As my very small and insignificant library of knowledge on Java grows, I've come across a question: Why is it that sometimes people instance by interface like :
List<Object> someList = new ArrayList<>();
/*
OR
*/
Animal minnie = new Cat();
instead of just instancing by the class itself :
ArrayList<Object> someList = new ArrayList<>();
/*
OR
*/
Cat minnie = new Cat();
- Which one is better or preferred? - What difference does it make? - (This is complete guesswork) Doesn't it take more memory if you instance by interface? I've read an answer from StackOverflow, something about loose coupling, but I'm still lost on this.