Hi to understand the purpose of interface for code Decoupling
I have written bellow mentioned code in Console
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ExporttoExcel obj = new ExporttoExcel();
Client cl = new Client();
cl.Export(obj);
}
}
interface ICommoanOperations
{
void IExportData();
}
public class ExporttoPdf : ICommoanOperations
{
public void IExportData()
{
Console.WriteLine("ExportDataToPdf....");
}
}
public class ExporttoExcel : ICommoanOperations
{
public void IExportData()
{
Console.WriteLine("ExportDatatoExcel....");
}
}
public class Client
{
public void Export(ICommoanOperations InterfaceObj)
{
InterfaceObj.IExportData();
Console.ReadLine();
}
}
}
but it shows an error at Export method definition
Inconsistent accessibility: parameter type 'ConsoleApplication1.ICommoanOperations' is less accessible than method 'ConsoleApplication1.Client.Export(ConsoleApplication1.ICommoanOperations)' C:\Users\259788\AppData\Local\Temporary Projects\ConsoleApplication1\Program.cs
but when I have changed the
Export method definition like
public void Export(ExporttoExcel InterfaceObj)
{
InterfaceObj.IExportData();
Console.ReadLine();
}
the error gone. Can you pls tell me the problem in my first code.?
pls refer the article
http://www.dotnetfunda.com/articles/article1340-purpose-and-use-of-interfaces.aspx