এই Lesson এ Object-Oriented PHP তে PHP Interface and Abstract class নিয়ে আলোচনা করব।
Vehicle.php
interface Vehicle {
public function display();
public function capcity();
public function fuelAmount();
}
Car.php
require 'Vehicle.php';
class Car implements Vehicle {
public function display() {
return 'Welcome';
}
public function capcity() {
return 10;
}
public function fuelAmount() {
return 12;
}
}
$car = new Car();
echo $car->capcity();
Bus.php
require 'Vehicle.php';
class Bus implements Vehicle {
public function display() {
return 'Welcome';
}
public function capcity() {
return 15;
}
public function fuelAmount() {
return 25;
}
public function applyBreaks() {
return 'Breaked';
}
}
$bus = new Bus();
echo $bus->capcity();
Vehicle.php
abstract class Vehicle {
public $name;
public function display(){
return 'Welcome';
}
abstract public function capcity();
abstract public function fuelAmount();
}
Bus.php
require 'Vehicle.php';
class Bus extends Vehicle {
public function capcity() {
return 15;
}
public function fuelAmount() {
return 25;
}
}
$bus = new Bus();
echo $bus->capcity();