1 Avoid multiple inheritance at all costs, as it’s too complex to be reliable. If you’re stuck with it, then be prepared to know the class hierarchy and spend time finding where everything is coming from.避免使用多层次继承
2 Use composition to package code into modules that are used in many different unrelated places and situations.模块可用组合
3 Use inheritance only when there are clearly related reusable pieces of code that fit under a single common concept or if you have to because of something you’re using.
When to Use Inheritance or Composition
最新推荐文章于 2021-02-28 01:51:05 发布