BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

object factory implementation problem

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++)
View previous topic :: View next topic  
Author Message
xubo
Guest





PostPosted: Fri Jun 03, 2005 3:22 am    Post subject: object factory implementation problem Reply with quote



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





PostPosted: Fri Jun 03, 2005 7:06 am    Post subject: Re: object factory implementation problem Reply with quote




"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





PostPosted: Fri Jun 03, 2005 7:43 am    Post subject: Re: object factory implementation problem Reply with quote



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)Wink??

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





PostPosted: Fri Jun 03, 2005 10:17 am    Post subject: Re: object factory implementation problem Reply with quote


"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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.