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

Discussion in 'C++' started by qazmlp, Jul 7, 2004.

  1. qazmlp

    qazmlp Guest

    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!
     
    qazmlp, Jul 7, 2004
    #1
    1. Advertising

  2. * 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: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Jul 7, 2004
    #2
    1. Advertising

  3. qazmlp wrote:
    > 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).

    --
    Best regards,
    Andrey Tarasevich
     
    Andrey Tarasevich, Jul 7, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mickey Segal
    Replies:
    0
    Views:
    899
    Mickey Segal
    Feb 2, 2004
  2. SaravanaKumar
    Replies:
    6
    Views:
    9,412
    Tony Morris
    Oct 19, 2004
  3. JFCM
    Replies:
    4
    Views:
    5,742
  4. CoolPint
    Replies:
    8
    Views:
    989
    Jeff Schwab
    Dec 14, 2003
  5. Hicham Mouline
    Replies:
    5
    Views:
    2,380
    James Kanze
    Dec 19, 2008
Loading...

Share This Page