How can the use of a Factory class help reduce unnecessary coupling between classes in PHP applications?

Using a Factory class can help reduce unnecessary coupling between classes in PHP applications by abstracting the creation of objects. This allows classes to depend on interfaces rather than concrete implementations, making the code more flexible and easier to maintain.

interface Product {
    public function getName(): string;
}

class ConcreteProduct implements Product {
    public function getName(): string {
        return 'Concrete Product';
    }
}

class ProductFactory {
    public static function createProduct(): Product {
        return new ConcreteProduct();
    }
}

$product = ProductFactory::createProduct();
echo $product->getName(); // Output: Concrete Product