• 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

Collections-usage design review

 
Ranch Hand
Posts: 782
Python Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


What is the difference between Design 1 & 2 ?
Which is better ?

Thanks
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Feels a little like a homework question. I'll get you going: design 1 is written to a more general interface than design 2. Which is better and why - you tell us.
 
Pho Tek
Ranch Hand
Posts: 782
Python Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my opinion, even if Design 1 is more general (Collection vs List), they are both equal. The public interface to both designs are the two methods getBars & addBar. And to a client, that's what matters.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you're right that the client won't care with the current state of things.

What if some other method of Foo needs to use a method that is on List but not on Collection? (Quick: To the JavaDoc! Are there any?) What if some refinement of the requirements reveals that Set would be better than List? (Back to the doc! What requirement would do that?) These are two possible changes that would lead you in different directions. Design is often about guessing what changes might come and avoiding being stuck when they show up.

How would a future change from Collection to List affect existing code inside Foo? From Collection to Set? From List to Set?
reply
    Bookmark Topic Watch Topic
  • New Topic