OOP, Generics and a little Humor
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);
}
}
}