Java – Refer to objects by their interfaces

Bad: private HashMap<String, HashMap<String, String>> var1;

Good: private Map<String, Map<String, String>> var1;

http://stackoverflow.com/questions/3383726/java-declaring-from-interface-type-instead-of-class

http://docs.oracle.com/javase/tutorial/java/IandI/interfaceAsType.html

http://jtechies.blogspot.com/2012/07/item-52-refer-to-objects-by-their.html

 

Reason:

Provides flexibility down the line. For more info read above links.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s