Class with all static members --> Is namespace() the right choice?

Q

qazmlp

I just noticed the following class design in a module.
class testClass
{
public:
static long utilFunc1() ;
static long utilFunc2() ;
static long utilFunc3() ;
private:
testClass(){};
~testClass(){};

static someClass1* someObj1Ptr ;
static someClass2* someObj2Ptr ;
static someClass3* someObj3Ptr ;
};

The class design looks ugly for me. The implementation also gives the
feeling that, this class is just a placeholder for the utility
functions.
In that case, could I suggest to use namespace instead of a class?
The only reason why I hesitate to suggest that is, the class also
contains some
members. Can still the namespace be the correct choice here?

Kindly clarify!
 
A

Alf P. Steinbach

* qazmlp:
I just noticed the following class design in a module.
class testClass
{
public:
static long utilFunc1() ;
static long utilFunc2() ;
static long utilFunc3() ;
private:
testClass(){};
~testClass(){};

static someClass1* someObj1Ptr ;
static someClass2* someObj2Ptr ;
static someClass3* someObj3Ptr ;
};

The class design looks ugly for me. The implementation also gives the
feeling that, this class is just a placeholder for the utility
functions.
In that case, could I suggest to use namespace instead of a class?
The only reason why I hesitate to suggest that is, the class also
contains some
members. Can still the namespace be the correct choice here?

Kindly clarify!

It seems the class could reasonably be split into two classes, one
with the non-static members and one with the static utility functions.

A class with only static members _can_ be useful e.g. as a template
argument.

But from what you write that seems unlikely.

The alternatives are (1) placing those functions at namespace
scope, or (2) using a singleton, or (3) re-design, who knows
what might pop out?

There is not enough information to recommend any specific design.
 
A

Andrey Tarasevich

qazmlp said:
I just noticed the following class design in a module.
class testClass
{
public:
static long utilFunc1() ;
static long utilFunc2() ;
static long utilFunc3() ;
private:
testClass(){};
~testClass(){};

static someClass1* someObj1Ptr ;
static someClass2* someObj2Ptr ;
static someClass3* someObj3Ptr ;
};

The class design looks ugly for me. The implementation also gives the
feeling that, this class is just a placeholder for the utility
functions.
In that case, could I suggest to use namespace instead of a class?
The only reason why I hesitate to suggest that is, the class also
contains some
members. Can still the namespace be the correct choice here?
...

A major reason to use class instead of namespace in this case is that
class can be used as template argument (namespace cannot).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top