Bridging mode for PHP implementation of design Patterns

Source: Internet
Author: User

<?php/* Bridging mode: Separates the abstract and the implementation parts so that they can be independently changed. *  * in software systems, some types because of their own logic, it has two or more dimensions of the change, bridging mode is to deal with this multidimensional changes *//* example: different cars in different streets driving. Car variable, street variable *  *  */abstract class Road{abstract Public function run (); Class Quickroad extends Road{public $car;p ublic function __construct ($car) {$this->car = $car;} Public Function Run () {$this->car->run (); Echo ' Drive on the freeway ';}} Class Street extends Road{public $car;p ublic function __construct ($car) {$this->car = $car;} Public Function Run () {$this->car->run (); Echo ' City street Drive ';}} Abstract class Car{abstract Public function Run ();} Class Jeep extends Car{public function run () {echo ' Jeep in ';}} Class Bus extends Car{public function run () {echo ' Bus in ';}} $car = new bus (); $road = new Quickroad ($car); $road->run (); echo "<br/>"; $car = new Jeep (); $road = New Street ($car) ; $road->run ();? >

UML Class Diagram

Bridging mode for PHP implementation of design Patterns

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.