문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top