程序员,四步教你写出简单易懂的代码!
网站建设 发布者:cya 2019-12-05 08:57 访问量:265
“四人帮”Gang of Four,指Erich Gamma、Richard Helm、Ralph Johnson以及John Vlissides四人。
接口Factory <T> { T build(Metadata d)} 类ClientFactory实现Factory <Client> { Client build(Metadata d){
//构建实际对象并返回
} }
接口Validator {
bool validate(Object o)} 类ValidatorHelper实现Validator { Set <Validator>委托;
bool validate(Object o){
for(Validator v:委托){
如果(!v.validate(o))返回false
}
返回true
} } 类RestController { ValidationHelper helper; 响应addObject(Object o){
如果(helper.validate(o))返回ErrorResponse //正常处理
} }
类Dto { 字符串s
int我私有Dto(String s,int i){
this.s = s
this.i = i
} public DtoBuilder builder(){
return new DtoBuilder()
} 公共静态类DtoBuilder {
private String s =“一些字符串“
private int i = 0 public DtoBuilder withString(String s){
this.s = s
return this
} public DtoBuilder withInt(int it){
this.i =我
返回此
} public Dto build(){
返回新的Dto( s,i)
}
} }
接口Enricher <T> { T rich(T something); } 类HeadersEnricher实现Enricher <Headers> {
标头
rich(Headers标头){ headers.add(“ x-header”,“某物”)
返回标头
} }
文章连接: https://chenzhankj.com/wzjss/633.html
版权声明:文章由 晨展科技 整理收集,来源于互联网或者用户投稿,如有侵权,请联系我们,我们会立即删除。如转载请保留