private void btnCalculateArea_Click(object sender, EventArgs e) { IShapeArea shape = null; if (radioCircle.Checked) { double radius = double.Parse(textBoxRadius.Text); shape = new Circle(radius); } else if (radioTriangle.Checked) { double tBase = double.Parse(textBoxBase.Text); double tHeight = double.Parse(textBoxHeight.Text); shape = new Triangle(tBase, tHeight); } if (shape != null) { Calculate(shape); } else { MessageBox.Show("no shape found..."); } }
private void Calculate(IShapeArea shape) { Type typeOfShape = shape.GetType(); double area = shape.CalculateArea(); MessageBox.Show($"Area of {typeOfShape} is {area}"); }
public AnyShape(IShapeArea shape) { _shape = shape; }