Click here to Skip to main content
16,000,950 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
More examples of non-member functions to 'glue' classes.
And the alternative approaches are?
Posted
Comments
Sandeep Mewara 17-Apr-11 13:58pm    
Incomplete?

1 solution

Alternative approach is: avoid non-member functions. Strictly speaking, you never need one (except application entry point, "main" :-). Each and every non-member function can be formally replaced with static function of a class. As to static functions, OOP usually reduces them and helps to keep them to minimum. At the same time, if a function does not use "this" (access to the instance), is should not be an instance function — make is static.

Also, gluing classes/instances together is not a problem at all. What so special about this? It's an integral part of general programming. Again, it never requires non-members.
Is what you mean a Singleton pattern? Yes, sometimes you need singletons, http://en.wikipedia.org/wiki/Singleton_pattern[^].

Start forgetting non-members. Get to OOP!

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900