Exemplo n.º 1
0
int main(int argc , char *argv [])
{
  Factory *factoryA = new FactoryA ();
  Product *productA = factoryA->CreateProduct();
  productA->Show();
 
  Factory *factoryB = new FactoryB ();
  Product *productB = factoryB->CreateProduct();
  productB->Show();
 
  if (factoryA != NULL)
  {
    delete factoryA;
    factoryA = NULL;
  }
 
  if (productA != NULL)
  {
    delete productA;
    productA = NULL;
  }
 
  if (factoryB != NULL)
  {
    delete factoryB;
    factoryB = NULL;
  }
 
  if (productB != NULL)
  {
    delete productB;
    productB = NULL;
  }
  return 0;
}
Exemplo n.º 2
0
//客户端
int main(int argc,char* argv[]){

    Factory *ProductFactory = new Factory();
    Product *productObjA = ProductFactory->CreateProduct(TypeA);

    if(productObjA != NULL)
        productObjA->Show();

    Product *productObjB = ProductFactory->CreateProduct(TypeB);

    if(productObjB != NULL)
        productObjB->Show();

    Product *productObjC = ProductFactory->CreateProduct(TypeC);
    if(productObjC != NULL)
        productObjC->Show();

    delete ProductFactory;
    ProductFactory = NULL;

    delete productObjA;
    productObjA = NULL;
    delete productObjB;
    productObjB = NULL;
    delete productObjC;
    productObjC = NULL;

    return 0;
}