Background
A method chain can put a function call on an object inside a statement. The core of the method chain pattern is the invocation of the previous object function, which returns the object of the next function call.
The builder pattern can be written as a method chain. The difference between a method chain and builder is that the builder has an intermediate object builder to stage the properties that need to be built.
There may be multithreading problems with the method chain.
Scene
Need ligatures.
Instance
final class rmbcurrency { private int yuan = 0; private int jiao = 0; private int fen = 0; public rmbcurrency setyuan (Int yuan) { this.yuan = yuan; return this; } public rmbcurrency setjiao (Int jiao) { this.jiao = jiao; return this; } public rmbcurrency setfen (Int fen) { this.fen = fen; return this; } @OverRide public string tostring () { return yuan + "." + jiao + "." + fen; }}
public class test{public static void Main (string[] args) {rmbcurrency currency = new Rmbcurrency (). Setyuan (1). s Etjiao (1). Setfen (1); System.out.print (currency); }}
[Coding mode] method chain