tags:

views:

211

answers:

5

OOP interfaces.

A: 
  1. Interface totally keeps away that implementation knowledge from client.
  2. It supports us to change their behaviour dynamically.It means that, it will act depends on dynamic specilization(or substitution).
  3. This gives very good abstraction about the object to client.
  4. It avoids client broken, even developer made some changes on implimentation or add new specilization(new implementation).
  5. So it gives open way to extend and implementation.

Programming language (C#, java )

in inheritence is not support the multiple inhertence but interface is supported multiple inhertence because imterface is advatage over the inhertience

Pranay Rana
I would +1 this if it wasn't written so horrible that you have to read every sentence twice.
dbemerlin
Markdown has support for lists, please use them when appropriate (and don't throw text in a code block like that!)
Jasper
@dbemerlin I would vote your comment as being great if you would be honest and admit that you needed to read each item for more than two times.
thelost
+2  A: 

Interfaces are very useful when you need a class to operate on generic methods implemented by subclasses.

public class Person
{
  public void Eat(IFruit fruit)
  {
    Console.WriteLine("The {0} is delicious!",fruit.Name);
  }
}

public interface IFruit
{
   string Name { get; }
}
public class Apple : IFruit
{
  public string Name
  {
    get { return "Apple"; }
  }
}
public class Strawberry : IFruit
{
  public string Name
  {
    get { return "Strawberry"; }
  }
}
Heini Høgnason
A: 

Basically Interfaces allow a Program to change the Implementation without having to tell all clients that they now need a "Bar" Object instead of a "Foo" Object. It tells the users of this class what it does, not what it is.

Example:

A Method you wrote wants to loop through the values given to it. Now there are several things you can iterate over, like Lists, Arrays and Collections.

Without Interfaces you would have to write:

public class Foo<T>
{
    public void DoSomething(T items[])
    {
    }

    public void DoSomething(List<T> items)
    {
    }

    public void DoSomething(SomeCollectionType<T> items)
    {
    }

}

And for every new iteratable type you'd have to add another method or the user of your class would have to cast his data. For example with this solution if he has a Collection of FooCollectionType he has to cast it to an Array, List or SomeOtherCollectionType.

With interfaces you only need:

public class Foo<T>
{
    public void DoSomething(IEnumerable<T> items)
    {
    }
}

This means your class only has to know that, whatever the user passes to it can be iterated over. If the user changes his SomeCollectionType to AnotherCollectionType he neither has to cast nor change your class.

Take note that abstract base classes allow for the same sort of abstraction but have some slight differences in usage.

dbemerlin
+15  A: 

In my own experience I find interfaces very useful when it comes to design and implement multiple inter-operating modules with multiple developers. For example, if there are two developers, one working on backend and other on frontend (UI) then they can start working in parallel once they have interfaces finalized. Thus, if everyone follows the defined contract then the integration later becomes painless. And thats what interfaces precisely do - define the contract!

Basically it avoids this situation : alt text

Gopi
Very funny and suggestive :)
thelost
Hey, this reminds me of my work... which in turns reminds me... have to get back to it (D*mn you SO!)
dbemerlin
unfortunately refactoring won't be easy for those guys as for software people
Arseny
+1  A: 

Interfaces are very useful, in case of multiple inheritance.

Sameer Joshi