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

RE: [XP] Use Virtual Methods in C++ to Support Fakes?

Expand Messages
  • Hiller, Dean
    well, java was defininetly for it. Maybe you would be interested in porting mocklib... http://sourceforge.net/project/mocklib . It was nice in the java world
    Message 1 of 1 , Feb 1 5:21 AM
    • 0 Attachment
      well, java was defininetly for it. Maybe you would be interested in porting
      mocklib... http://sourceforge.net/project/mocklib . It was nice in the java
      world as you could force paths easily without writing all that code in the
      fake class. You just told the mockobject how to behave(ie. throw an
      exception, return a bad or good value) and you could verify parameters
      passed in as well.
      later

      -----Original Message-----
      From: kk_oop [mailto:kk_oop@...]
      Sent: Sunday, January 29, 2006 3:24 PM
      To: extremeprogramming@yahoogroups.com
      Subject: [XP] Use Virtual Methods in C++ to Support Fakes?


      Hi. I'm on a C++ project where we are using CppUnitLite to drive our
      test-driven development.

      We find that we are using quite a bit of derived "fake" classes. The
      idea there is that if we are testing class A and it contains an
      instance of class B, it is helpful to override class B methods to
      provide fake behavior. Such behavior could simply retain an
      indication that the method was called (which we can assert on later),
      or it could return some canned value to force A's method down a
      certain path.

      To facilitate the creation of "fakes," we thought it would be a good
      idea to make all of our class methods virtual. That way, we would be
      free to make fakes as needed without having to change the production
      code. Naturally, we can make exceptions to this rule case by case,
      but it seemed like it would be a good idea to make methods virtual by
      default.

      From a design perspective, it also seems that virtual methods better
      support the Open-Closed Principle (OCP), since we could always
      override existing behavior without touching the currently working
      production code.

      Any thoughts for or against making methods virtual by default for
      these reasons?

      Thanks!

      Ken








      To Post a message, send it to: extremeprogramming@...

      To Unsubscribe, send a blank message to:
      extremeprogramming-unsubscribe@...

      ad-free courtesy of objectmentor.com
      Yahoo! Groups Links








      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.