Class StringDecorator<T>

java.lang.Object
com.csse3200.game.utils.StringDecorator<T>
Type Parameters:
T - Class to decorate

public class StringDecorator<T> extends Object
Apply a custom toString() for a class without overriding the class, using a decorator.
  • Constructor Details

    • StringDecorator

      public StringDecorator(T object, Function<T,String> printFn)
      Create a string-decorated object.
      Parameters:
      object - Object to decorate.
      printFn - Function which takes the object and returns the desired string representation.
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getObject

      public T getObject()
      Get the object.
      Returns:
      the object
    • getPrintFn

      public Function<T,String> getPrintFn()
      Get the print function.
      Returns:
      the print function