Abstraction
Abstraction is the principle of exposing only what a component does and hiding how it does it. In Java you achieve abstraction with interfaces and abstract classes — callers depend on the abstraction, not on the concrete implementation.
Interface-based abstraction
public interface PaymentProvider {
PaymentResult charge(Money amount, Card card);
}
public class StripeProvider implements PaymentProvider { ... }
public class PaypalProvider implements PaymentProvider { ... }
public class CheckoutService {
private final PaymentProvider provider;
public CheckoutService(PaymentProvider provider) {
this.provider = provider;
}
}
CheckoutService knows nothing about Stripe or PayPal. Swap one for the other — no code changes in CheckoutService.
Abstraction vs encapsulation
Closely related but distinct. Encapsulation is about hiding internal state (implementation details of a single class). Abstraction is about exposing a simplified contract at a higher conceptual level (what operations are possible, regardless of implementation).
Layered abstractions
Modern codebases stack abstractions: Repository abstracts over a database; Service abstracts over business rules; Controller abstracts over HTTP plumbing. Each layer depends on the abstraction of the layer below, not the concrete implementation.