From: emitrax on 12 Apr 2010 06:59 Hi, I'm finding myself analyzing a fairly complex system log (library), where amazingly for me, many classes have lots, or even only, static methods! What strikes me the most, is that static methods are used even in base class, and classes that inherits from it have only static methods. Now, despite whether this is good design or not, I was trying to understand what all this static methods would imply. Is there a "Why using so many static methods is a bad idea" FAQ somewhere? Especially in a shared library? Thanks in advance. Regards, Salvatore -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Ulrich Eckhardt on 12 Apr 2010 18:59 emitrax wrote: > I'm finding myself analyzing a fairly complex system log (library), > where amazingly for me, many classes have lots, or even only, static > methods! Typical reason: Bad code quality. Some people seem to think "OOP is a must" so they put everything into a class, i.e. abuse classes as mere namespaces. > What strikes me the most, is that static methods are used even in > base class, and classes that inherits from it have only static > methods. Especially in combination with templates, you often have traits classes that have no state and only provide certain small aspects of a feature. For example, comparing and copying strings is encapsulated into std::char_traits<T>, which is in turn used by std::basic_string<T>. > Now, despite whether this is good design or not, I was trying to > understand what all this static methods would imply. Either it's a well-informed decision or one made out of ignorance. Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Mickey on 12 Apr 2010 18:52 On Apr 13, 2:59 am, emitrax <emit...(a)gmail.com> wrote: > > I'm finding myself analyzing a fairly complex system log (library), > where amazingly for me, many classes > have lots, or even only, static methods! What strikes me the most, is > that static methods are used > even in base class, and classes that inherits from it have only static > methods. > > Now, despite whether this is good design or not, I was trying to > understand what all this > static methods would imply. Is there a "Why using so many static > methods is a bad idea" FAQ > somewhere? Especially in a shared library? Why is there so many static methods in your class can only be answered by knowing the purpose of the library. There might be a reasonable justification for doing that. About inheriting from a class that provides only static methods and this class does not define any other member function... I cannot imagine any purpose that such a design can serve. A specific example will be helpful. - Jyoti http://acceptingall.wordpress.com/2010/02/20/as-many-faiths-that-many-ways/ -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Daniel T. on 13 Apr 2010 01:42 emitrax <emitrax(a)gmail.com> wrote: > I'm finding myself analyzing a fairly complex system log (library), > where amazingly for me, many classes have lots, or even only, static > methods! What strikes me the most, is that static methods are used > even in base class, and classes that inherits from it have only static > methods. > > Now, despite whether this is good design or not, I was trying to > understand what all this static methods would imply. Is there a "Why > using so many static methods is a bad idea" FAQ somewhere? Especially > in a shared library? What you describe is pretty standard practice for writing procedural code in Java. Think of classes with only static members as namespaces, and inheriting from them is much like "using namespace foo". My guess is that the original designer came from a Java background. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: emitrax on 13 Apr 2010 06:55 On 13 Apr, 11:59, Ulrich Eckhardt <eckha...(a)satorlaser.com> wrote: > emitrax wrote: > > I'm finding myself analyzing a fairly complex system log (library), > > where amazingly for me, many classes have lots, or even only, static > > methods! > > Typical reason: Bad code quality. Some people seem to think "OOP is a must" > so they put everything into a class, i.e. abuse classes as mere namespaces. > Yes, that's what my colleague and I were wondering. Why not using namespaces in the first place, if the library has to be used with the following syntax STATICCLASSNAME::STATICMETHOD::Method(bla,bla,bla); > > > Now, despite whether this is good design or not, I was trying to > > understand what all this static methods would imply. > > Either it's a well-informed decision or one made out of ignorance. > I hoped it was the first one, so that I could learn something new, but the more I dig into it, the more I think it is not. S. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
|
Next
|
Last
Pages: 1 2 3 4 5 6 Prev: Errors using shared_ptr<> and get_deleter in g++-4.1/4.3/4.4 Next: Iterating over a directory |