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

Case Analysis of php bridging Mode

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

Share

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

Today, I would like to share with you the relevant knowledge points of php bridge mode instance analysis, the content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

Description

1. Combine two unrelated classes together, and then use the methods and properties in the two classes to output a new result.

2. The structure is divided into abstract class, refined abstract class, implementation class, concrete implementation class and client code.

Example

/ * Color abstraction class * Class Colour * / abstract class Colour {/ * @ return mixed * / abstract public function run ();} / * * Black * Class Black * / class Black extends Colour {public function run () {/ / TODO: Implement run () method. Return 'black';}} / * * White * Class White * / class White extends Colour {public function run () {/ / TODO: Implement run () method. Return 'White';}} / * Red * Class Red * / class Red extends Colour {public function run () {/ / TODO: Implement run () method. Return 'red';}} / * shape abstract class * Class Shape * / abstract class Shape {/ * Color * @ var Colour * / protected $colour; / * Shape constructor. * @ param Colour $colour * / public function _ construct (Colour $colour) {$this- > colour = $colour;} / * * @ return mixed * / abstract public function operation ();} / * Round * Class Round * / class Round extends Shape {/ * @ return mixed | void * / public function operation () {/ / TODO: Implement operation () method. Echo $this- > colour- > run (). 'Circle

';}} / * * rectangle * Class Rectangle * / class Rectangle extends Shape {/ * @ return mixed | void * / public function operation () {/ / TODO: Implement operation () method. Echo $this- > colour- > run (). 'rectangle

';}} / * * Square * Class Square * / class Square extends Shape {/ * @ return mixed | void * / public function operation () {/ / TODO: Implement operation () method. Echo $this- > colour- > run (). 'Square

';}} / / client code / / White circle $whiteRound = new Round (new White ()); $whiteRound- > operation (); / / Black square $blackSquare = new Square (new Black ()); $blackSquare- > operation (); / / Red rectangle $redRectangle = new Rectangle (new Red ()); $redRectangle- > operation () / / results White, round, black, square, red and above are all the contents of the article "php Bridge Mode example Analysis". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please 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