Shapes that can be saved to a database I have been asked to refactor the below code using SOLID principles and I was just wondering how you would go about it. I am not really sure if I am winning or not.

Could you have a stab at it and let me see what you come up with?

public class Box
    {
        private BoxType _boxType;

        public double Width { get; set; }
        public double Height { get; set; }
        public double Radius { get; set; }

        public BoxType BoxType
        {
            get { return _boxType; } 
            set { _boxType = value; }
        }

        public void Add()
        {
            using (var con = new SqlConnection())
            {
                SqlCommand cmd;

                if (_boxType == BoxType.Circle)
                {
                    cmd = new SqlCommand(string.Format("insert into [Table] values({0}, {1})", _boxType, Radius), con);
                }
                else
                {
                    cmd = new SqlCommand(string.Format("insert into [Table] values({0}, {1}, {2})", _boxType, Width, Height), con);
                }

                cmd.ExecuteNonQuery();
            }
        }

        public double CalculateArea()
        {
            if (_boxType == BoxType.Rectangle)
            {
                return Width * Height;
            }
            else if (_boxType == BoxType.Square)
            {
                return Width * Height; 
            }
            else if (_boxType == BoxType.Circle)
            {
                return Radius * Math.PI;
            }
            else
            {
                return 0;
            }
        }
    }     

    public enum BoxType
    {
        Unknown,
        Square,
        Rectangle,
        Circle
    }
Note: I don't claim to be an expert in SOLID principles, I do understand abstraction a bit though. 

Back to SOLID, CalculateArea violates the Open/Closed principle (The most frustrating concept to me). That is, when you add a shape  you have to go and modify the code by adding an if-statement, this can easily solved by using interfaces,

 interface IShape{
    double CalculateArea();
 } 

 class Rectangle : IShape{
    double CalculateArea(){
       return Width * Height;
    }
 } 


And so on for different shapes, so there is no need for if-statements. Btw: how come you representing a circle in a class called Box??

Single responsibility principle is being violated as well, where your class represents a Box Object and persists it to a database, these are two different responsibilities. You should rather have Data Access Layer to deal with a very HIGH dependency like a database.  

In regards to SQL generation you can abstract those as well using interfaces, and that is, given a shape get its sql code.

  interface ISQLShapeTemplates{
      DbCommand InsertionCode(IShape shape);
      DbCommand SelectCommand(IShape shape); 
  }


I used DbCommand and not SqlCommand because it's more abstract .