Case Analysis of php bridging Mode
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.