Skip to content

Instantly share code, notes, and snippets.

@Vijaysinh
Last active September 16, 2021 13:15
Show Gist options
  • Save Vijaysinh/4180d9789c8959144eceda101f6cf4d2 to your computer and use it in GitHub Desktop.
Save Vijaysinh/4180d9789c8959144eceda101f6cf4d2 to your computer and use it in GitHub Desktop.
SOLID - InterfaceSegregationPrinciple PHP
<?php
interface VehicleInterface {
public function drive();
public function fly();
}
class FutureCar implements VehicleInterface {
public function drive() {
echo 'Driving a future car!';
}
public function fly() {
echo 'Flying a future car!';
}
}
class Car implements VehicleInterface {
public function drive() {
echo 'Driving a car!';
}
public function fly() {
throw new Exception('Not implemented method');
}
}
class Airplane implements VehicleInterface {
public function drive() {
throw new Exception('Not implemented method');
}
public function fly() {
echo 'Flying an airplane!';
}
}
interface CarInterface {
public function drive();
}
interface AirplaneInterface {
public function fly();
}
class FutureCar implements CarInterface, AirplaneInterface {
public function drive() {
echo 'Driving a future car!';
}
public function fly() {
echo 'Flying a future car!';
}
}
class Car implements CarInterface {
public function drive() {
echo 'Driving a car!';
}
}
class Airplane implements AirplaneInterface {
public function fly() {
echo 'Flying an airplane!';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment