Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old October 9th, 2008, 05:35 PM
Anthony Smith
Guest
 
Posts: n/a
Default Design question: User objects and a Role object

I have a user object that is set when a user logs in. There are also
permissions that I get about the user from a web service. Currently I
take the results from those web services and store them as XML in the
user object so I can parse it when I need to look at them. I wanted to
turn the xml permissions into ROle objects, but does that mean that my
User class needs to make reference to the Role class?

User class example

class User{

protected $firstName;
protected $lastName;
protected $employeeNumber;
protected $orgCode;
protected $roles; //Could this be an object of my class Role?
protected $scope;
protected $type;
protected $primaryAssignmentsXML = null;
protected $securityRolesXML = null;

.... getters ad setters



getRole(roleName){
//get the securityRolesXML and then parse it setting the Role
Object

$role = new Role();
$role->setName();
$role->setFunction();


return $role;
}


Is this how I should be going about this?
  #2  
Old October 9th, 2008, 06:35 PM
R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
Default Re: Design question: User objects and a Role object

On Oct 9, 9:31 pm, Anthony Smith <mrsmi...@hotmail.comwrote:
Quote:
I have a user object that is set when a user logs in. There are also
permissions that I get about the user from a web service. Currently I
take the results from those web services and store them as XML in the
user object so I can parse it when I need to look at them. I wanted to
turn the xml permissions into ROle objects, but does that mean that my
User class needs to make reference to the Role class?
>
User class example
>
class User{
>
protected $firstName;
protected $lastName;
protected $employeeNumber;
protected $orgCode;
protected $roles; //Could this be an object of my class Role?
protected $scope;
protected $type;
protected $primaryAssignmentsXML = null;
protected $securityRolesXML = null;
>
.... getters ad setters
>
getRole(roleName){
//get the securityRolesXML and then parse it setting the Role
Object
>
$role = new Role();
$role->setName();
$role->setFunction();
>
return $role;
}
>
Is this how I should be going about this?
Theoretically looks ok. But, practically you'll end up deeper
object chains which might need caching to improve performance.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/
  #3  
Old October 9th, 2008, 06:35 PM
Jerry Stuckle
Guest
 
Posts: n/a
Default Re: Design question: User objects and a Role object

Anthony Smith wrote:
Quote:
I have a user object that is set when a user logs in. There are also
permissions that I get about the user from a web service. Currently I
take the results from those web services and store them as XML in the
user object so I can parse it when I need to look at them. I wanted to
turn the xml permissions into ROle objects, but does that mean that my
User class needs to make reference to the Role class?
>
Yes, the user will have zero or more roles, so it has to be able to
access the role class.
Quote:
User class example
>
class User{
>
protected $firstName;
protected $lastName;
protected $employeeNumber;
protected $orgCode;
protected $roles; //Could this be an object of my class Role?
protected $scope;
protected $type;
protected $primaryAssignmentsXML = null;
protected $securityRolesXML = null;
>
.... getters ad setters
>
>
>
getRole(roleName){
//get the securityRolesXML and then parse it setting the Role
Object
>
$role = new Role();
$role->setName();
$role->setFunction();
>
>
return $role;
}
>
>
Is this how I should be going about this?
>
Yes, it $roles could be an object of type Role. But also bear in mind a
user may have several roles - i.e. authorized user, power user, admin,
etc., each with its own permissions. You'll want to plan for this, also.

Of course, if you have a straight hierarchy (each higher role includes
all of the permissions of all the roles below it), then you could get by
with only one role. But that can be hard to change if you should have
to someday create a role which doesn't match that hierarchy.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles