Design patterns 条令战略模式
我正在尝试创建以下结构Design patterns 条令战略模式,design-patterns,doctrine-orm,mapping,Design Patterns,Doctrine Orm,Mapping,我正在尝试创建以下结构 class bot { protected $name; protected $type; public function __construct($name, IBotType $type) { $this->name = $name; $this->type = $type; } public function getProduct() { retu
class bot
{
protected $name;
protected $type;
public function __construct($name, IBotType $type)
{
$this->name = $name;
$this->type = $type;
}
public function getProduct()
{
return $this->type->produceProduct();
}
}
class botType1 implements IBotType
{
public function produceProduct()
{
return 'Donut';
}
}
class botType2 implements IBotType
{
public function produceProduct()
{
return 'Coffee';
}
}
作为实体的唯一类是bot类,类型将具有一些基本配置,如name等,一些逻辑ex botType1将能够生成甜甜圈,botType2将生成咖啡等
主要的问题是如何使用条令存储信息,以及如何从数据库加载对象以创建正确的bot类型
我希望这是有道理的
请注意,我不想将每种类型存储到数据库中,我希望有一个php类,我将在其中存储所有的控制逻辑
(在实际的应用程序中,有100个不同类型的bot,我们通过它们调用getProducts来创建产品等,希望上面的示例有意义!)
谢谢你抽出时间 这花了我一些时间,但我相信通过下面的文章,我应该能够完全理解我在表格中提出的要求: 或 玩得开心