|
<?php
Specification of interfaces for manufacturing individual parts
Interface Builder
{
Manufacturing Map Parts
Public function Buildmappart ();
Manufacturing Building Parts
Public function Buildbuildingpart ();
Manufacturing Force Parts
Public function Buildarmypart ();
Assemble parts
Public function GetResult ();
}
Actual builder class, such as initialization of a task
Class ConcreteBuilder implements Builder
{
Manufacturing Map Parts
Public Function Buildmappart ()
{
Draw a map based on the task set.
echo ' map parts n ';
}
Manufacturing Building Parts
Public Function Buildbuildingpart ()
{
Draw the construction according to the task, including the player's and Enemy's
Echo ' Building parts n ';
}
Manufacturing Force Parts
Public Function Buildarmypart ()
{
Draw the force according to the task, including the player's and Enemy's
Echo ' Force parts n ';
}
Assemble parts
Public Function GetResult ()
{
Stacking and processing all things to form an initialization screen
Echo ' assemble parts n ';
}
}
Monitoring class, which is the class that controls the drawing process
Class Director
{
Private properties, determining the builder used
Private $builder;
constructor method, parameter is the selected builder object
Public function __construct ($builder)
{
Determine which builder to use
$this->builder = $builder;
}
Responsible for the method of construction process, call Builder object method, make all parts
Public Function Buildeallpart ()
{
Manufacturing Map Parts
$this->builder->buildmappart ();
Manufacturing Building Parts
$this->builder->buildbuildingpart ();
Manufacturing Force Parts
$this->builder->buildarmypart ();
}
}
Assuming that the actual builder object we need is initialized according to the task
$concreteBuilder = new ConcreteBuilder ();
Initialize a supervised object
$director = new Director ($concreteBuilder);
Make all parts
$director->buildeallpart ();
Finally let the builder assemble the parts and create the picture
$concreteBuilder->getresult ();
?>
|