위치 : http://kr1.php.net/manual/en/function.call-user-func-array.php
<?php
Class Delegate
{
private $arrInstances = array();
protected function addObject( $oElement )
{
// add one element on the end of the stack //
$this->arrInstances[] = $oElement;
}
public function __call( $strMethod, $arrParams )
{
// for each element in instance //
foreach( $this->arrInstances as $oElement )
{
// get the class of the element //
$strClass = get_class( $oElement );
// get all methods of the class //
$arrMethods = get_class_methods( $strClass );
// case the method exists into this class //
if( in_array( $strMethod , $arrMethods ) )
{
// prepare caller //
$arrCaller = Array( $strClass , $strMethod );
// return the result of the method into the object //
return call_user_func_array( $arrCaller, $arrParams );
}
}
// any object has the method //
// throw a exception //
throw new Exception( " Method " . $strMethod . " not exist in this class " . get_class($this ) . "." );
}
}
class Log
{
public function sayHi()
{
print "hi!" . "<br/>\n";
}
public function sayMyName()
{
print "log" . "<br/>\n";
}
}
class Other
{
public function sayHello()
{
print "hello there!" . "<br/>\n";
}
public function sayMyName()
{
print "other" . "<br/>\n";
}
}
class Example extends Delegate
{
public function __construct()
{
$this->addObject( new Log() );
$this->addObject( new Other() );
}
}
$oExample = new Example();
$oExample->sayHi();
$oExample->sayHello();
$oExample->sayMyName();
/*
hi!<br/>
hello there!<br/>
log<br/>
*/
?>
댓글 6개
11년 전
이거 어디라 사용하실려구요? 그냥 매직함수 __call 사용한 것 뿐인데...
11년 전
$this->addObject( new Log() );
$this->addObject( new Other() );
이부분.......상속말고 다른 Class 의 Method 을 자신의 Method 처럼 사용하는 부분입니다.
급할땐 용이하죠...
$this->addObject( new Other() );
이부분.......상속말고 다른 Class 의 Method 을 자신의 Method 처럼 사용하는 부분입니다.
급할땐 용이하죠...
11년 전
아~ ^^ 그건 그렇죠 ... new 새로 메모리에 공간을 개설하면 메모리 작으면 좀 버벅 거릴겁니다.
11년 전
저 코드는 메모리에 차지하는 용량을 무시해도 될 정도의 코드예요.....ㅠ_ㅠ
워프는 콜리앗 ... class 로 만든 저 샘플은 개미 발에 미세먼지
혹 new 로 만드는게 버벅일꺼라 생각하시는거라면.......
Framework 쪽 한번 보시는것을 추천 드립니다.
워프는 콜리앗 ... class 로 만든 저 샘플은 개미 발에 미세먼지
혹 new 로 만드는게 버벅일꺼라 생각하시는거라면.......
Framework 쪽 한번 보시는것을 추천 드립니다.
11년 전
Framework 쪽으로 하고는 있습니다. 사이트는 가벼워야하니까 ^^
11년 전
제가 만들어 쓰고 있는 EventDispatcher 라는 클래스와 비슷하네요.
예를 들어 게시판에 로그인이 필요한 부분에는 Dispatcher 만 해주고 관련 처리는 외부 함수를 addEventHandler 메소드로 연결해 주기만 하면 되죠.
이런걸 Observer 패턴이라고 하등가... 머 그럴겁니다.
예를 들어 게시판에 로그인이 필요한 부분에는 Dispatcher 만 해주고 관련 처리는 외부 함수를 addEventHandler 메소드로 연결해 주기만 하면 되죠.
이런걸 Observer 패턴이라고 하등가... 머 그럴겁니다.
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7030 | 11년 전 | 1430 | ||
| 7029 |
|
11년 전 | 3254 | |
| 7028 |
|
11년 전 | 1158 | |
| 7027 | 11년 전 | 1020 | ||
| 7026 | 11년 전 | 2101 | ||
| 7025 |
어려워요잉
|
11년 전 | 2752 | |
| 7024 | 11년 전 | 2112 | ||
| 7023 | 11년 전 | 3152 | ||
| 7022 |
Shhhh
|
11년 전 | 1547 | |
| 7021 |
|
11년 전 | 3288 | |
| 7020 | 11년 전 | 798 | ||
| 7019 |
막돼먹은영애
|
11년 전 | 1091 | |
| 7018 | 11년 전 | 1971 | ||
| 7017 | 11년 전 | 2332 | ||
| 7016 | 11년 전 | 1037 | ||
| 7015 | 11년 전 | 2840 | ||
| 7014 | 11년 전 | 3034 | ||
| 7013 | 11년 전 | 1521 | ||
| 7012 |
|
11년 전 | 2205 | |
| 7011 | 11년 전 | 1055 | ||
| 7010 | 11년 전 | 1409 | ||
| 7009 |
|
11년 전 | 1093 | |
| 7008 | 11년 전 | 2279 | ||
| 7007 | 11년 전 | 2194 | ||
| 7006 |
|
11년 전 | 1185 | |
| 7005 | 11년 전 | 5319 | ||
| 7004 | 11년 전 | 2369 | ||
| 7003 | 11년 전 | 3084 | ||
| 7002 | 11년 전 | 1937 | ||
| 7001 | 11년 전 | 989 | ||
| 7000 | 11년 전 | 2059 | ||
| 6999 |
|
11년 전 | 2181 | |
| 6998 | 11년 전 | 1897 | ||
| 6997 |
네이비칼라
|
11년 전 | 1508 | |
| 6996 | 11년 전 | 970 | ||
| 6995 |
|
11년 전 | 1871 | |
| 6994 | 11년 전 | 2589 | ||
| 6993 |
kimsdesign
|
11년 전 | 1315 | |
| 6992 |
|
11년 전 | 2784 | |
| 6991 | 11년 전 | 1726 | ||
| 6990 | 11년 전 | 4484 | ||
| 6989 | 11년 전 | 1868 | ||
| 6988 |
네이비컬러
|
11년 전 | 2531 | |
| 6987 | 11년 전 | 3740 | ||
| 6986 |
잘살아보자
|
11년 전 | 1606 | |
| 6985 |
잘살아보자
|
11년 전 | 2487 | |
| 6984 | 11년 전 | 833 | ||
| 6983 |
천재조상훈
|
11년 전 | 1881 | |
| 6982 |
천재조상훈
|
11년 전 | 4515 | |
| 6981 |
천재조상훈
|
11년 전 | 1645 | |
| 6980 |
|
11년 전 | 1895 | |
| 6979 |
|
11년 전 | 769 | |
| 6978 |
잘살아보자
|
11년 전 | 1160 | |
| 6977 |
잘살아보자
|
11년 전 | 1476 | |
| 6976 |
잘살아보자
|
11년 전 | 1586 | |
| 6975 |
천재조상훈
|
11년 전 | 1498 | |
| 6974 |
잘살아보자
|
11년 전 | 2240 | |
| 6973 |
잘살아보자
|
11년 전 | 1168 | |
| 6972 |
잘살아보자
|
11년 전 | 3078 | |
| 6971 |
잘살아보자
|
11년 전 | 3283 | |
| 6970 |
잘살아보자
|
11년 전 | 1854 | |
| 6969 |
잘살아보자
|
11년 전 | 4787 | |
| 6968 | 11년 전 | 9916 | ||
| 6967 |
|
11년 전 | 2647 | |
| 6966 |
|
11년 전 | 1120 | |
| 6965 | 11년 전 | 3271 | ||
| 6964 | 11년 전 | 2596 | ||
| 6963 | 11년 전 | 2113 | ||
| 6962 |
star3840
|
11년 전 | 1026 | |
| 6961 | 11년 전 | 4252 | ||
| 6960 |
|
11년 전 | 743 | |
| 6959 | 11년 전 | 1267 | ||
| 6958 |
|
11년 전 | 1683 | |
| 6957 | 11년 전 | 1913 | ||
| 6956 |
잘살아보자
|
11년 전 | 1864 | |
| 6955 | 11년 전 | 4636 | ||
| 6954 | 11년 전 | 1638 | ||
| 6953 |
잘살아보자
|
11년 전 | 891 | |
| 6952 |
잘살아보자
|
11년 전 | 2056 | |
| 6951 | 11년 전 | 1624 | ||
| 6950 | 11년 전 | 2624 | ||
| 6949 |
잘살아보자
|
11년 전 | 903 | |
| 6948 | 11년 전 | 1570 | ||
| 6947 | 11년 전 | 1481 | ||
| 6946 | 11년 전 | 1627 | ||
| 6945 | 11년 전 | 1234 | ||
| 6944 | 11년 전 | 1199 | ||
| 6943 | 11년 전 | 1242 | ||
| 6942 | 11년 전 | 1595 | ||
| 6941 | 11년 전 | 1672 | ||
| 6940 | 11년 전 | 1764 | ||
| 6939 | 11년 전 | 1673 | ||
| 6938 | 11년 전 | 1956 | ||
| 6937 | 11년 전 | 1167 | ||
| 6936 | 11년 전 | 1368 | ||
| 6935 | 11년 전 | 1312 | ||
| 6934 | 11년 전 | 1478 | ||
| 6933 | 11년 전 | 1990 | ||
| 6932 | 11년 전 | 1549 | ||
| 6931 | 11년 전 | 1552 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기