위치 : 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 패턴이라고 하등가... 머 그럴겁니다.
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 6530 |
퍼블리셔강
|
12년 전 | 646 | |
| 6529 | 12년 전 | 1300 | ||
| 6528 | 12년 전 | 620 | ||
| 6527 | 12년 전 | 789 | ||
| 6526 | 12년 전 | 6580 | ||
| 6525 | 12년 전 | 548 | ||
| 6524 | 12년 전 | 837 | ||
| 6523 | 12년 전 | 486 | ||
| 6522 | 12년 전 | 534 | ||
| 6521 | 12년 전 | 797 | ||
| 6520 | 12년 전 | 738 | ||
| 6519 | 12년 전 | 1742 | ||
| 6518 |
가슴시린하늘
|
12년 전 | 1723 | |
| 6517 | 12년 전 | 1362 | ||
| 6516 | 12년 전 | 5225 | ||
| 6515 | 12년 전 | 1494 | ||
| 6514 | 12년 전 | 1597 | ||
| 6513 | 12년 전 | 953 | ||
| 6512 | 12년 전 | 1978 | ||
| 6511 | 12년 전 | 1368 | ||
| 6510 | 12년 전 | 3058 | ||
| 6509 |
프로프리랜서
|
12년 전 | 2547 | |
| 6508 |
프로프리랜서
|
12년 전 | 1897 | |
| 6507 |
프로프리랜서
|
12년 전 | 2373 | |
| 6506 |
프로프리랜서
|
12년 전 | 1854 | |
| 6505 |
프로프리랜서
|
12년 전 | 1631 | |
| 6504 | 12년 전 | 1025 | ||
| 6503 | 12년 전 | 1127 | ||
| 6502 |
프로프리랜서
|
12년 전 | 5554 | |
| 6501 |
프로프리랜서
|
12년 전 | 2599 | |
| 6500 |
프로프리랜서
|
12년 전 | 3082 | |
| 6499 |
프로프리랜서
|
12년 전 | 1750 | |
| 6498 |
프로프리랜서
|
12년 전 | 1462 | |
| 6497 | 12년 전 | 806 | ||
| 6496 |
yunkiri486
|
12년 전 | 1807 | |
| 6495 | 12년 전 | 917 | ||
| 6494 | 12년 전 | 1491 | ||
| 6493 | 12년 전 | 2763 | ||
| 6492 |
오늘도망했다
|
12년 전 | 2337 | |
| 6491 |
오늘도망했다
|
12년 전 | 1677 | |
| 6490 |
오늘도망했다
|
12년 전 | 6658 | |
| 6489 |
오늘도망했다
|
12년 전 | 2494 | |
| 6488 |
홈피119
|
12년 전 | 697 | |
| 6487 | 12년 전 | 669 | ||
| 6486 | 12년 전 | 1407 | ||
| 6485 | 12년 전 | 2049 | ||
| 6484 | 12년 전 | 897 | ||
| 6483 | 12년 전 | 715 | ||
| 6482 | 12년 전 | 1340 | ||
| 6481 | 12년 전 | 1468 | ||
| 6480 |
Header
|
12년 전 | 688 | |
| 6479 |
|
12년 전 | 1124 | |
| 6478 |
개초보제이
|
12년 전 | 1394 | |
| 6477 | 12년 전 | 791 | ||
| 6476 | 12년 전 | 1073 | ||
| 6475 | 12년 전 | 3678 | ||
| 6474 | 12년 전 | 1420 | ||
| 6473 | 12년 전 | 961 | ||
| 6472 | 12년 전 | 848 | ||
| 6471 |
AMDbest
|
12년 전 | 1203 | |
| 6470 |
jinmuk
|
12년 전 | 1444 | |
| 6469 |
jinmuk
|
12년 전 | 4249 | |
| 6468 |
jinmuk
|
12년 전 | 5574 | |
| 6467 | 12년 전 | 695 | ||
| 6466 |
jinmuk
|
12년 전 | 2269 | |
| 6465 |
jinmuk
|
12년 전 | 6732 | |
| 6464 |
jinmuk
|
12년 전 | 2407 | |
| 6463 |
jinmuk
|
12년 전 | 9330 | |
| 6462 |
희망과열정
|
12년 전 | 532 | |
| 6461 |
Header
|
12년 전 | 722 | |
| 6460 |
희망과열정
|
12년 전 | 1350 | |
| 6459 |
프리랜서개발자
|
12년 전 | 1675 | |
| 6458 | 12년 전 | 1334 | ||
| 6457 |
jinmuk
|
12년 전 | 1939 | |
| 6456 |
jinmuk
|
12년 전 | 2347 | |
| 6455 |
jinmuk
|
12년 전 | 3202 | |
| 6454 |
jinmuk
|
12년 전 | 2172 | |
| 6453 |
jinmuk
|
12년 전 | 2349 | |
| 6452 |
jinmuk
|
12년 전 | 2314 | |
| 6451 |
jinmuk
|
12년 전 | 1597 | |
| 6450 |
jinmuk
|
12년 전 | 1396 | |
| 6449 |
jinmuk
|
12년 전 | 1038 | |
| 6448 |
jinmuk
|
12년 전 | 1238 | |
| 6447 |
jinmuk
|
12년 전 | 2006 | |
| 6446 |
jinmuk
|
12년 전 | 1563 | |
| 6445 |
jinmuk
|
12년 전 | 1263 | |
| 6444 |
jinmuk
|
12년 전 | 2305 | |
| 6443 |
jinmuk
|
12년 전 | 2044 | |
| 6442 |
jinmuk
|
12년 전 | 1883 | |
| 6441 |
jinmuk
|
12년 전 | 1616 | |
| 6440 |
jinmuk
|
12년 전 | 2315 | |
| 6439 |
jinmuk
|
12년 전 | 1134 | |
| 6438 |
wndProc
|
12년 전 | 775 | |
| 6437 | 12년 전 | 393 | ||
| 6436 |
senseme
|
12년 전 | 542 | |
| 6435 | 12년 전 | 1045 | ||
| 6434 | 12년 전 | 2474 | ||
| 6433 | 12년 전 | 2480 | ||
| 6432 | 12년 전 | 1557 | ||
| 6431 |
밥먹고합시다
|
12년 전 | 1190 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기