aspose file tools*
The moose likes Beginning Java and the fly likes interfaces are strange... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "interfaces are strange..." Watch "interfaces are strange..." New topic
Author

interfaces are strange...

Randy Smith
Ranch Hand

Joined: Mar 27, 2011
Posts: 44


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

Joined: Jul 26, 2007
Posts: 10451
    
    8

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)


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: interfaces are strange...