_host = $host; return $this; // for a fluent interface } /** * @return string */ public function getHost() { return $this->_host; } } class Connection { protected $_configuration; /** * here, Configuration gets injected and Connection will get all that it needs from Configuration * without DI, the configuration would be created directly in Connection, which is not very good * for testing and extending Connection * * @param Configuration $config */ public function __construct(Configuration $config) { $this->_configuration = $config; } public function connect() { $host = $this->_configuration->getHost(); // ... } }