Advertisement
llsumitll

Factory design

Jan 29th, 2023
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | Source Code | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Invoice
  5. {
  6. public:
  7.     virtual void printInvoice() = 0;
  8. };
  9.  
  10. class clsInvoiceWithHeader : public Invoice
  11. {
  12. public:
  13.     void printInvoice()
  14.     {
  15.         cout << "Hello Client -  I am clsInvoiceWithHeader" << endl;
  16.     }
  17. };
  18. class clsInvoiceWithoutHeader : public Invoice
  19. {
  20. public:
  21.     void printInvoice()
  22.     {
  23.         cout << "Hello Client -  I am clsInvoiceWithoutHeader" << endl;
  24.     }
  25. };
  26.  
  27. class FactoryInvoice
  28. {
  29. public:
  30.     static Invoice * getInvoiceType( int inttype) ;
  31. };
  32. //static Invoice * invoice = nullptr;
  33.  
  34.  
  35.  
  36. Invoice * FactoryInvoice::getInvoiceType( int inttype)
  37. {
  38.         Invoice * i = nullptr;
  39.         if( inttype == 1)
  40.         {
  41.             return (new clsInvoiceWithHeader());
  42.         }
  43.         if ( inttype == 2)
  44.         {
  45.             return (new clsInvoiceWithoutHeader());
  46.         }
  47.         else
  48.             return nullptr;
  49. }
  50.  
  51. int main()
  52. {
  53.     Invoice* iv = FactoryInvoice::getInvoiceType(1);
  54.     iv -> printInvoice();
  55.     return 0;
  56. }
  57.  
  58.  
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement