Source: sebastiandedeyne.com

Granular interfaces
A few weeks ago a spec change for an application we’re working on forced us to refactor part of the codebase. It was food for thought about the flexibility granular interfaces provide, and choosing the right abstraction at the right time.

After the bundle is purchased, registrations need to be created for the underlying courses, not the bundle itself.

class Bundle implements Product, CreatesRegistrations { public function __construct( public array $courses ) { } public function createsRegistrationsFor(): array { return $this->courses; }}

If we want to know wether a product will create a registration, we have to check for both the Registrable and CreatesRegistrations interfaces.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners