Created
August 25, 2019 13:19
-
-
Save dseegers/d77e2aee4a788ffba49552abc5e83113 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"<?php | |
//Your practice code | |
abstract class User | |
{ | |
protected $scores = 0; | |
protected $numberOfArticles = 0; | |
// The abstract and concrete methods | |
public function setNumberOfArticles($int) | |
{ | |
// Cast to integer type | |
$numberOfArticles = (int)$int; | |
$this->numberOfArticles = $numberOfArticles; | |
} | |
public function getNumberOfArticles() | |
{ | |
return $this->numberOfArticles; | |
} | |
abstract public function calcScore(); | |
} | |
class Author extends User | |
{ | |
public function calcScore() | |
{ | |
return $this->scores = $this->numberOfArticles * 10 + 20; | |
} | |
} | |
class Editor extends User{ | |
public function calcScore(){ | |
return $this->scores = $this->numberOfArticles * 6 + 15; | |
} | |
} | |
$auteur = new Author; | |
$auteur->setNumberOfArticles(8); | |
echo $auteur->calcScore(); | |
$editor1 = new Editor(); | |
$editor1->setNumberOfArticles(15); | |
echo $editor1->calcScore();" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment