Delegation: When an object is asked for a property it doesn't have, it forwards ("delegates") the lookup to its prototype. Delegation, in prototype-based languages like JavaScript, means an object passes a property lookup on to another object when it does not have the property itself. If dog.speak does not exist on dog, JavaScript checks its prototype, then that prototype's prototype, and so on.
This prototype chain is how JavaScript implements inheritance under the hood. Classes in modern JavaScript are a friendlier syntax on top of it.
What should you keep in mind with Delegation?
Understanding it helps with debugging. A method that seems to exist on every object comes from Object.prototype. Changing a prototype affects every object that delegates to it, which is why changing built-in prototypes such as Array.prototype is considered bad practice. In other languages, delegation also means an object forwarding calls to a helper object it holds, which is a common alternative to inheritance.
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.