OOP PHP Interface and Abstract class Bangla Tutorial

Author: Al-mamun Sarkar Date: 2020-04-18 10:49:06

এই 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();

 

 

Abstract Class:

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();