vendredi 21 juillet 2017

What is the name of the design pattern where you chain method results of the same object?

I've seen this design pattern and I can't remember the name:

class Number {
  private int myNumber;
  public Number(int arg) {this.myNumber = arg;}
  public Number add (int arg) {return new Number(myNumber + arg);}
  public Number subtract (int arg) {return new Number(myNumber - arg);}
}

So the way you use it is:

Object result = (new Number(1)).add(2).subtract(1).add(3);

The point being you can keep chaining the method results together.

My question is: What is the name of the design pattern where you chain method results of the same object?

Aucun commentaire:

Enregistrer un commentaire