I have a piece of custom code that should be executed on different events but the code does not depend on anything the events send to the observer.
It's basically a dumb code like:
class MyObserver implements \Magento\Framework\Event\ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
do something here that does not depend $observer
}
}
Is there a downside in using this for multiple events like this (events.xml
)?
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="event_one">
<observer name="my_observer" instance="MyObserver" />
</event>
<event name="event_two">
<observer name="my_observer" instance="MyObserver" />
</event>
<event name="event_three">
<observer name="my_observer" instance="MyObserver" />
</event>
</config>
I can also create an abstract class that contains that code and create empty classes for each event, but I'm trying to avoid abstract classes and empty child classes.