public static function main(array $args = array())
 {
     $nyStore = new NYPizzaStore();
     $chicagoStore = new ChicagoPizzaStore();
     $pizza = $nyStore->orderPizza("cheese");
     println("Ethan ordered a " . $pizza . "\n");
     $pizza = $chicagoStore->orderPizza("cheese");
     println("Joel ordered a " . $pizza . "\n");
     $pizza = $nyStore->orderPizza("clam");
     println("Ethan ordered a " . $pizza . "\n");
     $pizza = $chicagoStore->orderPizza("clam");
     println("Joel ordered a " . $pizza . "\n");
     $pizza = $nyStore->orderPizza("pepperoni");
     println("Ethan ordered a " . $pizza . "\n");
     $pizza = $chicagoStore->orderPizza("pepperoni");
     println("Joel ordered a " . $pizza . "\n");
     $pizza = $nyStore->orderPizza("veggie");
     println("Ethan ordered a " . $pizza . "\n");
     $pizza = $chicagoStore->orderPizza("veggie");
     println("Joel ordered a " . $pizza . "\n");
 }
Esempio n. 2
0
<?php

require_once 'NYPizzaStore.php';
require_once 'ChicagoPizzaStore.php';
$nyStore = new NYPizzaStore();
$chicagoStore = new ChicagoPizzaStore();
$pizza = $nyStore->orderPizza("cheese");
echo "<br/><br/>Ethan recieved a " . $pizza->getName() . "<hr/>";
$pizza = $chicagoStore->orderPizza("cheese");
echo "<br/><br/>Joel recieved a " . $pizza->getName() . "<hr/>";
$pizza = $nyStore->orderPizza("clam");
echo "<br/><br/>Ethan recieved a " . $pizza->getName() . "<hr/>";
$pizza = $chicagoStore->orderPizza("clam");
echo "<br/><br/>Joel recieved a " . $pizza->getName() . "<hr/>";
$pizza = $nyStore->orderPizza("pepperoni");
echo "<br/><br/>Ethan recieved a " . $pizza->getName() . "<hr/>";
$pizza = $chicagoStore->orderPizza("pepperoni");
echo "<br/><br/>Joel recieved a " . $pizza->getName() . "<hr/>";
$pizza = $nyStore->orderPizza("veggie");
echo "<br/><br/>Ethan recieved a " . $pizza->getName() . "<hr/>";
$pizza = $chicagoStore->orderPizza("veggie");
echo "<br/><br/>Joel recieved a " . $pizza->getName() . "<hr/>";
Esempio n. 3
0
    public function createPepperoni()
    {
        println('use Chicago pepperoni');
    }
    public function createSauce()
    {
        println('use Chicago sauce');
    }
    public function createVeggies()
    {
        println('use Chicago veggies');
    }
}
println(SEPARATE, '工厂模式', SEPARATE);
showImgs('4.png', '4_1_.png');
$pizza = new NYPizzaStore();
$pizza->orderPizza('cheese');
println();
$pizza2 = new ChicagoPizzaStore();
$pizza2->orderPizza('cheese');
println(SEPARATE, 'END', SEPARATE);
/**
* 输出:
 use NY dough
 use NY cheese
 use NY sauce
 use NY clam
 Bake for 25 minutes at 350
 Cutting the pizza into diagonal slices
 Place pizza in official PizzaStore Box
Esempio n. 4
0
{
}
class NYPizzaStore extends PizzaStore
{
    public function createPizza($type)
    {
        $pizza = null;
        if ($type == 'cheese') {
            $pizza = new NYStyleCheesePizza();
        } elseif ($type == 'greek') {
            $pizza = new NYStyleGreekPizza();
        } elseif ($type == 'pepperoni') {
            $pizza = new NYStylePepperoniPizza();
        } elseif ($type == 'clam') {
            $pizza = new NYStyleClamPizza();
        } elseif ($type == 'veggie') {
            $pizza = new NYStyleVeggiePizza();
        }
        return $pizza;
    }
}
class NYPizzaFactory extends SimplePizzaFactory
{
}
class ChicagoPizzaFactory extends SimplePizzaFactory
{
}
$nyStore = new NYPizzaStore();
$pizza = $nyStore->orderPizza('veggie');
//$chicagoStore = new ChicagoPizzaStore();
//$pizza = $chicagoStore->orderPizza('veggie');