您的位置:首页 > 其它

When do we need to use Inheritance?

2007-04-25 14:21 489 查看
Basically, inheritance and composition both make one object contain another object.
Then when do we need to use inheritance not composition?
1. Need use polymorphism mechanism by upcasting. For c++, it's done by virtual function.
2. Need to access a class's some functions or member variables, but don't want to expose those to be public accessible.
3. Need to reuse code in an apparent inheritance relationship tree.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: