由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问个经典的car oo design题
相关主题
被design题搞疯了(附题目)问个MapReduce面试题
这道设计面试题这样解对吗PHD ME转AE,不知道对找工作多大影响,求建议
一道OO设计题,有经验的请给些思路,多谢背景调查中的Education
rate of unemployment by major问个在学校里做volunteer的事情
software engineer vs. assistant professor问个H1B 的问题: 公司上班 + part-time Adjunct Professor
Background check到底check什么 + 一个不知道写不写intern问个g家contact recruiter的问题
招聘,Biomedical Engineering Assistant Professor (转载)问个review paper的问题
向大家请教Silicon Valley的Santa Clara University的Graduate Engineering项目问个thank you letter的问题
相关话题的讨论汇总
话题: engine话题: car话题: body话题: tries
进入JobHunting版参与讨论
1 (共1页)
q******8
发帖数: 848
1
如何体现composition和aggregation的区别?
比如car有body,engine,tires。但是engine和tries与car应该是aggregation的关系,
那么在类设计的时候是不是应该这样:
class Car{
private:
Body body;
Tire* tries;
Engine engine;
public:
Car(Tire* tries, Engine engine){
body = new Body();
tries = tries;
engine = engine;
}
~Car(){
delete body;
}
}
在销毁car object时候只销毁composition关系的,然后保留aggregation关系的,是这
么写吗?
q******8
发帖数: 848
2
求大牛指点。
y******n
发帖数: 47
3
From wikipedia:
Composition implies the ownership. When the owning object is destroyed, so
are the contained objects. In aggregation, this is not necessarily true. For
example, a university owns various departments (e.g., chemistry), and each
department has a number of professors. If the university closes, the
departments will no longer exist, but the professors in those departments
will continue to exist. Therefore, a University can be seen as a composition
of departments, whereas departments have an aggregation of professors. In
addition, a Professor could work in more than one department, but a
department could not be part of more than one university.

【在 q******8 的大作中提到】
: 求大牛指点。
1 (共1页)
进入JobHunting版参与讨论
相关主题
问个thank you letter的问题software engineer vs. assistant professor
问个简历列experience的问题Background check到底check什么 + 一个不知道写不写intern
问个工作title的问题招聘,Biomedical Engineering Assistant Professor (转载)
问个简历的针对性问题 (转载)向大家请教Silicon Valley的Santa Clara University的Graduate Engineering项目
被design题搞疯了(附题目)问个MapReduce面试题
这道设计面试题这样解对吗PHD ME转AE,不知道对找工作多大影响,求建议
一道OO设计题,有经验的请给些思路,多谢背景调查中的Education
rate of unemployment by major问个在学校里做volunteer的事情
相关话题的讨论汇总
话题: engine话题: car话题: body话题: tries