티스토리 뷰

웹개발/Php

Adapter 패턴

yaku 2010. 12. 20. 15:54


interface Duck
{
 function quick();
 function fly();
}


class JDuck implements Duck {
 function quick() {
  echo "Quick";
 }
 function fly() {
  echo "Fly";
 }
}


interface Chil
{
 function goole();
 function fly();
}


class JChil implements Chil {
 function goole() {
  echo "GGGGGGG~~~~~";
 }

 function fly() {
  echo "  -|- ";
 }
}

 

class DuckApter implements Duck {

 public $_chil;
 function __construct($chil) {
  $this->_chil = $chil;
 }

 function quick() {
  $this->_chil->goole();
 }

 function fly() {
  for($i=0;$i<5;$i++) {
   $this->_chil->fly();
  }

 }
}

$Chil  = new jChil();

$Duck  = new DuckApter($Chil);

$Duck->fly();

'웹개발 > Php' 카테고리의 다른 글

php 날짜 계산 strtotime 이용  (0) 2011.02.18
추상 팩토리 패턴  (0) 2010.12.20
PHP 참조 (PHP References) - 2 (고급편)  (0) 2010.12.20
PHP 최적화 40가지  (0) 2010.12.20
PHP 참조 반환하기  (0) 2010.12.20
댓글
D-DAY
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함