Item-35 Consider Alternatives to Virtual Functions
· ☕ 7 min read
Alternatives to virtual functions include the NVI idiom (as an example of the Template Method design pattern) and various forms of the Strategy design pattern.
Alternatives to virtual functions include the NVI idiom (as an example of the Template Method design pattern) and various forms of the Strategy design pattern.
Names in derived classes hide names in base classes, which is not desirable in public inheritance. To fix it, employ using
declarations or forwarding functions to make hidden names visible again.
Everything that applies to base classes must also apply to derived classes in public inheritance, for every derived class object is a base class object.
To minimize compilation dependencies, depend on declarations instead of definitions via techniques such as Handle classes and Interface classes.