The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

402622 (3) [Avatar] Offline
#1
Hi,

while reading this awesome book I learned about the concept of a leaky abstraction. I have a question related to this topic, I posted the same question on the stack exchange software engineering q/a site (https://softwareengineering.stackexchange.com/questions/385482/is-an-interface-exposing-async-functions-a-leaky-abstraction). I would like to know what do you think about this.

These days I'm refactoring a C# code base using dependency injection so that async calls are used instead of blocking ones. Doing so I'm considering some interfaces which represent abstractions in my code base and which needs to be redesigned so that async calls can be used.

As an example, consider the following interface representing a repository for application users:

public interface IUserRepository 
    {
      Task<IEnumerable<User>> GetAllUsers();
    }


According to the book's definition a *leaky abstraction* is an abstraction designed with a specific implementation in mind, so that some implementation details "leak" through the abstraction itself.

My question is the following: can we consider an interface designed with async in mind, such as IUserRepository, as an example of a Leaky Abstraction ?

Of course not all possible implementation have something to do with asynchrony: only the out of process implementations (such as a SQL implementation) do, but an in memory repository does not require asynchrony (actually implementing an in memory version of the interface is probably more difficult if the interface exposes async methods, for instance you probably have to return something like Task.CompletedTask or Task.FromResult(users) in the method implementations just for respecting the method signature).

What do you think about that ?

Thanks in advance.

Enrico
Steven van Deursen (43) [Avatar] Offline
#2
402622 (3) [Avatar] Offline
#3


I saw that thanks for helping !

Enrico