class interaction?
Posted: Mon Jun 05, 2006 8:21 am
I've been struggling to find a way of explaining this. I'm not even sure its a problem!
I have an object from class1 that needs information from an object from class2 to perform an action.
The method in object1 accepts object2 as a parameter then accesses methods/properties of object2 to get the info it needs to carry out a task.
This all relies on the method receiving the correct object from the correct class, or the methods it is expecting won't be there.
I guess I need to test for the parent class of object2 but in PHP 4 i'm not sure how.
Also if another developer were to come along and use the script, how would they know that class1 relied on receiving class2 apart from me writing comments? It is not suitable for one class to be an extension of the other in this case.
An example situation would be a shopping cart, the cart is an object that contains product objects, and can perform functions on the product objects to find out total price etc.
I guess what I'm trying to ask is, is it correct for classes to interact in this way? And if not, what is the alternative? Just trying to make sure I'm doing things properly!
I have an object from class1 that needs information from an object from class2 to perform an action.
The method in object1 accepts object2 as a parameter then accesses methods/properties of object2 to get the info it needs to carry out a task.
This all relies on the method receiving the correct object from the correct class, or the methods it is expecting won't be there.
I guess I need to test for the parent class of object2 but in PHP 4 i'm not sure how.
Also if another developer were to come along and use the script, how would they know that class1 relied on receiving class2 apart from me writing comments? It is not suitable for one class to be an extension of the other in this case.
An example situation would be a shopping cart, the cart is an object that contains product objects, and can perform functions on the product objects to find out total price etc.
I guess what I'm trying to ask is, is it correct for classes to interact in this way? And if not, what is the alternative? Just trying to make sure I'm doing things properly!