Search⌘ K
AI Features

Challenge: Polymorphism

Learn to apply polymorphism in PHP by creating Author and Editor classes that inherit from an abstract User class. Understand how to use abstract methods and concrete implementations to calculate scores based on the number of articles authored or edited. This lesson strengthens your grasp of polymorphism and type hinting to write efficient, reusable PHP code.

We'll cover the following...

Task

An abstract User class is given below. It commits the classes that inherit from it to calculate the number of scores that a user has depending on the number of articles that they have authored or edited. On the basis of the User class, create the Author and Editor classes. Both classes should calculate the number of scores with the method calcScores() ...