Many PHP systems will implement object types (such as Models) that allow a client programmer to define a method in their own classes something like this
class Car extends Model
{
public function _afterSave()
{
//do something every-time this model is saved
}
}
In documentation and tutorials, this pattern is usually introduced as an “observer/listener” pattern.
However, while you could describe these method as listening for actions on the parent class, this appears to be something that’s very different from the classic OOP observer pattern.
Is there a formal name of the pattern that allows client-programmers to define these sorts of before/after methods, or is this just something early PHP developers ginned up before the language developed its java/C# like OOP?
Assuming that the calling of these methods is performed by Model or some other part of the frameowrk (I don’t know PHP) this is the Template Method pattern, with the methods that serve as extension points being frequently called hooks.