Class: Abstract

objectives:

  • forcing an extended class to define the abstract methods of the base class

Code

<?php
abstract class Members
{
// Forceing an extended class to define these method method
abstract protected function simple_test();
abstract protected function param_test($data);
}

class Test1 extends Members
{
// now we use public for protected method
public function simple_test()
{
echo "<br/> I did not vote republican party";
}
public function param_test($data)
{
echo "<br/> valid id $data";
}
}

class Test2 extends Members
{
public function simple_test()
{
echo "<br/> I did not vote democratic party";
}
public function param_test($data)
{
echo "<br/> valid id $data";
}
}
//
$obj1 = new Test1();
$obj1->simple_test();
$obj1->param_test(12345);
//
$obj2 = new Test2();
$obj2->simple_test();
$obj2->param_test(56789);
?>

Runtime View