 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
xubo Guest
|
Posted: Fri Jun 03, 2005 3:22 am Post subject: object factory implementation problem |
|
|
In the object factory document, it always say " the implementation of
product also must register this function with the
productFactory..." for example I have a product named "grape"
// class declairation in grape.h
class grape: public fruit{
private:
.....
public:
__fastcall grape();
};
also, I have a object factory named "productFactory" which is defined as
Singleton.
// class declairation
class productFactory
{
public:
typedef fruit* (*CreateFruitCallBack)();
bool RegisterFruit(int fruitId, CreateFruitCallBack cFruitFn);
bool UnregisterFruit(int fruitId);
fruit* CreateFruit(int fruitId);
private:
.....
protected:
......
}
Now how can i implement the sentence of "the implementation of product also
must register this function with the
productFactory..." ? How can i create concrete product and register it
within class "grape"???
does it means that I should declair a function in the <grape.h> like this:?
class grape: public fruit{
private:
.....
public:
__fastcall grape();
};
fruit* getGrape(void);
???
// in the graph.cpp file
.....
fruit* getGrape()
{
return new grape;
}
......
The problem is still. How can i put the following registration code::::
<productFactory::Instance().RegisterFruit(10,getGrape);> ????
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Jun 03, 2005 7:06 am Post subject: Re: object factory implementation problem |
|
|
"xubo" <xu (AT) bbn (DOT) cn> wrote
| Quote: | Now how can i implement the sentence of "the implementation of
product also must register this function with the productFactory..." ?
How can i create concrete product and register it within class "grape"???
does it means that I should declair a function in the <grape.h> like
this:? |
Yes.
| Quote: | How can i put the following registration code::::
productFactory::Instance().RegisterFruit(10,getGrape);> ????
|
That is exactly what you do.
Gambit
|
|
| Back to top |
|
 |
xubo Guest
|
Posted: Fri Jun 03, 2005 7:43 am Post subject: Re: object factory implementation problem |
|
|
Sorry. my last question is where to put registration code
<productFactory::Instance().RegisterFruit(10,getGrape);> ???
the registration code can't put into function getGrape(void); If it is not
put in getGrape(), how can program execute this part of
code(productFactory::Instance().RegisterFruit(10,getGrape) ??
| Quote: | How can i put the following registration code::::
productFactory::Instance().RegisterFruit(10,getGrape);> ????
That is exactly what you do.
Gambit
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Jun 03, 2005 10:17 am Post subject: Re: object factory implementation problem |
|
|
"xubo" <xu (AT) bbn (DOT) cn> wrote
| Quote: | Sorry. my last question is where to put registration code
|
Anywhere you want. Preferrably someplace where it will only be called once,
such as at program startup, like in your MainForm constructor, or in main()
or WinMain() directly, or in a static object that is created globally.
Gambit
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|