Can we use design patterns with Codeigniter? Can we create abstract classes, interfaces and extend them? If I can create those classes, how can I include them? Should those classes reside inside the controller folder or the model folder? If possible can someone explain me, how to implement the following design pattern with Codeignitor? How to include the fills and organize them. Appreciate your support. Thanks!
<?php
interface IAccount {
public function get_balance();
}
class Savings_account implements IAccount {
public function get_balance() {
//get account balance
}
}
class Current_account implements IAccount {
public function get_balance() {
//get account balance
}
}
class Bank {
private $acc_type = null;
public function __construct(IAccount $acc) {
$this->acc_type = $acc;
}
public function get_balance() {
return $this->acc_type->get_balance();
}
}
//Client code in a contoller
$bank = new Bank(new Savings_account());
echo $bank->get_balance();
//or
$bank = new Bank(new Current_account());
echo $bank->get_balance();
?>