Purpose and use of interfaces: Decoupling [Resolved]

Posted by Ray.Chayan under C# on 5/31/2012 | Points: 10 | Views : 9373 | Status : [Member] | Replies : 2
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




Responses

Posted by: Fool2code on: 5/31/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
Few things that i like to tell you , but first thing about your error.

Since you have not mentioned any axis specifier before your Interface it was assuming the interface to be internal
so where ever you are using it will give you the error of
"Inconsistent accessibility: parameter type 'className.ICommoanOperations' is less accessible than method 'className.Client.Export(abc.ICommoanOperations)"

since your method is public and interface is internal so if you access this method from outside the method will be accessible but the parameter will not be supplied , that's the reason it is giving error.
So to avoid this you can make this change.
public interface ICommoanOperations

{
void IExportData();
}


Ray.Chayan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 5/31/2012 [Member] Silver | Points: 25

Up
0
Down
post ur code in codes section..

Regards,
Singaravel M

Ray.Chayan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response