Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the function of php bridging mode

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

In this article, the editor introduces in detail "what is the role of php bridging mode", the content is detailed, the steps are clear, and the details are handled properly. I hope this article "what is the role of php bridging mode" can help you solve your doubts.

Function description

1. The bridge mode separates the abstract interface and its implementation, and realizes decoupling, which is a better solution than inheritance.

2. Easy to expand, bridging mode is more flexible than inheritance, and it is easy to combine while reducing the creation of classes.

3. The bridging mode can be used for two independent change dimensions.

Example

/ / employee grouping abstract class Staff {abstract public function staffData ();} class CommonStaff extends Staff {public function staffData () {return "nickname, Xiao Hong, Xiao Hei";}} class VipStaff extends Staff {public function staffData () {return 'Xiao Xing, Xiao long';} / / sending form / / Abstract parent class abstract class SendType {abstract public function send ($to, $content) } class QQSend extends SendType {public function _ construct () {/ / connection mode with QQ interface} public function send ($to, $content) {return $content. '(To'. $to. ' From QQ)

';}} class SendInfo {protected $_ level; protected $_ method; public function _ construct ($level, $method) {/ / A singleton can be used to control resource consumption $this- > _ level = $level; $this- > _ method = $method;} public function sending ($content) {$staffArr = $this- > _ level- > staffData () $result = $this- > _ method- > send ($staffArr, $content); echo $result;}} / / client calls $info = new SendInfo (new VipStaff (), new QQSend ()); $info- > sending ('go home for dinner'); $info = new SendInfo (new CommonStaff (), new QQSend ()); $info- > sending ('back to work') Output: go home for dinner (To Xiao Xing, Xiao long From QQ) continue to work (To nickname, Xiao Hong, Xiao Hei From QQ) read here, this "what is the role of php bridging mode" article has been introduced, want to master the knowledge of this article also need to practice and use in order to understand, if you want to know more related content of the article, welcome to pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report