which pattern would you use to create a complex object and have the assembly and parts independent?
A: Prototype
B: Singleton
C: Builder
D: Abstract Factory
选哪个
...全文
3711打赏收藏
火急:高手快来。。。。。
which pattern would you use to create a complex object and have the assembly and parts independent? A: Prototype B: Singleton C: Builder D: Abstract Factory 选哪个
The Builder Pattern is a software design pattern. The intention is to abstract steps of construction of objects so that different implementations of these steps can construct different representations of objects.
Often, the Builder Pattern is used to build Products in accordance to the Composite pattern, a structure pattern.
[/Quote]
呵呵,语言真的是一个限制,不过希望楼主可以看懂
public interface Builder {
public Part getPart();
public wholeObject getWholeObject();
}
----------------------------------------------------------
the first level class that decide which builder to use!
----------------------------------------------------------
public class Designer {
public void build(Builder builder) {
builder.getPart();
builder.getWholeObject();
}
}
-------------------------------------------
now you will implements Builder
--------------------------------------------
public class BuilderImpl implements Builder {
public Part getPart(){}; //parts independent
public wholeObject getWholeObject(){}; // have the assembly
}
--------------------------
client call that!!
--------------------------
public class Client {
public static void main(String[] args) {
Builder builderImpl = new BuilderImpl ();
Designer designer = new Designer();
designer.build(builderImpl); //maybe different Builder
builderImpl.getPart();
builderImpl.getWholeObject(;
}
}
The Builder Pattern is a software design pattern. The intention is to abstract steps of construction of objects so that different implementations of these steps can construct different representations of objects.
Often, the Builder Pattern is used to build Products in accordance to the Composite pattern, a structure pattern.