728x90
반응형
Builder 패턴 - config 설정할 때 종종 쓰임.
package builder;
import java.util.HashMap;
public class BuilderPatternExample
{
public static void main(String [] args)
{
Builder builder = $for("constructor")
.with("configuration")
.withAttribute("key", "value");
}
public static Builder $for(String configuration)
{
return new Builder();
}
public static class Builder
{
String configuration;
HashMap attributes = new HashMap();
public Builder with(String configuration)
{
this.configuration = configuration;
return this;
}
public Builder withAttribute(String key, Object value)
{
attributes.put(key, value);
return this;
}
}
}
'Java' 카테고리의 다른 글
CheckedException vs UnCheckedException (0) | 2020.08.08 |
---|---|
자바 ofNullable, ofElse, ofElseGet (0) | 2020.08.04 |
자바 object 속성 값들을 string 으로 붙여넣기. (reflect) (0) | 2020.07.23 |
MBean Client, Server Example (0) | 2018.07.31 |
Java checked exception vs unchecked exception (0) | 2017.11.24 |
댓글