Interface or an Abstract Class: which one to use?

Interface or an Abstract Class: which one to use?

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Interface vs. Abstract Class: Choosing the Right Tool for PHP

When designing a PHP architecture, the choice between defining a contract via an interface and providing a base implementation in an abstract class is fundamental. The decision isn't arbitrary; it hinges on whether you need to enforce behavior or provide shared logic. Understanding the specific constraints and capabilities of each construct prevents common design pitfalls like accidental state leakage or impossible-to-extend hierarchies.

Enforcing Contracts with Interfaces

Use an interface when your primary goal is to define a contract that disparate classes must adhere to, without providing any implementation details. An interface guarantees that implementing classes possess certain methods, ensuring polymorphism across the codebase. This is particularly useful for dependency injection, where you can type-hint against an interface to accept any implementation that satisfies the requirements.

interface RepositoryInterface {
    public function findById(int $id): ?array;
    public function save(array $data): int;
}

In this scenario, RepositoryInterface dictates the API surface. You might have a DatabaseRepository, CacheRepository, or MockRepository implementing this same interface. Because interfaces cannot contain state (properties) and historically could not include method implementations (prior to PHP 8's abstract methods), they force consumers to fill in the logic entirely.

A critical limitation arises when you attempt to mix inheritance with interfaces. A class can extend only one parent class, but it can implement multiple interfaces. If your design requires a class to inherit both state and behavior from a base class while also adhering to multiple contracts, relying solely on an interface for the shared logic is impossible. This is where abstract classes become necessary.

Providing Shared Logic with Abstract Classes

An abstract class is the correct choice when you need to share implementation details among related subclasses. Unlike interfaces, abstract classes can contain concrete methods, protected properties, and constructors. This allows you to define common behavior that all children inherit, reducing code duplication.

abstract class BaseService {
    protected string $configPath;

    public function __construct(string $path) {
        $this->configPath = $path;
    }

    abstract public function fetchData();

    public function validateConfig(): void {
        // Shared logic available to all subclasses
        if (empty($this->configPath)) {
            throw new \InvalidArgumentException('Config path is missing');
        }
    }
}

Here, BaseService enforces the presence of fetchData() via an abstract method but provides a shared constructor and validation logic. Subclasses like UserService or ProductService automatically gain access to $this->configPath and the validateConfig() method without needing to re-implement it.

Attempting to convert an existing abstract class into an interface is rarely a simple find-and-replace operation. If your current abstract class contains protected properties or concrete methods, you cannot simply switch to an interface unless you refactor those elements into separate interfaces or move the logic into a different inheritance hierarchy. This migration often involves breaking changes to existing implementations because interfaces do not support state or default behavior in the same way classes do.

Combining Both Strategies

In modern PHP (8.0+), the boundary blurs slightly with the introduction of abstract methods within interfaces, and properties are still technically allowed but discouraged for defining contracts. However, the architectural distinction remains: use interfaces for decoupling components via contracts, and use abstract classes for sharing implementation details among a single inheritance tree.

If you find yourself needing to enforce multiple contracts while sharing state, you will inevitably need a combination of both. You might define an interface like LoggableInterface and implement it alongside an abstract class that handles database connection logic. This hybrid approach requires careful planning to avoid circular dependencies or overly complex hierarchies.

For teams using the Laravel framework, this distinction is even more pronounced. Laravel's Eloquent ORM relies heavily on interfaces like ModelContract for trait composition, while base classes handle shared repository patterns. When extending these systems, adhering to these patterns ensures compatibility with the broader ecosystem. For deeper insights into building robust architectures that leverage these patterns effectively, resources from https://laravelcompany.com offer practical guidance on structuring applications that balance flexibility and stability.

Final Decision Matrix

Before defining a new contract, ask: "Do I need to share state or default logic?"

  • Yes: Use an abstract class. You can define protected properties, constructors, and concrete helper methods.
  • No: Use an interface. Define only the method signatures required for polymorphism, ensuring maximum flexibility for implementing classes to choose their own storage mechanisms or strategies.

Misunderstanding these constraints often leads to rigid codebases where adding new features requires modifying existing interfaces or abstract classes in ways that break single inheritance rules. By respecting the strengths of each construct, you create a system that is both extensible and maintainable.

Our network