Re: Abstract Factory Design Patterns Advice
On Jun 24, 9:36 am, DeMarcus <use_my_alias_h...@hotmail.com> wrote:
OK, I get your point. Why you say container is good for
polymorphism ?
In what situation container is more suitable than polymorphism ?
I mean that polymorphism and containers work very well together. You can
load a lot of different objects in for instance a std::vector and then
loop over the vector and run a common virtual method. Say you want to
initialize all your factories, then you don't have to write:
adminFactory.init();
hrFactory.init();
staffFactory.init();
but instead you just loop:
for( std::map<std::string, ObjectFactory*>::iterator i =
factoryMap.begin(); i != factoryMap.end(); ++i )
{
(*i).second->init();
}
I have a question here. After i create the appropriate user, how to
forward call to the user using this approach ?
It depends if the call is a common call receivable by all the users then
use polymorphism again:
class User // Interface
{
public:
virtual ~User() {}
virtual void receiveCall( const std::string& call ) = 0;
};
class AdminUser : public User
{
public:
virtual void receiveCall( const std::string& call ) { /* ... */ }
};
// Following may not be an optimal design, but rather a hint to your work.
User* user = factoryMap[userString]->createUser();
user->receiveCall( callString );
I not ignore your solution and advise but i just to execute my idea.
My solution is like this. Basically, there are two hierarchy which are
ObjecFactory which have three derived classes which are AdminFactory,
HRFactory and StaffFactory. Another class hierarchy is wraps login
session inside usernameType which have three derived classes also same
as above.
I was thinking the difficulties in creating concrete usernameType then
forward to concrete objectFactory to create the object. Now, i have
solution which is using factory method in usernameType hierarchy. Is
this possible ?
Thanks.
Please comment on this approach rather spoon feed me with some code
and explain why this approach doesn't works and other approach is
better.
Thanks.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]