m*k
2 楼
我们team有一senior programmer写了如同以下
的程序(我简化了非实质内容),他说是用了builder pattern,
我实在不明白这有何好处,各位以为呢?
just becoz we care about "final" then we create a builder which is almost a
duplicate of the original class?
public class Product
{
private final String m_a;
private final String m_b;
private final String m_c;
....
private final String m_z
protected Product(Builder builder)
{
super();
m_a = builder.m_a;
m_b = builder.m_b;
m_c = builder.m_c;
的程序(我简化了非实质内容),他说是用了builder pattern,
我实在不明白这有何好处,各位以为呢?
just becoz we care about "final" then we create a builder which is almost a
duplicate of the original class?
public class Product
{
private final String m_a;
private final String m_b;
private final String m_c;
....
private final String m_z
protected Product(Builder builder)
{
super();
m_a = builder.m_a;
m_b = builder.m_b;
m_c = builder.m_c;
i*e
3 楼
主角出场, 在我们家的众南瓜们是最小的,调皮,上房子了。
h*0
4 楼
我觉得更好看的模式是直接:
Product p = Builder.build(a,b,c,d...);
a
【在 m*****k 的大作中提到】
: 我们team有一senior programmer写了如同以下
: 的程序(我简化了非实质内容),他说是用了builder pattern,
: 我实在不明白这有何好处,各位以为呢?
: just becoz we care about "final" then we create a builder which is almost a
: duplicate of the original class?
: public class Product
: {
: private final String m_a;
: private final String m_b;
: private final String m_c;
Product p = Builder.build(a,b,c,d...);
a
【在 m*****k 的大作中提到】
: 我们team有一senior programmer写了如同以下
: 的程序(我简化了非实质内容),他说是用了builder pattern,
: 我实在不明白这有何好处,各位以为呢?
: just becoz we care about "final" then we create a builder which is almost a
: duplicate of the original class?
: public class Product
: {
: private final String m_a;
: private final String m_b;
: private final String m_c;
g*g
6 楼
Builder pattern is useless until you have 2 builders
to begin with.
a
【在 m*****k 的大作中提到】
: 我们team有一senior programmer写了如同以下
: 的程序(我简化了非实质内容),他说是用了builder pattern,
: 我实在不明白这有何好处,各位以为呢?
: just becoz we care about "final" then we create a builder which is almost a
: duplicate of the original class?
: public class Product
: {
: private final String m_a;
: private final String m_b;
: private final String m_c;
to begin with.
a
【在 m*****k 的大作中提到】
: 我们team有一senior programmer写了如同以下
: 的程序(我简化了非实质内容),他说是用了builder pattern,
: 我实在不明白这有何好处,各位以为呢?
: just becoz we care about "final" then we create a builder which is almost a
: duplicate of the original class?
: public class Product
: {
: private final String m_a;
: private final String m_b;
: private final String m_c;
m*t
8 楼
The idea behind the builder pattern is
to achieve a more fluid API. It would
make more sense if, e.g., a
Product instance requires a complex
sequence of API calls before it can be
used.
A side note - I'm not sure about
the Product constructor that takes
a Builder instance. I wouldn't have
Product depend on Builder, just like
I wouldn't have any core business object
depend on a helper class.
almost a
【在 m*****k 的大作中提到】
: 我们team有一senior programmer写了如同以下
: 的程序(我简化了非实质内容),他说是用了builder pattern,
: 我实在不明白这有何好处,各位以为呢?
: just becoz we care about "final" then we create a builder which is almost a
: duplicate of the original class?
: public class Product
: {
: private final String m_a;
: private final String m_b;
: private final String m_c;
to achieve a more fluid API. It would
make more sense if, e.g., a
Product instance requires a complex
sequence of API calls before it can be
used.
A side note - I'm not sure about
the Product constructor that takes
a Builder instance. I wouldn't have
Product depend on Builder, just like
I wouldn't have any core business object
depend on a helper class.
almost a
【在 m*****k 的大作中提到】
: 我们team有一senior programmer写了如同以下
: 的程序(我简化了非实质内容),他说是用了builder pattern,
: 我实在不明白这有何好处,各位以为呢?
: just becoz we care about "final" then we create a builder which is almost a
: duplicate of the original class?
: public class Product
: {
: private final String m_a;
: private final String m_b;
: private final String m_c;
b*y
9 楼
看见莲蓬了!
b*y
10 楼
lz帖子里面的这个用法好像是照搬Joshua Bloch那本书里面的
【在 m******t 的大作中提到】
: The idea behind the builder pattern is
: to achieve a more fluid API. It would
: make more sense if, e.g., a
: Product instance requires a complex
: sequence of API calls before it can be
: used.
: A side note - I'm not sure about
: the Product constructor that takes
: a Builder instance. I wouldn't have
: Product depend on Builder, just like
【在 m******t 的大作中提到】
: The idea behind the builder pattern is
: to achieve a more fluid API. It would
: make more sense if, e.g., a
: Product instance requires a complex
: sequence of API calls before it can be
: used.
: A side note - I'm not sure about
: the Product constructor that takes
: a Builder instance. I wouldn't have
: Product depend on Builder, just like
i*e
11 楼
莲子为啥个个都是空的, 郁闷了。。。就吃到一个,靠
m*k
12 楼
oh, after seeing you mention joshua, I google out this:
http://rwhansen.blogspot.com/2007/07/theres-builder-pattern-that-joshua.html
http://rwhansen.blogspot.com/2007/07/theres-builder-pattern-that-joshua.html
l*i
14 楼
和这个'pattern'贴些边的是fluent interface http://martinfowler.com/bliki/FluentInterface.html,属于internal domain-specific language。
builder的本质上是把对象一点点'捏'出来
例如:
htmlBuilder.beginParagraph();
htmlBuilder.text("Hey you, refactor to patterns only!");
htmlBuilder.endParagraph();
htmlBuilder.newLine();
Html testimony = htmlBuilder.getHtml();
a
【在 m*****k 的大作中提到】
: 我们team有一senior programmer写了如同以下
: 的程序(我简化了非实质内容),他说是用了builder pattern,
: 我实在不明白这有何好处,各位以为呢?
: just becoz we care about "final" then we create a builder which is almost a
: duplicate of the original class?
: public class Product
: {
: private final String m_a;
: private final String m_b;
: private final String m_c;
builder的本质上是把对象一点点'捏'出来
例如:
htmlBuilder.beginParagraph();
htmlBuilder.text("Hey you, refactor to patterns only!");
htmlBuilder.endParagraph();
htmlBuilder.newLine();
Html testimony = htmlBuilder.getHtml();
a
【在 m*****k 的大作中提到】
: 我们team有一senior programmer写了如同以下
: 的程序(我简化了非实质内容),他说是用了builder pattern,
: 我实在不明白这有何好处,各位以为呢?
: just becoz we care about "final" then we create a builder which is almost a
: duplicate of the original class?
: public class Product
: {
: private final String m_a;
: private final String m_b;
: private final String m_c;
s*e
16 楼
For me, it seems an example of overuse.
Builder pattern is one of 5 creational gof pattern. It will provide you
flexibility to build class based on the components. For me you would like to
choose this pattern if
1. the components can be coming in different fllavors
2. the components share the same interface.
For example, if you want to build a house, you have many kinds of windows to
choose, all these windows share the same interface, but they loos different
, so you can call house.buildWindow(e
Builder pattern is one of 5 creational gof pattern. It will provide you
flexibility to build class based on the components. For me you would like to
choose this pattern if
1. the components can be coming in different fllavors
2. the components share the same interface.
For example, if you want to build a house, you have many kinds of windows to
choose, all these windows share the same interface, but they loos different
, so you can call house.buildWindow(e
相关阅读
怎么做Status Bar?有多少人对annotation这个东西不满,请举手!!换个斑竹吧这里有人去OOPSLA么?String[] a = c.toArray(new String[0])soap questions, continuesJava Regular Expression Question怎么能学成J2EE的全能Can you show me ur Log4J config file?问个Spring的问题。Plan to learn Java, need some help!eclipse有没有update变量名称的功能?Can someone say say advantage of IDEA?Ejb 3.0 deployment descriptor?也问个SOAP相关问题怎么返回一个变量的地址?why people use Junit?SYSDEO tomcat的问题。Amazon is hiring experieced java developerany good java tool for txt->xml conversion?