There is no really best practice.
Use interface Map<string> map = new Hashmap<string>();
:
- Hide the concrete implementation algorithm
- The most important is the interface, what you object can do not how it do it
Use concrete implementation Hashmap<string> map = new Hashmap<string>();
:
- Concrete implementation with all interface method and you can have some method specific to the implementation
After it's just a question of POO, i think the purist guys will only used interface because, it is more abstract and the concrete type (algorithm) can be easy updated.
But, in fact, create an interface for each type of class is really dirty for your project and create a multiple number of useless classes / interface. So it is not a good idea for me.
To conclude, i prefer to use what i really need. If it is important to stay generic, i use the interface Map, but in most case, i don't care of this and i prefer to be less abstract than possible for this container so i prefer to use HashMap.
In fact, it's more a troll and a discussion around a bear than a true response.
Each developer has is own feeling of this.