PHP Classes

File: factory.php

Recommend this page to a friend!
  Classes of Malik Naik  >  PHP Design Patterns Repository  >  factory.php  >  Download  
File: factory.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Design Patterns Repository
Implementation of common design patterns in PHP
Author: By
Last change:
Date: 8 months ago
Size: 451 bytes
 

Contents

Class file image Download
<?php

require_once 'vendor/autoload.php';

use
DesignPattern\Factory\Logistics;
use
DesignPattern\Factory\RoadLogistics;
use
DesignPattern\Factory\SeaLogistics;

function
printTransportDetails(Logistics $logistics) : void
{
    print
$logistics->getTransportMessage() . "\n";
}

printTransportDetails(new RoadLogistics);
printTransportDetails(new SeaLogistics);

// Output:
//
// Truck: Deliver by land in a box.
// Ship: Deliver by sea in a container.

For more information send a message to info at phpclasses dot org.