我先从比尔·卡温(Zend_DB的候选者)那里读过一些与数据库表没有直接联系的模式。 (我认为,有些发展中国家有其模式,可直接延伸Zentd_tables,从而更难以增加 objects子的 objects子,这是有意义的。)
So what Bill Karwin was saying is that a Model has
tables and isn t a
table but I m still thinking the way I have it is correct as its designed in an object oriented manner.
例如(理由说明):
A Monster has 1:M Mouth. a Mouth has 1:M Tooth.
因此,在我的数据库中,有5个表格:
Monster: id, name, type
MonsterMouth: id, monster_id, mouth_id
Mouth: id, size
MouthTeeth: id, mouth_id, tooth_id
Tooth: id, size, shape, sharpness
然后是3个班级:
class Model_Monster {
private $id, $name, $type, $mouths = array();
public function __construct ($id) {
// Set properties from DB for supplied ID
// Go through DB and add the mouths based on monster ID
}
public function countTeeth () {
// Loop through each $mouths as $mouth and call $mouth->getTotalTeeth();
}
}
class Model_MonsterMouth {
private $id, $size, $teeth = array();
public function __construct($id) {
// Set properties from DB for supplied ID
// Go through DB and add the types of teeth for this mouth ID
}
public function getTotalTeeth () {
// return sizeof($teeth);
}
}
class Model_Tooth {
private $id, $size, $shape, $sharpness;
public function __construct($id) {
// Populate details based on ID passed
}
}
然后,我猜测计算牙齿和牙齿的方法。
$monsterId = 1;
$monster = new Monster($monsterId);
// Count total teeth
$totalTeeth = $monster->countTeeth();
因此,僧.可能有多种不同的口.,1口mouth可能有多种不同的牙齿。
After writing out this lengthy post I think I ve got it right and that Bill Karwin
is talking about those who have 5 Models
rather than 3
...
页: 1
3个模型代码>中的代码>2 用于储存许多其他类型的物体。
如果mon门在大约10种不同类型牙齿中的9-10克之间有10口mouth,这是否是一个业绩问题? 我指的是PHP。 如果一个物体有1-100k且在复合物品中添加1-100k,那么我就认为,我只应当拥有一个带有若干财产的物体,以表明有多少此类物品。
如果我听起来正确的话,也许会帮助一些与之有问题的其他人。
感谢:D Dom