Effective C++ Ed. 3rd: Item 23. Prefer non-member non-friend functions to member functions

Reasons to prefer non-member non-friend functions to member functions: 
  1. Encapsulation: More functions present in a class, lesser is the encapsulation.
  2. Modularity: Functionality of a class in terms of non-member functions or convenience functions can be defined in different header files in the same namespace. This will enable us to include only required functionality along with the class. For example: Functionality of standard library in namespace std is partitioned into many header files viz. vector, iostream, list etc. 
  3. Extensibility: Writing convenience function as mentioned in above point lets other users extend the functionality. This can be done by defining more code in a new header file with the same namespace.
    prev | next
    Cheers and try hosting at Linode.

    No comments:

    Post a Comment