Solution Review: Dependency Injection
Learn how to enhance PHP code by applying dependency injection and namespaces. This lesson guides you through creating classes with constructors, using type hinting, and defining interfaces to manage dependencies effectively.
We'll cover the following...
We'll cover the following...
Solution: Task 1
Explanation
- Line 2: We write the
Articleclass with protected properties$titleand$author. - Line 6: We add the
__construct()method to theArticleclass, which gets two parameters and sets the values of$titleand$authorproperties. - Line 11: We add the
getTitle()getter method to theArticleclass, which returns the$title