title: Is there a better way to make an EventManager
body: <p>I made a little code for my <code>EventManager</code>, it works correctly, but the thing is, I created it with a lot of copy-paste, and I think that every time you start doing copy-paste on a few lines, your code is badly designed.</p>
  
  <p>So, having done a lot of copy-paste on that <code>EventManager</code>, I think it's time to find out if there is another way to make it (and there probably is, and probably better).</p>
  
  <p>What I achieved is that when an Event happens (<code>window.pollEvent(event)</code>), it calls the <code>onEvent(sf::Event, sf::RenderWindow*)</code> method of the <code>EventManager</code> class, and for every event I need to listen, I call all instances of the listener.</p>
  
  <p>Here's the class :</p>
  
  <pre><code>public:
      void registerKeyPressed(std::shared_ptr&lt;KeyPressedEventListener&gt; listener);
      void registerWindowResized(std::shared_ptr&lt;WindowResizedEventListener&gt; listener);
      void registerWindowFrameUpdate(std::shared_ptr&lt;WindowFrameUpdateEventListener&gt; listener);
  private:
      std::vector&lt;std::shared_ptr&lt;KeyPressedEventListener&gt;&gt; m_keyPressedListeners;
      std::vector&lt;std::shared_ptr&lt;WindowResizedEventListener&gt;&gt; m_windowResizedListeners;
      std::vector&lt;std::shared_ptr&lt;WindowFrameUpdateEventListener&gt;&gt; m_windowFrameUpdateListeners;
  </code></pre>
  
  <p>So, the thing is, it is a lot of code for only 3 listeners (I currently have 6, but it's not useful to show them as the code is always similar).</p>
  
  <p>My problem is that I want a class to be able to listen to one, two or more events at a time, so all my listeners have a different function that's called when the event happens. For example, these three listeners have the functions <code>onKeypressed(sf::Event);</code>, <code>onWindowResized(sf::Event, sf::RenderWindow* window);</code> and <code>onFrameUpdate(sf::RenderWindow* window);</code>. That's the only way I found to make this code work.</p>
  
  <p>It actually works, but I'd like to make something better, because it's a lot of code for every event :</p>
  
  <pre><code>void EventManager::onEvent(sf::Event event, sf::RenderWindow* window) { // The window argument is used further, but it's not useful to show it here as the code is quite the same
      switch (event.type) {
      case sf::Event::Resized:
          for (unsigned int i = 0; i &lt; m_windowResizedListeners.size(); i++) {
              if (m_windowResizedListeners.at(i)-&gt;onWindowResized(event)) break; // The events return a bool value : True if the loop has to stop (for an error, for example), false otherwise. I always return false unless an error happen, but it's in case I need to stop it.
          }
          break;
      }
  }
  void EventManager::registerWindowResized(std::shared_ptr&lt;WindowResizedEventListener&gt; listener) {
      m_windowResizedListeners.push_back(listener);
  }
  </code></pre>
  
  <p>And I have to duplicate this code for every event. If there's a bug, you understand it'll be a lot of work to correct it, so I hoped you could help me find a better way to achieve it.</p>
  
  <p>Thank you for your help.</p>