위치 : 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 패턴이라고 하등가... 머 그럴겁니다.
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 6230 |
senseme
|
12년 전 | 1053 | |
| 6229 |
senseme
|
12년 전 | 1072 | |
| 6228 | 12년 전 | 4434 | ||
| 6227 |
senseme
|
12년 전 | 1492 | |
| 6226 |
senseme
|
12년 전 | 1632 | |
| 6225 | 12년 전 | 5489 | ||
| 6224 | 12년 전 | 3264 | ||
| 6223 |
kiplayer
|
12년 전 | 2138 | |
| 6222 | 12년 전 | 1297 | ||
| 6221 | 12년 전 | 3485 | ||
| 6220 | 12년 전 | 2510 | ||
| 6219 | 12년 전 | 2223 | ||
| 6218 |
senseme
|
12년 전 | 1839 | |
| 6217 |
senseme
|
12년 전 | 1532 | |
| 6216 |
senseme
|
12년 전 | 1523 | |
| 6215 |
senseme
|
12년 전 | 1281 | |
| 6214 | 12년 전 | 2393 | ||
| 6213 |
senseme
|
12년 전 | 1668 | |
| 6212 |
senseme
|
12년 전 | 1343 | |
| 6211 |
senseme
|
12년 전 | 2427 | |
| 6210 |
senseme
|
12년 전 | 1603 | |
| 6209 | 12년 전 | 2215 | ||
| 6208 | 12년 전 | 3438 | ||
| 6207 | 12년 전 | 1220 | ||
| 6206 |
senseme
|
12년 전 | 2196 | |
| 6205 | 12년 전 | 1034 | ||
| 6204 |
kiplayer
|
12년 전 | 1527 | |
| 6203 |
senseme
|
12년 전 | 2112 | |
| 6202 |
senseme
|
12년 전 | 1751 | |
| 6201 |
senseme
|
12년 전 | 4557 | |
| 6200 |
senseme
|
12년 전 | 2655 | |
| 6199 |
senseme
|
12년 전 | 2826 | |
| 6198 |
senseme
|
12년 전 | 1228 | |
| 6197 |
senseme
|
12년 전 | 8544 | |
| 6196 |
senseme
|
12년 전 | 3333 | |
| 6195 | 12년 전 | 1431 | ||
| 6194 |
|
12년 전 | 1283 | |
| 6193 |
senseme
|
12년 전 | 2685 | |
| 6192 |
senseme
|
12년 전 | 5361 | |
| 6191 |
senseme
|
12년 전 | 3405 | |
| 6190 | 12년 전 | 1333 | ||
| 6189 | 12년 전 | 13491 | ||
| 6188 |
웹디자인되고파
|
12년 전 | 1203 | |
| 6187 | 12년 전 | 606 | ||
| 6186 | 12년 전 | 3921 | ||
| 6185 | 12년 전 | 1462 | ||
| 6184 | 12년 전 | 9367 | ||
| 6183 | 12년 전 | 779 | ||
| 6182 |
senseme
|
12년 전 | 1237 | |
| 6181 |
senseme
|
12년 전 | 3214 | |
| 6180 |
senseme
|
12년 전 | 843 | |
| 6179 |
senseme
|
12년 전 | 1759 | |
| 6178 | 12년 전 | 3631 | ||
| 6177 | 12년 전 | 1063 | ||
| 6176 | 12년 전 | 950 | ||
| 6175 |
senseme
|
12년 전 | 5297 | |
| 6174 |
senseme
|
12년 전 | 1423 | |
| 6173 |
senseme
|
12년 전 | 751 | |
| 6172 |
senseme
|
12년 전 | 2738 | |
| 6171 |
senseme
|
12년 전 | 2472 | |
| 6170 |
senseme
|
12년 전 | 1494 | |
| 6169 |
senseme
|
12년 전 | 2925 | |
| 6168 |
senseme
|
12년 전 | 6535 | |
| 6167 | 12년 전 | 2136 | ||
| 6166 | 12년 전 | 740 | ||
| 6165 |
페이지팩트
|
12년 전 | 1898 | |
| 6164 |
네오soft
|
12년 전 | 1853 | |
| 6163 |
|
12년 전 | 2606 | |
| 6162 | 12년 전 | 590 | ||
| 6161 |
|
12년 전 | 1687 | |
| 6160 | 12년 전 | 766 | ||
| 6159 | 12년 전 | 1776 | ||
| 6158 |
|
12년 전 | 2680 | |
| 6157 |
sa2pan
|
12년 전 | 1241 | |
| 6156 | 12년 전 | 3889 | ||
| 6155 | 12년 전 | 9961 | ||
| 6154 | 12년 전 | 1123 | ||
| 6153 | 12년 전 | 2452 | ||
| 6152 |
생각보다몸이앞서다
|
12년 전 | 2117 | |
| 6151 | 12년 전 | 2974 | ||
| 6150 |
kiplayer
|
12년 전 | 6000 | |
| 6149 |
|
12년 전 | 2639 | |
| 6148 | 12년 전 | 2963 | ||
| 6147 |
hwang007
|
12년 전 | 951 | |
| 6146 |
aqqasdf
|
12년 전 | 764 | |
| 6145 | 12년 전 | 1856 | ||
| 6144 | 12년 전 | 5862 | ||
| 6143 |
smwkd
|
12년 전 | 1458 | |
| 6142 | 12년 전 | 4696 | ||
| 6141 | 12년 전 | 928 | ||
| 6140 | 12년 전 | 4090 | ||
| 6139 | 12년 전 | 1237 | ||
| 6138 | 12년 전 | 1093 | ||
| 6137 |
SugarSkull
|
12년 전 | 1677 | |
| 6136 | 12년 전 | 1304 | ||
| 6135 |
한번잘해보자
|
12년 전 | 559 | |
| 6134 |
프리랜서개발자
|
12년 전 | 533 | |
| 6133 |
basaria
|
12년 전 | 20441 | |
| 6132 | 12년 전 | 501 | ||
| 6131 | 12년 전 | 1081 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기