Asynchronous Interfaces

Mark
1 min readMar 27, 2021

Microsoft really fucked the dog on this one. Say you have some class…

public interface ICalculator<T>
{
T Add(T augend, T addend);
T Subtract(T minuend, T subtrahend);
T Multiply(T multiplicand, T multiplier);
T Divide(T dividend, T divisor;
}

… but your implementation needs to be called asynchronously because it takes considerable time to complete; you need a new interface…

public interface IAsyncCalculator<T>
{
Task<T> Add(T augend, T addend);
Task<T> Subtract(T minuend, T subtrahend);
Task<T> Multiply(T multiplicand, T multiplier);
Task<T> Divide(T dividend, T divisor;
}

Like, literally wtf?!, right? Why the hell should my fucking interface need to know about the bloody implementation? This is just ridiculous. Interfaces aren’t meant to leak implementation details. They’re just meant to be a contract. You could have just let us do…

public class MyAsyncCalculator : async ICalculator<int>
{
...
}

… and done the Task wrappering for us. Maybe next time you’ll get this shit right.

--

--