I use Windows Communication Services (WCF) in my project.
In my project,
I write the function like below:
GetUserNameByUserId(int userId);
GetProductInformationByProductId(int productId);
But this naming have been coming more and more complex day by day.
For instance I have 5 parameters to pass to the function, in this case the function name will be like blow:
GetStackOverFlowByStackByOverByFlowByIdByStackOverFlow(string stack, string over, string flow, int id, string stackOverFlow);
And assume that I want to get with 2 parameters like blow:
GetStackOverFlowByIdByStackOverFlow(int id, string stackOverFlow);
I want to use function overloading like below:
public void abc(int i)
{
System.Console.WriteLine("abc" + i);
}
public void abc(string i)
{
System.Console.WriteLine("abc" + i);
}
public void abc(string i,int j)
{
System.Console.WriteLine("abc" + i + j);
}
That is to say, I want to write below functions:
GetStackOverFlow(int id);
GetStackOverFlow(int id, string name);
GetStackOverFlow(int id, string name, string StackOver);
.
.
Isn’t it?
Are there any methodology for that?
Or am I doing right?
I research and find this:
Function Overloading in WCF
public interface IMyService
{
[OperationContract(Name = "GetStringWithParam")]
string GetString(DateTime date);
[OperationContract(Name = "GetStringWithoutParam")]
string GetString();
}
and he said that
But i don’t prefer it as it is sometimes lead to confusion.
are there any other way?
Thanks.
You could use a class as a parameter.
and than create a method like this:
I have not included the
GetStackOverflowResponse classbut you get the idea of it.One of the benefits of this is that you could easily extend the class without breaking functionality of a client when a newer version of your Service is deployed.