title: java command pattern example with Runnable class : Is Receiver missing?
body: <p>From <a href="https://stackoverflow.com/questions/1673841/examples-of-gof-design-patterns-in-javas-core-libraries/2707195#2707195">Examples of GoF Design Patterns in Java&#39;s core libraries</a> question, it was quoted that </p>
  
  <blockquote>
    <p>All implementations of java.lang.Runnable are examples of <strong>Command</strong> pattern. </p>
  </blockquote>
  
  <p>As per my understanding of Command pattern, </p>
  
  <p><strong><em>Client</strong> calls <strong>Invoker</strong> => <strong>Invoker</strong> calls <strong>ConcreteCommand</strong> => <strong>ConcreteCommand</strong> calls <strong>Receiver</strong> method, which implements abstract <strong>Command</strong> method</em>.</p>
  
  <p>Have a look at this working <a href="https://dzone.com/articles/design-patterns-command" rel="nofollow noreferrer">example</a></p>
  
  <p>Command pattern UML diagram from <a href="http://www.codeproject.com/Articles/106198/Design-Patterns-nuff-said" rel="nofollow noreferrer">this article</a> is shown as below.</p>
  
  <p><a href="https://i.stack.imgur.com/DcUaU.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DcUaU.jpg" alt="enter image description here"></a></p>
  
  <p>Have a look at this code:</p>
  
  <pre><code>public class ThreadCommand{
      public static void main(String args[]){
          Thread t = new Thread(new MyRunnable());
          t.start();
      }
  }
  class MyRunnable implements Runnable{
      public void run(){
          System.out.println("Running:"+Thread.currentThread().getName());
      }
  }
  </code></pre>
  
  <ol>
  <li><em>ThreadCommand</em> is <strong>Client</strong></li>
  <li><em>Runnable</em> interface is <strong>Command</strong></li>
  <li><em>MyRunnable</em> is <strong>ConcreteCommmand</strong></li>
  <li><em>Thread</em> is <strong>Invoker</strong> with <code>start()</code> method calling <strong>ConcreteCommand</strong> implementaiton ( which calls <code>run()</code> method)</li>
  </ol>
  
  <p><strong><em>Is Receiver missing here? Or Does MyRunnable play combined role of ConcreteCommand and Receiver</strong>?</em></p>