Dispatcher Pattern
出自VFP Wiki
小 |
TrlarOlrac (對話 | 貢獻) |
||
第1行: | 第1行: | ||
+ | http://www.textracacel.com | ||
====Dispatcher Pattern==== | ====Dispatcher Pattern==== | ||
- | + | çå® RUN!PC å
æèç±æç¶å
çæ寫ç"ç±è»é«å質檢é©è«Design Patternçæç¨"ä¸æ,æ覺å¾ç¨ VFP å°±å¯ä»¥å¾ç°¡å®çä½å°,æ以就以 VFP 實ä½. | |
- | + | 該æ以è¨ç®çç
§ç¨
çºå¼å | |
- | + | è¨ç®çç
§ç¨
çæå,æéè¦ä¾ç
§æ±½ç¼¸çccæ¸ä»¥åç§äºº/çæ¥ç¨è»ä¾å¤å®æ¶è²»çæ¨æº,ç
§ä¸è¬ç寫æ³,å¾èªç¶å°±æç¨å°å¾å¤ If...Then...Else æ do case...endcase, å¯æ¯é樣åç¨å¼ç¢¼å°±æè®å¾å¾é·å¾é·,èé£ä»¥ç¶è·. | |
- | + | åæ¯é樣: | |
<pre> | <pre> | ||
If cc < 500 | If cc < 500 | ||
第11行: | 第12行: | ||
if cc < 600 | if cc < 600 | ||
money=1200 | money=1200 | ||
- | && ..... | + | && ..... ç¥ |
endif | endif | ||
endif | endif | ||
</pre> | </pre> | ||
- | + | ç¨ do case ç話åæ¯é樣 | |
<pre> | <pre> | ||
do case | do case | ||
第23行: | 第24行: | ||
case between( 501, 599 ) | case between( 501, 599 ) | ||
money=1200 | money=1200 | ||
- | && ... | + | && ... ç¥ |
endcase | endcase | ||
</pre> | </pre> | ||
- | + | æå
ç以ä¸å Dispatcher pattern 解決æ¤ä¸åé¡. | |
- | + | å¨ VFP 裡é¢å¯ä»¥ç´æ¥çµåè³æ庫ä½æ´å¥½çè§£æ³ | |
<pre> | <pre> | ||
第89行: | 第90行: | ||
</pre> | </pre> | ||
- | + | ç§,é樣ä¸æ¯ç°¡å®å¤äºå?? | |
- | + | å¨é裡æç£å¼çä¸ä¸,å¸æ大家å¦æææ´å¥½çè§£æ³ | |
- | + | ä¹ post ä¸ä¾,è®å¤§å®¶è§æ©ä¸ä¸ | |
^_^ | ^_^ | ||
- | [[category: | + | [[category:以VFPä»ç´¹Design Pattern]] |
在2009年5月21日 (四) 15:10所做的修訂版本
Dispatcher Pattern
çå® RUN!PC å æèç±æç¶å çæ寫ç"ç±è»é«å質檢é©è«Design Patternçæç¨"ä¸æ,æ覺å¾ç¨ VFP å°±å¯ä»¥å¾ç°¡å®çä½å°,æ以就以 VFP 實ä½.
該æ以è¨ç®çç §ç¨ çºå¼å è¨ç®çç §ç¨ çæå,æéè¦ä¾ç §æ±½ç¼¸çccæ¸ä»¥åç§äºº/çæ¥ç¨è»ä¾å¤å®æ¶è²»çæ¨æº,ç §ä¸è¬ç寫æ³,å¾èªç¶å°±æç¨å°å¾å¤ If...Then...Else æ do case...endcase, å¯æ¯é樣åç¨å¼ç¢¼å°±æè®å¾å¾é·å¾é·,èé£ä»¥ç¶è·. åæ¯é樣:
If cc < 500 money=900 else if cc < 600 money=1200 && ..... ç¥ endif endif
ç¨ do case ç話åæ¯é樣
do case case between( 0, 500 ) money=900 case between( 501, 599 ) money=1200 && ... ç¥ endcase
æå ç以ä¸å Dispatcher pattern 解決æ¤ä¸åé¡. å¨ VFP 裡é¢å¯ä»¥ç´æ¥çµåè³æ庫ä½æ´å¥½ç解æ³
* * ITax.prg * DEFINE CLASS ITax as custom PROCEDURE Init() create cursor crTax( cc_lo I, cc_hi I, PrivateTax Y, BusinesTax Y ) insert into crTax values ( 0, 500, $ 1620, $ 900 ) insert into crTax values ( 501, 599, $ 2160, $ 1200 ) insert into crTax values ( 600, 1199, $ 4320, $ 2160 ) insert into crTax values ( 1200, 1799, $ 7120, $ 3060 ) insert into crTax values ( 1800, 2399, $11230, $ 6480 ) insert into crTax values ( 2400, 2999, $15210, $ 9900 ) insert into crTax values ( 3000, 4199, $28220, $16380 ) insert into crTax values ( 4200, 5399, $46170, $24300 ) insert into crTax values ( 5400, 6599, $69690, $33660 ) insert into crTax values ( 6600, 7799, $117000, $44460 ) insert into crTax values ( 7800, 9999999, $117000, $44460 ) ENDPROC PROCEDURE Destroy() use in crTax ENDPROC PROCEDURE GetTax( cc, theKind ) local ly_result local lc_oldalias lc_oldalias=alias() select("crTax") go top locate for between( cc, crTax.cc_lo, crTax.cc_hi ) if found() ly_result=crTax.&theKind else ly_result=0 endif select( lc_oldalias ) return ly_result ENDPROC PROCEDURE GetPrivateTax( cc ) return this.GetTax( cc, "PrivateTax" ) ENDPROC PROCEDURE GetBusinessTax( cc ) return this.GetTax( cc, "BusinesTax" ) ENDPROC ENDDEFINE
* * test_itax.prg * LOCAL lo_obj set procedure to itax.prg lo_obj=createobject("ITax") ? lo_obj.GetPrivateTax( 1000 ) ? lo_obj.GetBusinessTax( 2000 )
ç§,é樣ä¸æ¯ç°¡å®å¤äºå?? å¨é裡æç£å¼çä¸ä¸,å¸æ大家å¦æææ´å¥½çè§£æ³ ä¹ post ä¸ä¾,è®å¤§å®¶è§æ©ä¸ä¸ ^_^