You use abstract classes when you want to leave some functionality to be implemented by the derived classes. For an example, consider the following code,
abstract class DrawingHelper
{
void LoadModel(string fileName)
{
...
...
}
void SaveToFile(string fileName)
{
...
...
}
abstract public void Draw(int x, int y, int z);
}
class OpenGLDrawingHelper : DrawingHelper
{
public override void Draw(int x, int y, int z)
{
...
...
}
}
class DirectXDrawingHelper : DrawingHelper
{
public override void Draw(int x, int y, int z)
{
...
...
}
}
Thus the method "Draw" differs according to the drawing API. Consider the following code,
DrawingHelper dHelper;
if(choice == APIChoice.OpenGL)
{
dHelper = new OpenGLDrawingHelper();
}
else if(choice == APIChoice.DirectX)
{
dHelper = new DirectXDrawingHelper();
}
dHelper.LoadModel("D:\\car.b3d");
dHelper.Draw(100, 200, 300);
The main difference between an abstract and a virtual method is you can't implement an abstract method in the base class. But you can implement a virtual function in the base class.