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.

相关文章:

  • 2021-06-09
  • 2021-12-21
  • 2021-04-22
  • 2022-12-23
  • 2021-12-29
  • 2021-11-26
  • 2021-12-08
  • 2022-12-23
猜你喜欢
  • 2021-05-20
  • 2022-01-05
  • 2021-11-14
  • 2021-12-06
  • 2021-06-12
  • 2021-05-17
  • 2022-01-19
相关资源
相似解决方案