How does the Factory Method Pattern differ from a static invoker in PHP?

The Factory Method Pattern is a design pattern that defines an interface for creating objects, but lets subclasses decide which class to instantiate. This allows for more flexibility and easier maintenance of code. On the other hand, a static invoker in PHP typically involves directly calling a static method on a class without any abstraction or flexibility.

// Factory Method Pattern example
interface VehicleFactory {
    public function createVehicle();
}

class CarFactory implements VehicleFactory {
    public function createVehicle() {
        return new Car();
    }
}

class BikeFactory implements VehicleFactory {
    public function createVehicle() {
        return new Bike();
    }
}

// Static invoker example
class StaticInvoker {
    public static function createCar() {
        return new Car();
    }
}

// Usage of Factory Method Pattern
$carFactory = new CarFactory();
$car = $carFactory->createVehicle();

// Usage of Static invoker
$car = StaticInvoker::createCar();