Skip to content

Instantly share code, notes, and snippets.

@dseegers
Created August 25, 2019 13:19
Show Gist options
  • Save dseegers/d77e2aee4a788ffba49552abc5e83113 to your computer and use it in GitHub Desktop.
Save dseegers/d77e2aee4a788ffba49552abc5e83113 to your computer and use it in GitHub Desktop.
"<?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