【发布时间】:2015-03-18 09:27:59
【问题描述】:
软件设计模式中的client是什么意思?例如,我看到这个词在设计模式中被多次提及,例如在this PHP Visitor Design Pattern tutorial 中。它甚至还有一个名为Client的类(它也是一种设计模式吗?)
//Client.php
error_reporting(E_ALL | E_STRICT);
ini_set("display_errors", 1);
// Autoload given function name.
function includeAll($className)
{
include_once($className . '.php');
}
//Register
spl_autoload_register('includeAll');
class Client
{
private static $shapeElement;
private static $color;
private static $package;
//client request
public static function request()
{
self::$shapeElement= array();
self::$shapeElement=$_POST['shape'];
self::$color=$_POST['color'];
self::$package= array();
$obStructure = new ObjectStructure();
$colorVisitor= new self::$color();
//Attach concrete elements to array & accept visitor
foreach (self::$shapeElement as $shapeNow)
{
$obStructure->attach(new $shapeNow,$colorVisitor);
}
//Display selected shapes
self::$package=$obStructure->getElements();
foreach (self::$package as $colorShape)
{
echo $colorShape->showShape();
}
}
}
Client::request();
来自wikipedia,客户端-服务器网络中的客户端,也就是我通常理解的,
客户端是访问 服务器提供的服务。服务器经常(但不是 总是)在另一个计算机系统上,在这种情况下客户端访问 通过网络提供的服务。该术语适用于程序或 属于客户端-服务器模型的设备。
那么这也是软件设计模式中client的定义吗?
如果将客户端做成类,
class Client
{
...
}
那么,我是否也可以拥有 许多 个客户端,我应该将这些客户端保留在 MVC 架构模式中的什么位置?我应该/可以创建一个名为 client 的目录并将所有客户端类保存在其中吗?
【问题讨论】:
标签: php design-patterns client-server client