OOP · Abstraction · The Deep Whale
Abstraction in WordPress
Show a simple interface — hide HTTP, OAuth, SQL, and vendor SDK details underneath.
WordPress developers interact with abstractions every day: you register a REST route without writing raw JSON responses, and you call wp_remote_get() without managing cURL. In plugins, abstract classes and interfaces let you swap Stripe for PayPal or MySQL for an external API without rewriting admin screens.
Core concept
Abstraction defines what a component does, not how. Callers depend on a stable contract — an abstract method, interface, or base class — while concrete implementations handle vendor-specific code behind that boundary.
WordPress core examples
- WP_REST_Controller — define routes and permissions; core handles HTTP serialization.
- WP_List_Table — admin tables share pagination and column logic; you fill rows.
- WP_HTTP — remote requests through one API regardless of transport.
- wpdb — prepared statements hide driver details (still use carefully).
Payment gateway abstraction
abstract class Payment_Gateway {
abstract public function process( float $amount );
public function log( array $data ): void {
error_log( wp_json_encode( $data ) );
}
}
class Stripe_Gateway extends Payment_Gateway {
public function process( float $amount ) {
return $this->stripe_api->charge( $amount );
}
}
Interface for multiple providers
interface Payment_Gateway_Interface {
public function charge( float $amount, string $token );
}
class Stripe_Gateway implements Payment_Gateway_Interface { /* ... */ }
class PayPal_Gateway implements Payment_Gateway_Interface { /* ... */ }
WooCommerce uses the same idea with WC_Payment_Gateway: checkout calls one API; each gateway plugin supplies the implementation. Your custom plugin can follow the same pattern for CRM, email, or storage backends.