On Jun 22, 4:41 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2008-06-22 16:22, Marco wrote:
One of the things I like about C++ is that it doesn't force
you to create fake "objects" in the OO sense. We had a
debate at the office about the "right" way to encapsulate
related utility functions (such as additional math
functions). These would be pure functions with no state.
1) Create a class with all static functions
2) Use a named namespace
Please site articles or books if possible.
Ask your self this (or ask your collogues):
* If you will never instantiate it why use a class, or put another way:
how is it object-oriented to create a class but never create any
objects from it?
To close it? A class differs from a namespace in several ways.
One, of course, is that you can't instantiate a namespace.
Another is that you can't add names to a class. Yet a third is
that a class can have private members.
Obviously (I think), none of these issues apply to additional
math functions, and these should probably be in a namespace.
But there are probably cases where closure or private members
are an issue, in which case, a class should be used.
* If you create a class with static functions, what relation
does these functions have with the class (except that the
class provides a namespace for the functions)?
If the functions are private, they can only be called by other
members of the class.
Note that I'm just playing the devil's advocate here. Generally
speaking, the original question can be restated to ask "is it
appropriate to confuse the reader by pretending something is OO
when you're not?"
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34