Basic Differences between Abstract class and Interface
Behaviour
Abstract Class
Interface
Multiple Inheritance
Not Possible
Possible
Inheritance Chain(of same type)
Possible
Not Possible
(does not fall under the inheritance chain of same type)
Concrete Functionality
Possible
Not Possible
Private Members
Not Possible
Possible
Type can be declared as method input parameter
Not Possible
(because instance could not be created)
Possible
(acceptable with fully implemented instance is being passed)
Structs can implement
Not Possible
Possible
Every member needs to be implemented
No
Yes
We can have the interface as the input type for some method which accepts only the objects which completely implements this interface. Following example shows this:
<asp:Button id="Button1" runat="server" OnClick="Goooooogle"/>
public partial class TestViewState_Default : System.Web.UI.Page
{
protected void Goooooogle(object sender, EventArgs e)
{
myClass myclass = new myClass();
DoSomeAction(myclass);
}
private void DoSomeAction(myInterface myinterface)
{
Response.Write(myinterface.myfield.ToString());
}
public class myClass:myInterface
{
int_ field;
public int myfield
{
get { return 12; }
set {_ field = value; }
}
public int getId()
{
return 190;
}
}
public interface myInterface
{
int myfield{get; set;}
int getId();
}
}
Originally posted on Things on Tech.