Chip is correct about going from most generic to most specific in most cases. So let's jump into an example.
Let's take a can of soda and a bottle of bleach. If you mix them together and drink them you will probably not be around to read the rest of this - so don't do that.
But a bottle and a can have something in common - they both contain a liquid. So the first thing we do is define our container object.
public class LiquidContainer
{
//Here we will define some generic properties that explain what a container is. These properties apply to both a Can and a Bottle.
public int SizeInML = 0;
public string ContainerMaterial = "";
public string Contents = "";
public LiquidContainer()
{
}
}
So we can say that a bottle of bleach and a can of soda has a size in millilitres, is made of some kind of material, and can hold some kind of contents.
So lets look a little further into the Bleach bottle - which will inherit the Container class.
public class BleachBottle : LiquidContainer //inherits from LiquidContainer by putting the class name after the :
{
//Any other class accessing this class can already see SizeInML, ContainerMaterial, and Contents so we don't have to add them here. We only add properties that are specific to the bleach bottle.
public int AcidityLevel = 7; //Default set to Neutral
public BleachBottle()
{
}
}
Wow that was simple (I think). So how do we use this class?
public class Form1 : System.Windows.Forms.Form //inherits from the Form class
{
public Form1()
{
InitializeComponent();
}
private BleachBottle CreateBleachBottle()
{
BleachBottle jaavex = new BleachBottle();
//Set the properties defined in LiquidContainer
jaavex.SizeInML = 710;
jaavex.ContainerMaterial = "Plastic";
jaavex.Contents = "Jaavex Bleach";
//Set the properties specific to BleachBottle
jaavex.AcidityLevel = 9;
return jaavex;
}
private void button1_Click(object sender, EventArgs e)
{
//A message box saying Jaavex Bleach" will show up
MessageBox.Show(CreateBleachBottle().Contents);
}
}
So now let's look at the can.
public class SodaCan : LiquidContainer
{
//This class will also have a specific property - LabelColor
public Color LabelColor = Color.Silver;
public SodaCan()
{
}
//We will also add a specific method to the can
public void OpenCan()
{
MessageBox.Show("pssssssssht"); //that's the can opening....

}
}
So we can use this class.
public class Form1 : System.Windows.Forms.Form //inherits from the Form class
{
public Form1()
{
InitializeComponent();
}
private SodaCan CreateSoda()
{
SodaCan soda = new SodaCan();
soda.SizeInML = 355;
soda.ContainerMaterial = "Aluminum";
soda.Contents = "Dr. Pepperr";
soda.LabelColor = Color.DarkRed;
return soda;
}
private BleachBottle CreateBleachBottle()
{
BleachBottle jaavex = new BleachBottle();
//Set the properties defined in LiquidContainer
jaavex.SizeInML = 710;
jaavex.ContainerMaterial = "Plastic";
jaavex.Contents = "Jaavex Bleach";
//Set the properties specific to BleachBottle
jaavex.AcidityLevel = 9;
return jaavex;
}
private void button1_Click(object sender, EventArgs e)
{
//A message box saying Jaavex Bleach" will show up
MessageBox.Show(CreateBleachBottle().Contents);
}
private void button2_Click(object sender, EventArgs e)
{
//Open the can of soda
SodaCan soda = CreateSoda();
soda.OpenCan(); //use the method specific to SodaCan
}
}
You will notice above that the interface typically follows the : in the class declaration and so does a class type that we are inheriting from (often called a base class)
so how do we use an interface and a base class?
public class JuiceBox : LiquidContainer, IMyActionClass
{
public JuiceBox()
{
}
public void PerformAction()
{
MessageBox.Show("Squeeeeeeze and out comes the juice!");
}
}
So we can use this class by creating the JuiceBox as a container and runnind the action on it.
public void DoSomething()
{
JuiceBox juice = new JuiceBox();
juice.SizeInML = 160;
juice.ContainerMaterial = "Cardboard";
juice.Contents = "Fruit Punch";
StartActionSequence(juice);
//we can pass in the JuiceBox class because it implements the IMyActionClass interface.
}
public void StartActionSequence(IMyActionClass action)
{
//Even though we are passed in a juice box we cannot access the properties of LiquidContainer or of JuiceBox specifically because this method only knows the JuiceBox as a IMyActionClass which only contains the method PerformAction();
action.PeformAction();
}
I hope that makes some sense. If you have more questions let me know.