Why program to an interface rather than a concrete type?
Short answer
Depending on an abstraction decouples callers from implementations, enabling substitution, testing with mocks, and dependency injection.
Advertisement
AModel answer
Depending on an abstraction decouples callers from implementations, enabling substitution, testing with mocks, and dependency injection.
public OrderService(IOrderRepository repo) { }Real-world example
Swapping a SQL repository for an in-memory fake in unit tests without changing OrderService.