Here is how I would refactor it:
Explainations:
Enum for Colors:
We define an enum called Color, which contains two values: Red and Blue. This enum is used to represent the color of the shapes.
Abstract Product (Shape):
We have an abstract class named Shape, which serves as a blueprint for different types of shapes. It declares an abstract method Draw() which will be implemented by concrete shape classes.
Concrete Products (Circle and Rectangle):
We define two concrete shape classes: Circle and Rectangle, both inheriting from the Shape abstract class.
Each shape class has a constructor that takes a Color parameter, allowing us to specify the color of the shape.
These classes implement the Draw() method, providing the functionality to draw the respective shape with its specified color.
Abstract Factory Interface (IShapeFactory):
We declare an interface IShapeFactory which defines methods for creating different types of shapes (CreateCircle() and CreateRectangle()).
These factory methods take a Color parameter, indicating the color of the shape to be created.
Concrete Factory (ShapeFactory):
We implement the IShapeFactory interface with a concrete factory class named ShapeFactory.
The ShapeFactory class provides implementations for creating circles and rectangles with the specified color.
Client Code (Client):
The Client class contains the Main method, which serves as the entry point of the program.
Inside the Main method, we create an instance of the ShapeFactory.
We then demonstrate how to use the factory to create and draw shapes of different colors (Red and Blue) by calling the DrawShapes method.
The DrawShapes method accepts a factory object and a color parameter. It uses the factory to create shapes of the specified color and then calls the Draw() method on each shape to draw it.