Quote Originally Posted by lastcraft View Post
See the CanUseDifferentDependencySetWithinAnInterface test case.
It could be that there is more than one instance of the same class and each instance needs to fill the dependency differently:

PHP Code:
abstract class Scientist {

    function 
__construct(Publisher $publisher) {
        
$this->publisher $publisher;
    }
    function 
getPublisher() {
        return 
get_class($publisher);
    }
}
class 
Dawkins extends Scientist {}
class 
Hawking extends Scientist {}

interface 
Publisher {}
class 
AmericanPublisher implements Publisher {}
class 
BritishPublisher implements Publisher {}

class 
CanUseDifferentDependencySetWithinAnInterface extends UnitTestCase {

    function 
testCanSetDifferentPreferencesForInstancesOfTheSameClass() {
        
$globe = new Phemto();
        
$britain $globe->getSubgraph();
        
$america $globe->getSubgraph();

        
$globe->register('Dawkins');
        
$america->register('AmericanPublisher');
        
$britain->register('BritishPublisher');
        
        
$scientist $britain->instantiate('Scientist');
        
$this->assertEqual(
            
$scientist->getPublisher(), 
            
'BritishPublisher');

        
$scientist $america->instantiate('Scientist');
        
$this->assertEqual(
            
$scientist->getPublisher(), 
            
'AmericanPublisher');
    }