Welcome Guest, Not a member yet? Register   Sign In
REST, API - confusion
#6

[eluser]Jay Callicott[/eluser]
I usually will try to remove duplication in that case. You don't want to have 2 different controllers with the same methods for adding users, showing an index, viewing the details, etc.

I use some form of the factory pattern for instances where I want to have for instance users with more methods.

There are different ways of doing this. You could have a base model and have each child model inherit methods overriding and extending where necessary, you could use delegate functions instead of inheritance.

The annoying thing about models is that you can't pass initialization parameters like you can with libraries. So sometimes I create an initialize function. Something like $this->load->model('User_model'), then User_model->intialize(array(params..)); and then call your functions and when you call User_model->find it will call whichever child model you've initialized. That way you can have a consistent interface.

I also always use a user access class for determining access to a controller function and i call an authorization check before i do anything in that function. When users log in I store all of their stuff in a session var called "user" and refer to that when im determining what kind of user they are.

You could also use that session var to initialize your model.

In the constructor you could look at the user session variable and maybe you have a property that indicates what type of user they are. In your parent class that's how you know which child model to initialize.

The important thing with that is that you should try to limit how many times you check what type of user it is.

You don't want switch statements all over the place.

Anyways that's one of the simpler design patterns I use, I don't know a lot of design patterns but that one is one I employ alot. Clear as mud?


Messages In This Thread
REST, API - confusion - by El Forum - 10-10-2007, 08:32 AM
REST, API - confusion - by El Forum - 10-10-2007, 08:57 AM
REST, API - confusion - by El Forum - 10-10-2007, 09:11 AM
REST, API - confusion - by El Forum - 10-11-2007, 02:48 PM
REST, API - confusion - by El Forum - 10-11-2007, 03:25 PM
REST, API - confusion - by El Forum - 10-11-2007, 03:57 PM
REST, API - confusion - by El Forum - 10-11-2007, 04:05 PM
REST, API - confusion - by El Forum - 10-12-2007, 03:34 PM



Theme © iAndrew 2016 - Forum software by © MyBB