Possible Duplicate:
Namespace + functions versus static methods on a class
Where is the most sensible way to write, for example, a function that would look like
Point intersection(const Line &L1, const Line &L2);
(assuming I have written classes Point
and Line
)?
Maybe I can make the question a little more precise: I am considering the following options:
- Write a global function (declare it in line.h, write it in line.cpp)
- Write a static method of the class
Line
- Use a namespace.
- Write instead a function
Point Line::intersection(const Line & otherLine);
I'm not a fan of the last option because I don't want my function to be "asymmetric" (I have several other examples of functions like this in my code). For the moment they are global functions (as in option 1.), but I'm given to understand this is not "good practice". As for static methods and namespaces, I am not acquainted to these yet, so I'm not sure.
What do you think is the "best" design?
Thanks for your insights!
Edit: To give you an idea of the size of my project : 50 to 100 classes.