客户端类:
1.初始化一个公共的构造方法
2.builder 方法返回一个构建者
public class RestClient {
private String mUrl;
private String mMehtod;
private int mTimeout;
public RestClient(String url, String mehtod, int timeout) {
mUrl = url;
mMehtod = mehtod;
mTimeout = timeout;
}
public static RestClientBuilder builder(){
return new RestClientBuilder();
}
}
构建者类:
1.受保护的构造方法,其他类不能调用
2.build 方法返回 一个新的 客户端实例
public class RestClientBuilder {
private String mUrl;
private String mMehtod;
private int mTimeout;
RestClientBuilder(){
}
public RestClientBuilder setUrl(String url){
this.mUrl = url;
return this;
}
public RestClientBuilder setMethod(String mehtod){
this.mMehtod = mehtod;
return this;
}
public RestClientBuilder setTimeout(int timeout){
this.mTimeout = timeout;
return this;
}
public RestClient build(){
return new RestClient(mUrl, mMehtod, mTimeout);
}
}