The Bridge pattern splits a design into two hierarchies: an abstraction and an implementation. Here the implementation is the Renderer - the backend that actually turns a shape into output. We start with just circles.
Implement the two Renderer subclasses:
Build each result by concatenating the fixed prefix with str(radius) so any radius works. The Renderer base class just declares the method.
class Renderer:
def render_circle(self, radius):
raise NotImplementedError
class VectorRenderer(Renderer):
def render_circle(self, radius):
"""Return a vector description of a circle of the given radius."""
# TODO: return a string like 'vector circle r=5'
pass
class RasterRenderer(Renderer):
def render_circle(self, radius):
"""Return a raster description of a circle of the given radius."""
# TODO: return a string like 'raster pixels for circle r=5'
pass
The editor and the test runner need a wide screen. Open this page on a desktop browser and your progress will be waiting.
The Bridge pattern splits a design into two hierarchies: an abstraction and an implementation. Here the implementation is the Renderer - the backend that actually turns a shape into output. We start with just circles.
Implement the two Renderer subclasses:
Build each result by concatenating the fixed prefix with str(radius) so any radius works. The Renderer base class just declares the method.
Press Run Tests or ββ© to check your solution.