Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class IndependentDeveloper1
- {
- public function calc($a, $b) {
- return $a + $b;
- }
- }
- class IndependentDeveloper2
- {
- public function nameIsVeryLongAndUncomfortable($a, $b) {
- return $a + $b;
- }
- }
- interface IAdapter
- {
- public function sum($a, $b);
- }
- class ConcreteAdapter1 implements IAdapter
- {
- protected $object;
- public function __construct() {
- $this->object = new IndependentDeveloper1();
- }
- public function sum($a, $b) {
- return $this->object->calc($a, $b);
- }
- }
- class ConcreteAdapter2 implements IAdapter
- {
- protected $object;
- public function __construct() {
- $this->object = new IndependentDeveloper2();
- }
- public function sum($a, $b) {
- return $this->object->nameIsVeryLongAndUncomfortable($a, $b);
- }
- }
- $adapter1 = new ConcreteAdapter1();
- $adapter2 = new ConcreteAdapter2();
- function sum(IAdapter $adapter) {
- echo $adapter->sum(2, 2);
- }
- sum($adapter1);
- sum($adapter2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement