Skip to main content
PreparationZone Logo
PreparationZone
Back to Fundamentals

Fundamentals · Medium · Free

What is an interface? Why use interfaces in backend services?

FresherFundamentalsOOP & Language Fundamentals
Model answer

Interfaces in services

An interface defines a contract—implementations can change (Postgres vs in-memory) without touching callers. Enables dependency injection and clean architecture.

java
interface OrderRepository {
  Optional<Order> findById(UUID id);
  void save(Order order);
}
class JpaOrderRepository implements OrderRepository { /* ... */ }
Say interfaces at boundaries: DB, payment, email—core domain stays pure.