Something I saw in code of other plugin authors that I adapted is creating a “prepareVars” function, that prepares/initializes all the variables the component needs on every request, and call that in “onRun” and in every custom “onXY” action handler function. It’s a very useful pattern to avoid initializing the same variable at multiple points in the code.
To clarify here is the pattern mentioned by @marco.grueter
public function prepareVars()
{
// Set common page variables
}
public function onDoSomething()
{
$this->prepareVars();
// Do thing
}
public function onAnotherThing()
{
$this->prepareVars();
// Do thing
}