Discussions

EJB design: Interfaces vs abstract classes

  1. Interfaces vs abstract classes (6 messages)

    hi all
      Can any one explain me when to use abstract classes and when to use interfaces. I get confused on this.

    pl help

    regards
    sundar

    Threaded Messages (6)

  2. An abstract class can have implemented methods where interfaces cannot.

    Like an interface, an abstract class can also never be instantiated. Just FYI.
  3. Interfaces vs abstract classes[ Go to top ]

    One thing which I will like to point here is
    by default every interface is abstract.

    what I will suggest to you is for understanding usage of interface over abstract or other way round, try getting hang of some of the patterns. With patterns you will be able to understand what kind of situation is getting solved and why perticular pattern has interface or abstract classes.

    the thing is it is more of exp. and point of view, if you want behaviour to be encapsulated in you parent class as a default then go for abstract class if you just want to impose rule that any subclass shall implement some set of methods hence to have consistancy in method signature across the subclasses and hence finally hepling you code the module in more generalized way then go for interface.
  4. Interfaces vs abstract classes[ Go to top ]

    Chetan is right here, also note that if extending an abstract class you then can't obviously extend anything else. You can on the other hand implement as many interfaces as you like.

    Regards,
    Max
  5. Interfaces vs abstract classes[ Go to top ]

    One thing which I will like to point here is by default every interface is abstract.


    Huh?
  6. One thing which I will like to point here is by default every interface is abstract.

    >
    > Huh?

    As in it doesn't have implementation
  7. abstract...[ Go to top ]

    http://jinx.swiki.net/255

    See also: pages 78 through 88 in Josh Bloch's book "Effective Java"