Loading ...
Sorry, an error occurred while loading the content.

Re: [XP] Constructors as verbs.

Expand Messages
  • Stacie Clark
    ... Oh, yuck. The first smell is the name. Classes with verb names are always immediately suspect, especially of you re looking at what was once C code. I ve
    Message 1 of 6 , Apr 27, 2001
    • 0 Attachment
      John Carter wrote:
      >
      > I'm looking at a patch of legacy C++ code which is doing something I have
      > never seen before. Using a constructor as a verb.
      Oh, yuck. The first smell is the name. Classes with verb names are
      always immediately suspect, especially of you're looking at what was
      once C code. I've just been compiling a paper on how to evaluate the
      quality of code. Since I'm at home, I have neither my books nor my paper
      but I'll take a shot at it.
      The class is created, does something quickly and then disappears. It
      makes no use of one the basic concepts of OO which is the retention of
      state. "AntiPatterns: Refactoring Software, Architectures, and Projects
      in Crisis" by Wilson et al calls this the Poltergeist Anti-Pattern and
      it is often seen in C legacy code. While not illegal, it hardly
      constitutes good OO design. In addition, the use of enums is
      discouraged in C++ and a const is a better choice (Scott Meyers,
      Effective C++). Does the value of the enum change the behavior of the
      constructor? Are there lots of conditionals? Then consider using
      polymorphism, and the enum goes away. Ask yourself: which objects create
      this class? Should this function be a responsibility of this other
      object instead of it's class? While I'm not a fan of classes full of
      statics, when dealing with ported legacy code, it's certainly an
      option.

      Stacie
    Your message has been successfully submitted and would be delivered to recipients shortly.