Effective C++ Ed. 3rd: Item 35. Consider alternatives to virtual functions

  • Non-virtual Interface Idiom (NVI): Provides an alternative to public virtual functions by making these public and accesible via a public non-virtual member function. It does NOT elimination the use of virtuals.
  • Function Pointers: To eliminate using virtual member functions, pointer to function can be kept as a member. It is good when all needed information for the function is available from public interface.
  • tr1::function: It is like function pointers but more generic and can even point to function objects or member functoins. So clients can use any compatible calling entity.
  • The "classic" Strategy Pattern: To move virtual functions from 1 inheritance hierarchy to other.
prev | next

Cheers

No comments:

Post a Comment