Factory vs Multipurpose constructor for creating object on event
<p>I have two "modules" <code>PanelManager</code> and <code>Panel</code> which I want to be as independent as possible so I use <code>events</code> for communication between them. This way you can run each module independently on if the other one is running and you can plug or unplug modules dinamically just setting or removing the listeners.</p>

<p>The <code>PanelManager</code> module dispatches a <code>newPanel</code> event whenever it needs a new panel, and listens for <code>newPanelCreated</code> events.</p>

<p>The <code>Panel</code> module listens for the <code>newPanel</code> events, creates a new Panel and dispatches a <code>newPanelCreated</code> custom event with the new panel as <code>{detail}</code>.</p>

<p>To achive this I can design the <code>Panel</code> module in two different ways: the first is a <code>PanelFactory</code> class that sets the listeners when instantiated and creates instances of a <code>Panel</code> class. The second is just one <code>Panel</code> class with a flag in the constructor so if it's instantiated with a <code>true</code> flag it just sets the listeners, but if instantiated with a <code>false</code> flag it acts as a regular <code>Panel</code>. This way the same class could act as <em>Factory</em> and <em>Panel</em> at the same time.</p>

<p>Which approach would you recommend? Is there a better way to achieve this?</p>