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
相关阅读
Latest Java 7 update 11 not working in Chrome/Firefox forprogramming那帮人好好玩啊Why Java did not include Tree or Graph into its Collecionts Framwork?US-CERT warns users to disable Java in web browsers, Appleservlet是否可以在doGet里面返回304新手求project 机会(免费劳动力)offer选择求建议 (转载)aspx网页现在到底流行不?java网站写好,如何提速? (转载)有没有好的Hibernate教程?你们一般把transaction放在哪一层?JDK8要出来了?JetBrain75%off,还剩17小时.准备把整个team都给升级了.怎么可以练习多线程编程呢?是病毒吗(看本文没事)?how to host a simple blog? (转载)anyone using play framework (from Typesafe)?SSH lib for Java最近玩linkedin,觉得那些花花绿绿的公司logo很好看PHP真火啊Fatal Error怎么回事?