【发布时间】:2012-01-07 01:33:40
【问题描述】:
什么时候最理想:
class USER {
// stuff about user
}
class PROFILE extends USER {
// stuff about user's profile
}
什么时候是理想的:
class USER {
$id;
$profile;
function __construct($id) {
$this->id = $id;
$this->profile = new PROFILE($id);
// set profile variables
}
}
class PROFILE {
$id;
// other variables pertaining to profile
function __construct($id) {
$this->id = $id;
}
}
我觉得第二个例子更舒服?有什么我应该注意的具体警告吗?
我应该将一个视为不互斥的子集而将另一个视为子集吗?
【问题讨论】:
标签: php class inheritance parent extends