java - Why to keep interface as reference? -


this question has answer here:

i have observed in java programming language, code following:

list mylist = new arraylist();

why should not use following instead of above one?

arraylist mylist = new arraylist(); 

just avoid tight coupling. should in theory never tie implementation details, because might change, opposite interface contract, supposed stable. also, simplifies testing.

you view interface overall contract implementing classes must obey. instead, implementation-specific details may vary, how data represented internally, accessed, etc. - information you'd never want rely on.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -