类 ShapeFactory

java.lang.Object
com.example.graphics.factory.ShapeFactory

public class ShapeFactory extends Object
Factory class for creating different types of shapes. This is an implementation of the Factory Method pattern.
  • 构造器详细资料

    • ShapeFactory

      public ShapeFactory()
  • 方法详细资料

    • createCircle

      public Shape createCircle(int x, int y, int radius)
      Create a circle with the specified parameters
      参数:
      x - the x coordinate of the center
      y - the y coordinate of the center
      radius - the radius of the circle
      返回:
      a new Circle object
    • createRectangle

      public Shape createRectangle(int x, int y, int width, int height)
      Create a rectangle with the specified parameters
      参数:
      x - the x coordinate of the top-left corner
      y - the y coordinate of the top-left corner
      width - the width of the rectangle
      height - the height of the rectangle
      返回:
      a new Rectangle object
    • createLine

      public Shape createLine(int x1, int y1, int x2, int y2)
      Create a line with the specified endpoints
      参数:
      x1 - the x coordinate of the first endpoint
      y1 - the y coordinate of the first endpoint
      x2 - the x coordinate of the second endpoint
      y2 - the y coordinate of the second endpoint
      返回:
      a new Line object
    • createTriangle

      public Shape createTriangle(int x1, int y1, int x2, int y2, int x3, int y3)
      Create a triangle with the specified vertices
      参数:
      x1 - the x coordinate of the first vertex
      y1 - the y coordinate of the first vertex
      x2 - the x coordinate of the second vertex
      y2 - the y coordinate of the second vertex
      x3 - the x coordinate of the third vertex
      y3 - the y coordinate of the third vertex
      返回:
      a new Triangle object