Reputation: 69
I am a novice in WCF. So, Please bear with me.
I have a WCF service that is consumed by many clients
Example: I have a service which calculates sum and that service is consumed by all the clients.Now I have a client who wants to give discount. I want to change the service to calculate discount for that particular client without affecting other clients. How to achieve that (I think it can be achieved with overloading.I need solutions other than overloading).
Upvotes: 1
Views: 57
Reputation: 69
Another solution i can think of is by using optional arguments
public float Add(float n1, float n2,float discount=0) {
return n1 + n2-discount;
}
This way the clients don't have to change their service. Only the clients who wish to avail discount can pass the discount parameter.
Upvotes: 0
Reputation: 7456
In my opinion its the best solution to overload your function.
The reason is, that you are calculating a different result if you include something like disount.
Lets say this in code:
public float Add(float nrOne, float nrTwo) {
return nrOne + nrTwo;
}
public float Add(float nrOne, float nrTwo, float discount) {
return nrOne + nrTwo - discount;
}
The other way could be, that you write a second function.
public float AddWithDiscount(float nrOne, float nrTwo, float discount) {
return nrOne + nrTwo - discount;
}
So your Client with granted discount could simply call that function instead of the clients without granted discount
Upvotes: 1