Pseudocode

Report a typo

This pseudocode depicts the design pattern. Is it the factory method or prototype?

interface Shape is
  method draw()
  
class Square implements Shape is
  method draw() is
    print "Square"

class Circle implements Shape is
  method draw() is
    print "Circle"

class ShapesFactory is
  method shapeType(String shape) is
    if (shape == square) then
      return new Square()
    else if (shape == circle) then
      return new Circle()
    else
      print "Error"

class App is
  method drawShape()
    ShapesFactory shapeFactory = new ShapesFactory()

    shape1 = shapeFactory.shapeType(square)
    shape1.draw()

    shape2 = shapeFactory.shapeType(circle)
    shape2.draw()
Select one option from the list
___

Create a free account to access the full topic