Consider this code:
public class MyClass()
{
public MyClass()
{
}
public DoSomething()
{
using (var service = new CustomerCreditServiceClient())
{
var creditLimit = service.GetCreditLimit(
customer.Firstname, customer.Surname, customer.DateOfBirth);
}
}
}
We now want to refactor it to loosely couple it. We end up with this:
public class MyClass()
{
private readonly ICustomerCreditService service;
public MyClass(ICustomerCreditService service)
{
this.service= service;
}
public DoSomething()
{
var creditLimit = service.GetCreditLimit(
customer.Firstname, customer.Surname, customer.DateOfBirth);
}
}
Looks ok right? Now any implementation can use the interface and all is good.
What if I now say that the implementation is a WCF class and that the using statement before the refactoring was done was there for a reason. ie/to close the WCF connection.
So now our interface has to implement a Dispose
method call or we use a factory interface to get the implementation and put a using statement around that.
To me (although new to the subject) this seems like a leaky abstraction. We are having to put method calls in our code just for the sake of the way the implementation is handling stuff.
Could someone help me understand this and confirm whether I'm right or wrong.
Thanks