views:

791

answers:

1

I am using CodeIginter as my PHP framework. I am explaining the situation below: -

I need three models named: -

  • User_Model
  • Relation_Model
  • Reminder_Model

Now consider the situation:

User_Model is already written. I am writing Relation_Model. My friend will write the Reminder_Model.

Relation_Model instantiates User_Model, and uses that, in one of its method: getRelation($userID)

Reminder_Model also instantiates one User_Model instance for its functioning.

Reminder_Model needs to call getRelation method of Relation_Model.

So, there should be at least two instances of User_Model. One in Relation_Model, another in Reminder_Model.

The problem is how do I ensure inside Relation_Model, that my User_Model instance does not interfere with the User_Model instance of my friend’s Reminder_Model class?

That is, to code Reminder_Model, my friend should not have internal knowledge of Relation_Model, just to use one of its method getRelation.

If you want to know the need for this, say: Reminder_Model loads the model of the user who has logged in (say user-A), Relation_Model works with the models of the users who are member of user-A's team.

+1  A: 

I'm not sure I understand why you can't use the same instance of the User_Model class, but maybe loading the model twice, once with plain old $this->load->model('User_Model') and second with $this->load->model('Use_Model', 'Second_User_Model') will help. Or you could clone the object like $this->second_user_model = clone $this->user_model.

Ch4m3l3on
The first method, will require, the implementer of Reminder_Model to have internal knowledge of Relation_Model (the fact that inside Relation_Model, I have instantiated User_Model with the name of Second_User_Model!).Yes, I also finally thought of cloning.
Sabya