class Color
attr_reader :hex
def initialize(hex)
@hex = hex
end
end
class Canvas
def draw(x:, y:, color:)
# Draw color on provided coordinates
end
end
canvas = Canvas.new
1000.times do |x|
1000.times do |y|
canvas.draw(x: x, y: y, color: Color.new('#000000'))
end
end
class ColorFactory
attr_reader :colors
def initialize
@colors = {}
end
def find_color(hex)
if colors.has_key?(hex)
color = colors[hex]
else
color = Color.new(hex)
colors[hex] = color
end
color
end
end
class Canvas
attr_reader :color_factory
def initialize
@color_factory = ColorFactory.new
end
def draw(x:, y:, color:)
color = color_factory.find_color(color)
# Draw color on provided coordinates
end
end
canvas = Canvas.new
1000.times do |x|
1000.times do |y|
canvas.draw(x: x, y: y, color: '#000000')
end
end