Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 7th, 2006, 06:45 AM
sunny
Guest
 
Posts: n/a
Default Whether the following program implement the factory Design

Does this following program implement the factory design.if not what
are things that i have to change in order to make this following
program to be designed to factory design pattern.

#include<iostream>
Quote:
using namespace std;
>
class Quad
{
public:
void Area();
void Desc();
};
>
class Square : public Quad
{
public:
Square() {};
>
void Area(int x)
{
cout<<"Area of square is = "<<x*x<<endl;
}
>
void Desc()
{
cout<<"This Derived class Square from Base Class Quad"<<endl;
}
};
>
class Rectangle : public Quad
{
public:
Rectangle() {};
>
void Area(int x, int y)
{
cout<<"Area of Rectangle is = "<<x*y<<endl;
}
>
void Desc()
{
cout<<"This Derived class Rectangle from Base Class Quad"<<endl;
}
>
};
>
class Creator
{
public:
Quad* Creator::Create(int id)
{
if (id==2)
return new Square;
else
return new Rectangle;
}
};
>
int main(int argc, char* argv[])
{
Creator mcreator;
if (argc<=2)
{
Square *square = reinterpret_cast<Square*>(mcreator.Create(2));
square->Area(3);
square->Desc();
}
else
{
Rectangle *rectangle =
reinterpret_cast<Rectangle*>(mcreator.Create(1));
rectangle->Area(3,4);
rectangle->Desc();
}
>
return 0;
}
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles