Computer scienceFundamentalsEssentialsSoftware constructionDesign patternsStructural design patterns

Flyweight pattern

Pseudocode example

Report a typo

Here's a pseudocode example of a flyweight pattern. Try to match classes with their types.

class Shape is
  float size
  String line

  constructor of Shape(size, line) is ...



class Creator is
  List(Shape) shapes;

  method getShape(size, line) is
    shape = shapes.contains(size, line)
    if(shape == null)
       shape = new Shape(size, line)
       shapes.add(shape)
    return shape



class Circle is
  String circle
  Shape circleShape

  constructor of Circle(round, circleShape) is ...
Match the items from left and right columns
Shape
Circle
Creator
Contextual object
Flyweight
Flyweight factory
___

Create a free account to access the full topic