-
Notifications
You must be signed in to change notification settings - Fork 0
/
abstract_classes.php
36 lines (28 loc) · 1.01 KB
/
abstract_classes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
//An abstract class cannot be instantiated. Instead, it defines (and, optionally, partially
//implements) the interface for any class that might extend it.
abstract class AchievementType{
public function name()
{
$class = (new ReflectionClass($this))->getShortName();
return trim(preg_replace('/[A-Z]/', '$0', $class));
}
public function icon()
{
return strtolower(str_replace(' ', '-', $this->name())).'.png';
}
//In creating an abstract method, you ensure that an implementation will be available in all
//concrete child classes, but you leave the details of that implementation undefined.
abstract public function qualifier($user);
}
class FirstThousandPoints extends AchievementType
{
//You must use abstract methods in the new class
public function qualifier($user)
{
// TODO: Implement qualifier() method.
}
}
$firstThousandPoints = new FirstThousandPoints();
print($firstThousandPoints->name());
print($firstThousandPoints->icon());