I have this code , i wanted to modify it using SOLID principles where all can i edit it please suggest
- class Program
- {
- static void Main(string[] args)
- {
- List<Figure> figureList = new List<Figure>();
- Figure rectangle = new Figure()
- {
- Height = 3,
- Width = 4,
- Type = ShapeType.Rectangle
- };
- figureList.Add(rectangle);
- Figure square = new Figure()
- {
- Height = 4,
- Type = ShapeType.Square
- };
- figureList.Add(square);
- Figure circle = new Figure()
- {
- Radius = 3.5,
- Type = ShapeType.Circle
- };
- figureList.Add(circle);
- foreach (Figure figure in figureList)
- {
- Console.WriteLine(figure.CalculateArea());
- figure.Save();
- }
- }
- }
- public class Figure
- {
- public double Height { get; set; }
- public double Width { get; set; }
- public double Radius { get; set; }
- public ShapeType Type { get; set; }
- public void Save()
- {
- if (Type == ShapeType.Circle)
- throw new Exception("Circle cannot be saved!");
-
- using (Stream stream = File.Open("saveFile.bin", FileMode.OpenOrCreate))
- {
- BinaryFormatter formatter = new BinaryFormatter();
- formatter.Serialize(stream, this);
- }
- }
- public double CalculateArea()
- {
- try
- {
- if (Type == ShapeType.Rectangle)
- {
- return Height * Width;
- }
- else if (Type == ShapeType.Square)
- {
- return Height * Height;
- }
- else if (Type == ShapeType.Circle)
- {
- return Radius * Radius * Math.PI;
- }
- }
- catch (Exception e)
- {
- if (e is ArgumentNullException)
- {
-
- System.IO.File.WriteAllText("log.txt", e.ToString());
- }
- else if (e is ArgumentException)
- {
-
- Console.WriteLine(e.ToString());
- }
- }
- return 0;
- }
- }
- public enum ShapeType
- {
- Rectangle,
- Circle,
- Square
- }