Fluent interface-perception

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.