March 16, 2011

Need suggestions for naming 2 classes in PHP

Question by Jared

I have one class user that is initiated in /update/user.php when update.php is started. This class handles user related queries on the database, such as edit, delete, create, etc.

I’m in the process of creating a new class also named user in /src/user.php that will perform user related queries on the database but only to retrieve them (and output) them. Such as to retrieve their user id, usergroup, e-mail, etc.

I find the need to name them both user but obviously there will be conflicts when update.php is retrieved. What suggestions can you give for naming these two different classes, even though they are seperate areas in my library but perform similar operations?

Using PHP 4.

Answer by Fraser

If they both query, but only one writes, then I would suggest something like.

UserWrite
UserRead

or

UserCreate
UserAccess

Answer by Starx

I would suggest you create one class to create, edit, delete, and retrieve records related to the users. Then manage user Roles to limit the access to the methods, rather than creating two separate class for one object class.

Explanation with comparison to real world.

Let’s say we have class Car. When user with Mechanical Role (or a mechanic) uses the car class then, he will able to access methods like repair(), openHood(), where as when users with driving role (or drivers) will access drive() methods.

In this scenarios also it is very inappropriate to create CarMechanic class and CarDriver class.

I think I made my point.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!