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.
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.
相关文章推荐
- When and Why do we use "#if 0"
- When to Use Inheritance or Composition
- Why do I need to use DAC from Oracle BI?
- What do we need to develop android applications?
- When we use PdfStamper to merge fields.
- what is WLAN ? when and why we need use it ?
- When we need to inherit from WSS WebPart class?
- Why do we need smart pointer and how to implement it.
- What's the use of do while(0) when we define a macro?
- what is the virtual machine, when and why we need use it ?
- Do We Really Need to Collect Millions of Faces for effective face recognition
- When do we use Initializer List in C++?
- use regular expression to delete the lines which we don't need
- ccah-500 第25题 what do you need to do when adding a new slave node to cluster
- 读书心得-Do we Need Hundreds of Classifiers to Solve Real World Classification Problems
- How do we release the GDI object when we use selectobject choosing a brush?
- When do we use Initializer List in C++?
- Why does a statically built Qt use the dynamic Visual Studio runtime libraries ? Do I need to deploy
- log4j when need to use log4j.isDebugEnabled()
- 每日英语:When The Boss Works Long Hours, Do We All Have To?