Expand description

The Decorator design pattern example module

The Decorator pattern is used when an object at run time needs to have its behavior altered. This is supported by providing wrappers around the object called decorators. Those wrappers take instances of the IRenderElement trait. All elements look the same and can therefore recursively wrap other decorators. The base element never wraps anything and decorators must ultimately wrap a non-decorator class to be of any use.

Accessed through the decorator_exercise() function.

Modules

  • Contains the IRenderElement trait that represents decorator and text elements.
  • Contains the RedForegroundDecorator struct representing a decorator that renders an element with red foreground (text) color.
  • Contains the TextElement struct representing a string that can be decorated.
  • Contains the UnderlineDecorator struct representing a decorator that renders an element as underlined text.
  • Contains the WhiteBackgroundDecorator struct representing a decorator that renders an element on a white background.

Functions