OOP, Generics and a little Humor

Published Mon, Jul 25 2005 19:15 | William

Well, I decided to show a few examples with a little humor.  I know a few of you thought my “Shocker” post was in poor taste, and I apologize if you did, but obviously many people liked it.  Anyway, I'm gonig to show a few examples of how to make a class better, and better and better, and use the Shocker as an example.  So at first, I'll implement it as lame as possible.  Then I'll build on it and quickly show how to make an infinitely better implementation.  Then, we'll actually add some smarts to it so we can make sure that only valid values can be set.  I'll be using Generics to help this process.


namespace DoubleI.TheShocker
{
#region Using Statements
   using System;
   using System.Collections.Generic;
   using System.Text;
#endregion
class Shocker
{
  private String _oneValue;
  private String _twoValue;
  public Shocker(String oneValue, String twoValue)
  {
     this.OneValue = OneValue;
     this.TwoValue = TwoValue;
  }
  public String OneValue
  {
    get { return _oneValue; }
    set { _oneValue = value; }
  }
  public String TwoValue
  {
    get { return _twoValue; }
    set { _twoValue = value; }
  }
  public override String ToString()
  {
      return String.Format("One in the {0}, Two in the {1}",
                            this.OneValue,
                            this.TwoValue);
  }
 }
}

Comments

# William said on July 25, 2005 9:23 PM:

DoubleI,

I can't stop laughing. I can already see that this set of posts will become one of your classics.

As you have already provided for Spanish parameters, here are a few Russian parameters that work for this class without worries of censorship from search engines or your blog provider. Pronunciations in parenthesis.

One of my nicknames in Russian is "????" (Yeh-boon').
OneValue would be set to "???????" (Pi-er'-deel-a').
TwoValue would be set to "????????" (Po'-soo-dee'-na).

??? ???? ? ??????-???? ????!!!

????? ????????!!!!

---O

p.s. It's funny, but babelfish.altavista.com has a difficult time translating these. I wonder why???

# William said on July 25, 2005 9:28 PM:

Uh-oh, it looks like your blog provider catches my "parameters" (or doesn't take cyrillic characters).

---O

# William said on July 26, 2005 3:35 PM:

Bill, let me take the position of the d!ckhead who points out code errors in demo code :P

I don't think your constructor will work properly - or I'm on drugs. From what I can see you aren't using the passed in parameter strings to populate the properties, your pointing the properties to themselves.

Now, if this was done on purpose and I'm looking like a idiot...well, then I'm an idiot, and will say "Carry on with your example and ignore the bonehead in the corner" ;)

And yeah, I agree with O, this looks like it's going to be great!

# William said on July 26, 2005 3:56 PM:

Skicow - Excellent point and yes, that's actually on purpose but It's for another reason. I'll have the explanation later tonight and BTW, you are always welcomed to critique code - we bitch about the same sort of aholes all the time so your cool credentials are written in stone.

# TrackBack said on July 30, 2005 9:28 PM:

# TrackBack said on August 5, 2005 8:21 PM:

So it has been a really good week.  I'm listening to Funkadelic (because as a blogger, I'm supposed...

Search

This Blog

Tags

Community

Archives

News

My other sites

Cool Stuff

Book Stuff

Security

ORM

Data Access

Funny Stuff

Compact Framework Stuff

Web Casts

My KnowledgeBase Articles

My MVP Profile

Design Patterns

Performance

Debugging

Remoting

My Fellow Authors

My Books

LINQ

Misc

Speech

Syndication

Email Notifications