Factory Method: Define an interface for creating an object, but let subclasses decide which class to instantiate. The Factory Method pattern lets a class decide which kind of object to create through a method that subclasses or configuration can change. The caller asks for "a notifier" and gets an email, SMS or push notifier depending on the situation.
It keeps object creation in one place. If the logic for choosing changes, you update the factory, not every piece of code that needs a notifier.
What should you keep in mind with Factory Method?
In everyday PHP, this often appears as a simple static method like Notifier::for($user) or a factory class registered in the service container. Laravel's model factories for test data use the same name for a related idea. Do not add a factory when there is only one implementation and no sign of a second. A plain new is clearer until you need the flexibility.
Apply Spatie's Laravel and PHP coding standards for any task that creates, edits, reviews, refactors, or formats Laravel/PHP code or Blade templates; use for controllers, Eloquent models, routes, config, validation, migrations, tests, and related files to align with Laravel conventions and PSR-12.
Implement proven backend architecture patterns including Clean Architecture, Hexagonal Architecture, and Domain-Driven Design. Use this skill when designing clean architecture for a new microservice, when refactoring a monolith to use bounded contexts, when implementing hexagonal or onion architecture patterns, or when debugging dependency cycles between application layers.