I first came into contact with the concept of reading from <model-engineering implementation and expansion>, in addition to the http://martinfowler.com/bliki/FluentInterface.html written by Martin Fowler
Fluent interface instance
Java country
package com.jue.fluentinterface;public class Country {private String name;private int code;private boolean isDevelopedCountry;private int area;Country addName(String name) {this.name = name;return this;}Country addCountyCode(int code) {this.code = code;return this;}Country setDeveloped(boolean isdeveloped) {this.isDevelopedCountry = isdeveloped;return this;}Country setAread(int area) {this.area = area;return this;}}
Call class
/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubCountry china = new Country();china.addName("The People's Republic of China").addCountyCode(1001).setDeveloped(false).setAread(960);}
Main features:
The country method returns its own country, so that the caller can continue to call the country method.
Advantages
1. Sometimes we need to define different constructors based on the number of input parameters. With fluentinterface, You can freely transmit the desired data and maintain their consistency.
Java applications
Stringbuffer append Method