我想使用PHP实现图的下一个片段.
请参阅下面的组成示例图:
我们可以使用内部类在Java中实现组合.
但PHP中没有"内部类"的类比.当然,还有一些特点.但是我们可以在多个班级中使用它.
我已经实现了这样的组合:
class Head {
private static $instance = NULL;
private function __construct(){}
public static function getInstance() {
$traces = debug_backtrace();
if (strcmp($traces[1]['class'], 'Human')) {
echo "<br>Only human has head"; // Exception can be thrown here
return NULL;
}
if (!static::$instance) static::$instance = new self();
return static::$instance;
}
public function __toString() {
return 'Head';
}
}
class Human {
private $head;
public function __construct() {
$this->head = Head::getInstance();
}
public function __toString() {
return 'I …Run Code Online (Sandbox Code Playgroud) 7.3.3 关联(来自内核),第 36 页,UML 上层结构,v2.4.1:
UML 中是否有关于分类器拥有的关联和关系拥有的关联的真实示例?
bouml 中的聚合/组合和定向聚合/组合有什么区别?
除了 bouml 和 bouml 在其站点中没有解释外,其他地方找不到定向聚合/组合概念。
注意:基于代码的解释会好得多。