title: Notify bunching object with abstract methods
body: <p>What I'd like to:</p>
  
  <ul>
  <li>notify bunching objects in order:　B -> C -> D </li>
  <li>separate the notification methods to module.</li>
  </ul>
  
  <p>Then I wrote the code below:</p>
  
  <pre class="lang-rb prettyprint-override"><code>module AbstractModule
  def notifiable?
      raise "this should be overriden"
  end
  
  def observers
      raise "this should be overriden"
  end
  
  def notify
      puts "#{self.class.to_s} notification"
  end
  
  def notify_all
      notify
      observers.map{|o| o.notify_all} if observers &amp;&amp; notifiable?
  end
  end
  
  class B
      include AbstractModule
      def observers
          c_objects = 2.times.map{ C.new }
      end
  
      def notifiable?
          true
      end
  end
  
  class C
      include AbstractModule
      def observers
          d_objects = 3.times.map{ D.new }
      end
      def notifiable?
          true
      end
  end
  
  class D
      include AbstractModule
      def observers
          nil
      end
      def notifiable?
          false
      end
  end
  
  obj = B.new
  obj.notify_all
  </code></pre>
  
  <p>Actually it's my desired result and the result is :</p>
  
  <pre><code>B notification
  C notification
  D notification
  D notification
  D notification
  C notification
  D notification
  D notification
  D notification
  </code></pre>
  
  <p>But I'm dissatisfied with :</p>
  
  <ul>
  <li>B,C,D must implement <code>observers</code> and <code>notifiable</code> methods</li>
  </ul>
  
  <p>How do I refactor this code ?</p>