Domanda

Let's say we have an Interface called IAccountRepo and a class that implements this interface called AccountDbRepo that makes calls to SQL.

Now we have to replace this concrete class (AccountDbRepo) with AccountWebApiRepo, meaning that this class will make their operations in webapi.

Is the correct the naming of IAccountRepo, knowing that the concretes classes make web api calls? Should we rename Repo to Service?

Edit: Now if you have to create a second interface ICarRepo and you know the implementation will be calls to a webapi. Is correct to name it Repo?

È stato utile?

Soluzione

The whole point of programming to an interface is that you should be able to substitute one implementation with another implementation without changing the correctness of the system. This is also known as the Liskov Substitution Principle.

Thus, if you were to rename your interfaces based on a concrete implementation, it would be a Leaky Abstraction.

So, you shouldn't rename your interfaces for that reason. As Robert C. Martin explains in Agile Principles, Patterns, and Practices, "clients […] own the abstract interfaces" (chapter 11). Thus, you should name the interface based on how the client perceives it, not how it's implemented.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top