Hi Rajesh. i explain to you very simple with my sample code i hope to help you.
interface is a Standardize way for your classes for now. see the example
:: When you Use of Interface ITV you are saying all of TV such as "Monitor","Home Theater","LCD","LED",and so on must have this features and method and in order to TV Can have more own features.
class Monitor : ITV
{
public int Number_HDMI_Port { get; set; }
public int Number_USB3_Port { get; set; }
public void Power(bool on)
{
if (on) Console.WriteLine(" the TV is ON");
else Console.WriteLine(" the TV is OFF");
}
}
class HomeTheater : ITV
{
public int Number_HDMI_Port { get; set; }
public int Number_USB3_Port { get; set; }
public void Power(bool on)
{
if (on)
{
Console.WriteLine(" Shows the Menu for ON the Screen");
Console.WriteLine(" The TV is ON");
}
else
Console.WriteLine(" the TV is OFF");
}
}
interface ITV
{
int Number_HDMI_Port { get; set; }
int Number_USB3_Port { get; set; }
void Power(bool on);
}
:: but when you can use the Abstract Class that You Have one or more Abstract Members Class. Such as a Method that Has no body and it's can not "static" or "virtual"
Example:
abstract class TwoDShape
{
private double width;
public double Width
{
set { this.width = value < 0 ? -value : value; }
get { return this.width; }
}
private double height;
public double Height
{
set { this.height = value < 0 ? -value : value; }
get { return this.height; }
}
public abstract double Area();
}
class Triangle : TwoDShape
{
public override double Area()
{
return (Width * Height) / 2;
}
}
class Rectangle : TwoDShape
{
public override double Area()
{
return Width * Height;
}
}