• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Coding standards while using Collection

 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello sir, friends, mam,

I heard that its a good practice that while using collection api you must have an interface of collection type on the left hand side of the assignment operator. Concrete implementations should be used only while making instances.
Example
(Correct approach) List sList = new Vector();
(Wrong approach) Vector sVector = new Vector();

This is what I have heard from my friend. Is this really taken into consideration especially in coding standards. I am hearing this for the first time .Can anyone please comment whether such approach should be followed or is it just an individual's perception ?

Waiting for your replies.

Thanks and Regards
Rohit.
 
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rohit, you can find the answer in the following thread:
https://coderanch.com/t/379305/java/java/List-Vs-ArrayList

I hope the above thread answers your query.
 
Rohit Bhagwat
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Reddy. Indeed it answered my question..

Thanks and Regards
Rohit.
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Java (Intermediate)
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Is this really taken into consideration especially in coding standards.


Yes. It is certainly grounds for a failure of code review in practice. More so, not declaring public methods on an interface results in failure (this is usually automatically enforced).

Then, where the core API is "not so broken" in that it follows this rule (as collections (almost) do), use them appropriately - with an interface reference. I've heard some really poor excuses for contravening this rule, so no doubt you'll hear some more. Imagine a world where the language did not permit a reference of a concrete type...
 
today's feeble attempt to support the empire
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic