Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Collections-usage design review  RSS feed

 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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

Thanks
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!