Results 1 to 6 of 6
  1. #1
    javarishi is offline Member
    Join Date
    Apr 2008
    Posts
    91
    Rep Power
    0

    Default Interface Vs Abstract Class

    Can AnyOne Say, When Exactly, We Need To Go For An Abstract Class, And An

    Interface? On Basis Of What We Need To Make A Decision?

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    In my programming practice, if I want to change something on my design frequently, I go for an interface.

    Abstract class used for some common behaviors.

  3. #3
    javarishi is offline Member
    Join Date
    Apr 2008
    Posts
    91
    Rep Power
    0

    Default

    Thanks Eranga. Abstract Class Is Clear. In Case Of Interface, you mean to say if the method signature changes frequently, then we need to put it inside an interface? Can you please, brief me please?

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Yep, you are right. Say I have an interface like this,

    Java Code:
    interface Test{
       boolean isLess(Object a);
       boolean isSmall(Object a);
       boolean isEqual(Object a);
    }
    In all case I'm looking different implementation, with the same arguments actually. There are large number of such cases can be found in Java.

  5. #5
    ferranb is offline Member
    Join Date
    Jun 2008
    Posts
    22
    Rep Power
    0

    Default

    Use abstract classes when you want to "force" to derived classes to implement some code.

    Use interfaces when you want to define a behavior that can define any class that implement it on different hierarchies. When a class implements an interface is saying "I'm able to do that especific thing". When you subclass a class you are saying "I'm like my parent and more".

    Ferran

    Ferran

  6. #6
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

Similar Threads

  1. difference between Abstract and interface
    By mrark in forum New To Java
    Replies: 3
    Last Post: 11-07-2009, 04:20 AM
  2. Can this be done using abstract class??
    By romina in forum New To Java
    Replies: 6
    Last Post: 03-02-2009, 12:46 PM
  3. Replies: 0
    Last Post: 04-02-2008, 07:04 AM
  4. Abstract Class
    By gapper in forum New To Java
    Replies: 4
    Last Post: 01-31-2008, 01:25 PM
  5. Abstract Class question
    By maa11235 in forum New To Java
    Replies: 1
    Last Post: 01-05-2008, 10:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •