위치 : 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 패턴이라고 하등가... 머 그럴겁니다.
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 6030 | 12년 전 | 2833 | ||
| 6029 | 12년 전 | 2854 | ||
| 6028 | 12년 전 | 1478 | ||
| 6027 | 12년 전 | 899 | ||
| 6026 |
kiplayer
|
12년 전 | 812 | |
| 6025 | 12년 전 | 610 | ||
| 6024 | 12년 전 | 2828 | ||
| 6023 | 12년 전 | 2959 | ||
| 6022 |
|
12년 전 | 2114 | |
| 6021 |
Holyreign
|
12년 전 | 1345 | |
| 6020 | 12년 전 | 793 | ||
| 6019 | 12년 전 | 2864 | ||
| 6018 | 12년 전 | 3200 | ||
| 6017 | 12년 전 | 1245 | ||
| 6016 |
kiplayer
|
12년 전 | 10587 | |
| 6015 |
itlang
|
12년 전 | 1428 | |
| 6014 | 12년 전 | 434 | ||
| 6013 |
senseme
|
12년 전 | 1368 | |
| 6012 | 12년 전 | 3116 | ||
| 6011 | 12년 전 | 7133 | ||
| 6010 | 12년 전 | 8968 | ||
| 6009 | 12년 전 | 2876 | ||
| 6008 | 12년 전 | 2999 | ||
| 6007 | 12년 전 | 6680 | ||
| 6006 | 12년 전 | 10520 | ||
| 6005 | 12년 전 | 4057 | ||
| 6004 |
|
12년 전 | 589 | |
| 6003 | 12년 전 | 892 | ||
| 6002 | 12년 전 | 2355 | ||
| 6001 | 12년 전 | 692 | ||
| 6000 |
kiplayer
|
12년 전 | 3745 | |
| 5999 | 12년 전 | 443 | ||
| 5998 |
|
12년 전 | 2950 | |
| 5997 |
|
12년 전 | 3446 | |
| 5996 | 12년 전 | 2105 | ||
| 5995 |
kiplayer
|
12년 전 | 2179 | |
| 5994 |
|
12년 전 | 3276 | |
| 5993 |
windowhan
|
12년 전 | 684 | |
| 5992 | 12년 전 | 2906 | ||
| 5991 | 12년 전 | 5240 | ||
| 5990 | 12년 전 | 1645 | ||
| 5989 |
AMDbest
|
12년 전 | 1357 | |
| 5988 | 12년 전 | 1223 | ||
| 5987 |
kiplayer
|
12년 전 | 1141 | |
| 5986 |
한번잘해보자
|
12년 전 | 931 | |
| 5985 |
kiplayer
|
12년 전 | 3144 | |
| 5984 |
dsv421
|
12년 전 | 811 | |
| 5983 |
dsv421
|
12년 전 | 1512 | |
| 5982 |
dsv421
|
12년 전 | 5843 | |
| 5981 | 12년 전 | 3221 | ||
| 5980 |
MFBob
|
12년 전 | 2629 | |
| 5979 | 12년 전 | 3105 | ||
| 5978 |
AMDbest
|
12년 전 | 1465 | |
| 5977 | 12년 전 | 796 | ||
| 5976 | 12년 전 | 1214 | ||
| 5975 | 12년 전 | 1284 | ||
| 5974 | 12년 전 | 616 | ||
| 5973 |
kiplayer
|
12년 전 | 3559 | |
| 5972 |
kiplayer
|
12년 전 | 3983 | |
| 5971 |
kiplayer
|
12년 전 | 2306 | |
| 5970 |
kiplayer
|
12년 전 | 8299 | |
| 5969 |
kiplayer
|
12년 전 | 953 | |
| 5968 | 12년 전 | 8749 | ||
| 5967 |
|
12년 전 | 16907 | |
| 5966 | 12년 전 | 1233 | ||
| 5965 | 12년 전 | 715 | ||
| 5964 | 12년 전 | 6258 | ||
| 5963 | 12년 전 | 710 | ||
| 5962 | 12년 전 | 891 | ||
| 5961 | 12년 전 | 643 | ||
| 5960 | 12년 전 | 787 | ||
| 5959 |
|
12년 전 | 1124 | |
| 5958 | 12년 전 | 987 | ||
| 5957 |
웹디자인되고파
|
12년 전 | 1094 | |
| 5956 | 12년 전 | 3663 | ||
| 5955 | 12년 전 | 2143 | ||
| 5954 | 12년 전 | 4402 | ||
| 5953 | 12년 전 | 3093 | ||
| 5952 | 12년 전 | 4270 | ||
| 5951 | 12년 전 | 2085 | ||
| 5950 | 12년 전 | 1284 | ||
| 5949 | 12년 전 | 940 | ||
| 5948 | 12년 전 | 2086 | ||
| 5947 | 12년 전 | 5008 | ||
| 5946 |
dsv421
|
12년 전 | 1276 | |
| 5945 |
dsv421
|
12년 전 | 4125 | |
| 5944 |
dsv421
|
12년 전 | 5648 | |
| 5943 | 12년 전 | 1293 | ||
| 5942 | 12년 전 | 2544 | ||
| 5941 |
프로프리랜서
|
12년 전 | 1648 | |
| 5940 |
atria
|
12년 전 | 620 | |
| 5939 | 12년 전 | 2347 | ||
| 5938 | 12년 전 | 2090 | ||
| 5937 |
프로프리랜서
|
12년 전 | 779 | |
| 5936 |
프로프리랜서
|
12년 전 | 718 | |
| 5935 |
프로프리랜서
|
12년 전 | 3222 | |
| 5934 |
프로프리랜서
|
12년 전 | 1647 | |
| 5933 |
AMDbest
|
12년 전 | 662 | |
| 5932 |
AMDbest
|
12년 전 | 507 | |
| 5931 | 12년 전 | 8145 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기