Abstract Factory Design Patterns Advice
Hello to all, i would like to create a family of object at run time
rather than hard coded in main.
My situation is like this.
ObjectFactory(Abstract) inherits by three classes which are AdminOF,
HumanPersonnelOF and StaffOF.
Moreover, there are another hierarchy which its interface is
concretePosition which inherits by three classes which are Admin,
HumanPersonnel and Staff.
I would like to create the object based on their user name when login
in the following format.
Admin - A0000
HumanPersonnel - H0000
Staff - S0000
Then, they can access their particular function which have option
If username == 'A' then create Administrator object at run time
else if usernmae = 'H' then create HUMANPersonnel object
else if username == 'S' then create Staff.
I want something like this but i don't want the if statement but i
need them in two class hierarchy with polymorphism.
That's means i receive something in abstract base class and call the
actual type of derived class creator.
Last time, i wrote something similar but using template argument fixed
it at compile time.
Here is my code.
void createInstance() = 0;
class AdministratorFactory : public objectFactory
class HRFactory : public objectFactory
class StaffFactory : public objectFactory
I could find any mechanism to determine usernameType and call the
class login contains a std::string username and password.
There are two approaches in my head right now.
1. Without polymorphism
2. With polymorphism
1. I can just create the object using if statement such as
if login.username == 'A"
else if login.username == 'H'
else if login.username == 'S'
I could write this if statement using template too but i would like to
master C++ polymorphism.
2. The difficulties of this approach is to construct the appropriate
type based on the username.
If the login.username is 'A' then create AdminUserType and its member
function will called createInstance() to the appropriate type.
This is my question How to construct usernameType based on
login.username and forward the request to createInstance() method.
I really need your help.
Thanks for your help.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]