I'm a newbie to OO but am reading around and trying to learn to do things the 'right' way. I've been reading up on dependency injection and can understand why it is a good thing, however I am not totally clear on the syntax.
For example looking at this Basic PHP Object Oriented Instantiation and Dependency Injection question on SO I replicate the exact same code (with the changes as the answer suggests) and then print out what the methods return:
$author = new Author('Mickey', 'Mouse');
print $author->getFirstName();
$question = new Question('what day is it?', $author);
print $question->getQuestion();
However I'm not clear on the role the class name plays in:
public function __construct($question, Author $author)
{
$this->author = $author;
$this->question = $question;
}
If I remove it from my code nothing breaks. Is it just a human readable thing so that other people can explicitly see that there is a dependency or does it play a role in actually making the code work?
Thanks for any help!