Which one is better when compare with Interface and Abstract class ?

Questions by enjoy

Showing Answers 1 - 3 of 3 Answers

P Meshkovsky

  • Apr 5th, 2007

Inteface is concidered to be a best practice to use then Abstract(Template) Desing Pattern.
Inderface is more flexible is also forcess to maintain same code for Similar Objects but Abstract objects do the same. Abstract objects are based on Inheritance. Where Interface uses Delegation. Delegation is more flexible and can easly incorporate multiple types of objects.


  • Oct 29th, 2010

Both Interface and Abstract class have different usages. Interface is used to define that an object support a certain kind of functionality like any class that implements Comparable interface has the ability that its instances can be compared with each other. On the other hand Abstract class is used to define generalization, like a Fruit class may be an Abstract class having Specilized derived classes like Orange, Apple etc.

  Was this answer useful?  Yes

I prefer to Interface. Because the same feature can have different implementations in different Objects.And can also support for multiple Inheritance through Interfaces.

If you go for Abstarct Classes it should have some common functionality and common features in that class ofcourse it is also having abstract classes as well as Concrete Classes.We have to extend the available feature in our class.

But here the Interfaces we can implement our own features in our class.When ever a good programmer choose for Interfaces.

One Ex..In Threads Concept:

Every body choose to create Thread by useing Runnable interface not extends the Class Thread

Because of Object Oriented Design Pattern it is safe to using Interfaces.

class MyClass implements Runnable{                          //here we are using the
       public static void main(String[] args){                  // interface to create athread      
              Runnable r=new MyClass();            
              Thread t=new Thread(r);

             ----write here the run method-----

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.


Related Answered Questions


Related Open Questions