在java中它是可能的建設者setter方法返回建設者本身,這樣的調用可以鏈接,就像這樣:C++能做這個java builder模式嗎?
public class builder{
private String name;
private int age;
private char glyph;
public builder setName(String name){
this.name = name;
return this;
}
public builder setAge(int age){
this.age = age;
return this;
}
public builder setGlyph(char glyph){
this.glyph = glyph;
return this;
}
public static void main(String[] args){
builder b = new builder().setName("").setAge(10).setGlyph('%');
}
}
在C是這可能++?
你可以用與這些3個參數,一個constuctor – duffy356 2013-03-13 09:53:29
你'setGlyph'方法'builder'作爲其聲明的返回類型,但不返回。這是內涵嗎? – mbatchkarov 2013-03-13 09:55:08
如果在Java中可能,它必須在C++中可能。在彙編程序中它也必須是可能的:-)! – sk2212 2013-03-13 09:55:30