5 Replies - 281 Views - Last Post: 21 January 2013 - 10:26 PM Rate Topic: -----

#1 dulvinrivindu  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 51
  • Joined: 25-September 12

Interface declaration, need to clarify

Posted 21 January 2013 - 01:29 AM

public interface Relatable {
    
    // this (object calling isLargerThan)
    // and other must be instances of 
    // the same class returns 1, 0, -1 
    // if this is greater // than, equal 
    // to, or less than other
    public int isLargerThan(Relatable other);
}



in the method signature, Why do we use Relatable? Is it compulsary?
Is This A Good Question/Topic? 0
  • +

Replies To: Interface declaration, need to clarify

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3715
  • View blog
  • Posts: 5,972
  • Joined: 08-June 10

Re: Interface declaration, need to clarify

Posted 21 January 2013 - 01:43 AM

You use Relatable to limit the input parameters to only instance of classes that implement the Relatable interface.

Is it compulsory? No. You can use whatever type there you need. However, you'd need to make sure that whatever parameter value you allow there is capable of being compared to the Relatable instance the method belongs to; that it has the required attributes/methods to be compared using this method. If you allow an object that doesn't have the attribute/method the method uses to make the comparison, then you're in trouble.
Was This Post Helpful? 0
  • +
  • -

#3 dulvinrivindu  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 51
  • Joined: 25-September 12

Re: Interface declaration, need to clarify

Posted 21 January 2013 - 01:57 AM

Thanks. can you please direct me for more tutorials on implementing interfaces. Im new and confused. Thanks again.
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10437
  • View blog
  • Posts: 38,651
  • Joined: 27-December 08

Re: Interface declaration, need to clarify

Posted 21 January 2013 - 10:08 AM

Check out these tutorials:
Abstract Classes vs. Interfaces
Programming to an Interface, Not an Implementation
Was This Post Helpful? 0
  • +
  • -

#5 dulvinrivindu  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 51
  • Joined: 25-September 12

Re: Interface declaration, need to clarify

Posted 21 January 2013 - 09:54 PM

Thanks alot sir!
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10437
  • View blog
  • Posts: 38,651
  • Joined: 27-December 08

Re: Interface declaration, need to clarify

Posted 21 January 2013 - 10:26 PM

Glad I could help! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1