Home  /  Questions  /  Question

58   94.9
Sep 03, 2010

Question on Factory Method

Hi all,

I work on bus terminal project that website users can reserve and purchase bus tickets on. I have 2 levels of users: admin and other users. Admin and other users classes are empty and don't have any attribute. Their attributes are common and stored in their parent class (members super class). Child classes are different only in their methods (due to access permissions).

This hierarchy is stored in one table in SQL Server which consists of these fields: Memberid, Email (or Username), Password and Usertype. I don't have Usertype attribute in my parent class in class diagram. This field is just in the table on the database.

My first question is: How can I use Factory Method for detecting user type?
My second question is: Is it good that I create a class for permissions?

100   96.6
Sep 06, 2010

HI Yekta,

I am not sure whether I got your question correctly, but here my comments based on my understanding:

1. You can define the virtual function in parent class as GetUserType() and implement the same in the derived class
which returns their own type.

2. Generally for the permission, Enum is preferred datatype to use. Because it is value-type whereas class will be reference type which ask for more processing.

But at the end of the day it all depends on the requirements of your application.

- Saurabh

50   50
Sep 06, 2010
Hi Yekta:

I don't see the need for you to use Factory Pattern. You can have a basic user class with all the needed parameters and methods. Any way to authenticate the user you need to pass the username and password to the database, along with this action you can get back the user class filled with the details and permissions which would tell you the user type. These are my thoughts and it is left to you to decide the best options available

Thanks and regards 

50   50
Sep 20, 2010
Hi Yekta,

Q1: How can I use Factory Method for detecting user type?

A1: For this scnerio I feel Factory Method not required.

Q2: Is it good that I create a class for permissions?

A2: U can have permission class, which will have Admin and Gust currently. In future if new role come you can add very well in this class its self.