位置: IT常识 - 正文

php桥接模式是什么(桥接模式例题)

编辑:rootadmin

推荐整理分享php桥接模式是什么(桥接模式例题),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:桥接模式的缺点,桥接模式的缺点,桥接是否成功,桥接模式的缺点,桥接模式的缺点,桥接模式案例,桥接模式案例,桥接模式案例,内容如对您有帮助,希望把文章链接给更多的朋友!

php桥接模式是什么(桥接模式例题)

476

说明

1、将两个原本不相关的类结合在一起,然后利用两个类中的方法和属性,输出一份新的结果。

2、结构分为抽象类、被提炼的抽象类、实现类、具体实现类和客户端代码。

实例

/***颜色抽象类*ClassColour*/abstractclassColour{/***@returnmixed*/abstractpublicfunctionrun();/***黑色*ClassBlack*/classBlackextendsColour{publicfunctionrun(){//TODO:Implementrun()method.return'黑色';/***白色*ClassWhite*/classWhiteextendsColour{publicfunctionrun(){//TODO:Implementrun()method.return'白色';/***红色*ClassRed*/classRedextendsColour{publicfunctionrun(){//TODO:Implementrun()method.return'红色';/***形状抽象类*ClassShape*/abstractclassShape{/***颜色*@varColour*/protected$colour;/***Shapeconstructor.*@paramColour$colour*/publicfunction__construct(Colour$colour){$this->colour=$colour;/***@returnmixed*/abstractpublicfunctionoperation();/***圆形*ClassRound*/classRoundextendsShape{/***@returnmixed|void*/publicfunctionoperation(){//TODO:Implementoperation()method.echo$this->colour->run().'圆形<br>';/***长方形*ClassRectangle*/classRectangleextendsShape{/***@returnmixed|void*/publicfunctionoperation(){//TODO:Implementoperation()method.echo$this->colour->run().'长方形<br>';/***正方形*ClassSquare*/classSquareextendsShape{/***@returnmixed|void*/publicfunctionoperation(){//TODO:Implementoperation()method.echo$this->colour->run().'正方形<br>';//客户端代码//白色圆形$whiteRound=newRound(newWhite());$whiteRound->operation();//黑色正方形$blackSquare=newSquare(newBlack());$blackSquare->operation();//红色长方形$redRectangle=newRectangle(newRed());$redRectangle->operation();//运行结果白色圆形黑色正方形红色长方形
本文链接地址:https://www.jiuchutong.com/zhishi/311772.html 转载请保留说明!

上一篇:python如何过滤列表中的唯一值(python怎么过滤多余空格)

下一篇:dedecms调用当前文章所属栏目名(dedecms进入数据库)

免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络