FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
Database
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
January 01, 2003

Multithreaded Programming with the Command Pattern

(Page 5 of 6)
Multithreaded Programming with the Command Pattern

Listing 4 The Command pattern



#include <iostream>

// base command class
class Command
{
public:
  Command () {}
  ~Command () {}

  // the actual command logic resides in Execute ()
  virtual void Execute () = 0; 
};

class Command_A : public Command
{
public:
  Command_A () {}
  ~Command_A () {}

  void Execute () { std::cout << "Doing some work" << std::endl; }
};

class Command_B : public Command
{
public:
  Command_B () {}
  ~Command_B () {}

  void Execute () { std::cout << "Doing some other work" << std::endl; }
};

int main ()
{
  Command_A a;
  Command_B b;

  Command* Commands[ 2 ];

  Commands[ 0 ] = &a;
  Commands[ 1 ] = &b;

  Commands[ 0 ]->Execute ();
  Commands[ 1 ]->Execute ();

  return ( 0 );
}

Previous Page | 1 | 2 | 3 | 4 | 5 | 6 Next Page
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK