Friday, November 16, 2007

If only the truth was a base class...

I was having a discussion with a friend of mine and, as fate would have it, we managed a brief stint over the theory of truth and lies...
"Lie" is such a strong word - to alleviate this burden some think it's better phrased as "extending the truth". Now if only there was some technical implementation of this.... hmmmm....

Fear not! I have done it. Here it is in all its glory...

The truth as a base class.

(in C#)

   1: public class ExtenedTruth : Truth
   2: {      
   3:     public override string TellTheTruth()      
   4:     {          
   5:         StringBuilder sb = new StringBuilder(base.TellTheTruth());          
   6:         sb.AppendLine(" and we extend over here... ");           
   7:         return sb.ToString();      
   8:     }
   9: }


Done! All this without any lies involved. What a pleasure... :D


P.S. please notice the use of the StringBuilder so that we can append loads onto the "truth" with as little of a performance hit as possible.
P.P.S. I am pretty sure this would compile on the Mono framework.
P.P.P.S I think I need to patent this.


No comments: