Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interfaces are strange...

 
Randy Smith
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi guys, I find that the concept of an Interface strange. Any method that live in an interface don't serve any purpose and doesn't do anything until it is implemented. If there are 10 guys using this interface, they could write that method in 10 different ways.

Why would anyone want an interface with no concrete methods at all other than a stop-gap multi-inheritance measure? I would appreciate if anyone could explain how can I fully exploit interfaces. Thanks!
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at it this way: The guru(interface) guarantees he will teach x stuff. How much is picked up, depends on the student.(concrete implementing class).

Randy Smith wrote:If there are 10 guys using this interface, they could write that method in 10 different ways.
True. but then these 10 classes are different. The interface has nothing to do with the implementation, just the contract (that the class will provide the functionality)
 
Campbell Ritchie
Sheriff
Posts: 48386
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But you can declare a MethodsLiveHere reference and use it, secure in the knowledge that it will have a placeholder() method.

You can create a List<E> reference, and assign an ArrayList<E> or a LinkedList<E> object to it, secure in the knowledge that if you ask whether it contains(someObject), that will work.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic