本文章来给大家介绍php入门教程之工厂模式哦,工厂模式概念:实例化对象,用工厂方法替代new操作,有需要了解学习的朋友可参考.
工厂模式实例代码:
- <!–?php
- //首先定义什么是人类
- interface Human {
- //人是愉快的,会笑的
- public function laugh();
- //人类还会哭,代表痛苦
- public function cry();
- //人类会说话
- public function talk();
- }
- //然后定义具体的人种
- class YellowHuman implements Human {//黄色人种,这个翻译的不准确,将就点吧
- function cry() { var_dump( "黄色人种会哭");}
- function laugh() {var_dump( "黄色人种会大笑,幸福呀!");}
- function talk() {var_dump( "黄色人种会说话,一般说的都是双字节"); }
- }
- class WhiteHuman implements Human { //白色人种
- public function cry() {var_dump("白色人种会哭");}
- public function laugh() {var_dump("白色人种会大笑,侵略的笑声"); }
- public function talk() {var_dump("白色人种会说话,一般都是但是单字节!"); }
- }
- class BlackHuman implements Human { //黑色人种
- public function cry() {var_dump("黑色人种会哭");}
- public function laugh() {var_dump("黑色人种会大笑,侵略的笑声"); }
- public function talk() {var_dump("黑色人种会说话,一般都是但是单字节!"); }
- }
- //人种也定义完毕了,那我们把八卦炉定义出来:
- class HumanFactory {
- //定一个烤箱,泥巴塞进去,人就出来,这个太先进了
- public static function createHuman( $c ){
- if ($c instanceof Human ) {//判断是否继承自Human
- return $c;
- }else {
- var_dump("必须跟HuMan有一腿");
- }
- }
- }
- var_dump("————造出的第一批人是这样的:白人—————–");
- $whiteHuman = HumanFactory::createHuman( new WhiteHuman());
- $whiteHuman->cry();
- $whiteHuman->laugh();
- $whiteHuman->talk();
- //女娲第二次造人,火候加足点,然后又出了个次品,黑人
- var_dump("nn————造出的第二批人是这样的:黑人—————–");
- $blackHuman = HumanFactory::createHuman(new BlackHuman());
- $blackHuman->cry();
- $blackHuman->laugh();
- $blackHuman->talk();
- //第三批人了,这次火候掌握的正好,黄色人种(不写黄人,免得引起歧义),备注:RB人不属于此列
- var_dump("nn————造出的第三批人是这样的:黄色人种—————–");
- $yellowHuman = HumanFactory::createHuman(new YellowHuman());
- $yellowHuman->cry();
- $yellowHuman->laugh();
- $yellowHuman->talk();
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!
波比源码 » php工厂模式简单使用说明
波比源码 » php工厂模式简单使用说明
levofloxacin uk levaquin for sale online
buy aldactone 25mg online cheap buy diflucan pill order fluconazole 100mg generic
acillin generic bactrim 960mg tablet buy erythromycin 500mg generic
cost anastrozole biaxin 500mg cost sildenafil over the counter
buy bupropion online buy zyrtec 5mg generic seroquel 50mg uk
imuran oral buy imuran 100 mcg generic order sildenafil without prescription
cheap cialis online buy cialis 5mg without prescription amantadine online order
revia 50mg drug order generic aripiprazole 20mg abilify price
buy avlosulfon 100 mg online cheap buy allegra pill aceon 8mg drug
fluvoxamine 50mg over the counter duloxetine 20mg for sale buy glipizide pills
viagra 50mg sale lisinopril generic buy lisinopril 5mg online cheap
order vardenafil 20mg pill medrol tablet cost medrol
buy clomid without prescription online slots for real money legitimate online slots for money
buy xenical 120mg for sale zovirax 800mg canada acyclovir oral
how to get cialis buy inderal 20mg pills oral plavix 75mg
methotrexate for sale online methotrexate 5mg us metoclopramide 20mg oral
buy ozobax online zanaflex ca buy toradol 10mg generic
buy colchicine 0.5mg sale buy colchicine pill best casino online
order generic zantac 300mg generic ranitidine 150mg buy celebrex 200mg sale
casino slots free real online casino tadalafil 20mg generic
prednisone medication order amoxicillin 250mg online cheap order amoxicillin 250mg online
cheap viagra for sale cheap sildenafil 50mg buy cialis 20mg generic
casinos stromectol 3mg usa provigil over the counter
montelukast 10mg generic viagra over the counter sildenafil 100mg cheap
adalat 30mg tablet buy aceon 4mg pill allegra medication
altace 10mg canada amaryl price order arcoxia without prescription
doxycycline 200mg generic albuterol 4mg usa order cleocin
cheap research paper writers college essay service azulfidine 500 mg uk
olmesartan price buy verapamil 240mg pills order depakote generic
order diamox 250mg online imuran tablet azathioprine pills
amoxicillin 1000mg generic purchase amoxicillin generic ivermectin 3mg pill
fosamax 35mg cheap buy nitrofurantoin 100mg motrin price
dapoxetine 30mg cheap motilium us buy domperidone generic
order ropinirole 1mg pill buy requip 2mg generic buy labetalol online cheap
purchase tadalafil for sale order tadalafil 20mg pill purchase trimox generic
buy fenofibrate 160mg generic viagra pills 50mg oral viagra 50mg
glucophage drug order calan generic order tamoxifen 20mg online
clomid 50mg pill buy clomid 100mg pills prednisolone us
accutane 10mg drug deltasone order ampicillin brand
best ed pills non prescription purchase fildena pills propecia 5mg tablet
order absorica pills order amoxicillin 250mg sale zithromax 250mg for sale
provigil 200mg generic cost lopressor order metoprolol online cheap
buy prednisolone 5mg online cheap prednisolone 10mg oral buy furosemide 100mg generic
order generic azathioprine 25mg naproxen 250mg sale buy naproxen 500mg for sale
alfuzosin us buy desyrel 100mg online diltiazem 180mg usa
buy ezetimibe 10mg online cheap order ezetimibe generic buy methotrexate medication
buy lexapro 20mg generic naltrexone 50 mg uk order revia 50mg pills
letrozole 2.5 mg for sale buy sildenafil 50mg sildenafil in usa
buy provigil online cheap buy promethazine 25mg for sale order deltasone 5mg for sale
purchase amoxicillin without prescription buy amoxil 500mg generic cost prednisolone 10mg
neurontin 600mg without prescription order lasix generic vibra-tabs for sale online
order prednisolone 40mg for sale buy neurontin 600mg pill lasix 100mg sale
buy ventolin pills for sale buy clavulanate pill levoxyl without prescription
buy clomiphene no prescription plaquenil 200mg over the counter hydroxychloroquine 400mg drug
order tenormin 100mg for sale medrol cost order letrozole 2.5 mg
levoxyl order buy synthroid 150mcg online buy levitra 10mg sale
albenza 400mg us order medroxyprogesterone online order provera 5mg
glycomet 500mg ca buy norvasc 5mg for sale oral amlodipine
praziquantel 600 mg us buy cyproheptadine 4mg online cheap cyproheptadine price
purchase losartan for sale order topamax sale buy topamax cheap
brand imitrex cost imitrex 25mg buy avodart 0.5mg generic
ketorolac over the counter buy generic inderal inderal 20mg canada
ranitidine 150mg tablet order celecoxib online cheap purchase celebrex online cheap
buy clopidogrel cheap buy ketoconazole 200 mg for sale order nizoral 200mg sale
buy generic tamsulosin online order zofran 4mg generic buy aldactone pills for sale
cheap betamethasone 20 gm betamethasone 20 gm tablet purchase sporanox pills
combivent 100 mcg brand linezolid 600mg generic buy linezolid for sale
nateglinide 120mg over the counter buy candesartan 16mg purchase candesartan sale
carbamazepine drug buy carbamazepine 400mg online order lincocin 500mg generic
cost cialis 20mg buy branded cialis cheap sildenafil generic
nolvadex 20mg over the counter order tamoxifen 10mg generic order cefuroxime 500mg pills
buy sildenafil 100mg without prescription sildenafil 100mg price buy cheap sildalis
buy minocycline without prescription buy hytrin 5mg generic order pioglitazone 30mg generic
buy cialis sale viagra 100mg pills for men cialis 10mg brand
azipro 250mg over the counter prednisolone 40mg us neurontin 600mg drug
ivermectin 3mg online stromectol pills for humans buy deltasone without prescription
order furosemide pills generic furosemide order albuterol generic
order generic levitra generic vardenafil 10mg hydroxychloroquine buy online
mesalamine 400mg for sale buy avapro generic avapro 150mg pills
how to buy acetazolamide buy acetazolamide 250mg buy azathioprine online cheap
cheap digoxin 250mg telmisartan 80mg brand molnupiravir 200mg price
naproxen 250mg price omnicef 300mg oral order lansoprazole 15mg sale
albuterol 100 mcg price buy proventil generic phenazopyridine price
olumiant 4mg drug where to buy lipitor without a prescription order generic atorvastatin 40mg
generic nifedipine nifedipine 10mg tablet generic fexofenadine 180mg