這裏是我Builder界面:生成器設計模式:訪問/模型數據傳遞到/混凝土類
public interface IContainerBuilder {
void SetSections();
void SetSides();
void SetArea();
WebControl GetContainer();
}
這是我ConcreteBuilder:
public class SingleContainerBuilder:BaseProperties, IContainerBuilder {
Panel panel = new Panel();
public void SetSections() {
//panel.Height = value coming from model
//panel.Width = value coming from model
}
public void SetSides() {
//panel.someproperty = //value coming from model,
//panel.someotherproperty = //value coming from model,
}
public void SetArea() {
throw new NotImplementedException();
}
public System.Web.UI.WebControls.WebControl GetContainer() {
return panel;
}
}
和導演是在這裏:
public class ContainerBuilder {
private readonly IContainerBuilder objBuilder;
public Builder(IContainerBuilder conBuilder) {
objBuilder = conBuilder;
}
public void BuildContainer() {
objBuilder.SetArea();
objBuilder.SetSections();
objBuilder.SetSides();
}
public WebControl GetContainer() {
return this.objBuilder.GetContainer();
}
}
這就是我如何從默認的頁面調用它:
var conBuilder = new ContainerBuilder(new SingleContainerBuilder());
conBuilder.BuildContainer();
var container = conBuilder.GetContainer();
現在我遇到的問題/困惑是如何傳遞的模型數據的具體類?我困惑/卡住的原因是可能有多個不同的容器(可能超過20-30個)。每種不同類型的容器都必須從模型中獲取數據,還是有更好的方法?
我很困惑與是第二件事,我的模型是在不同的圖書館。我是否需要在我的Web項目中創建模型的副本,並從該主模型填充本地模型,還是應該直接查詢混凝土類屬性的主模型?正如你所看到的,我的SingleContainer包含BaseProperties,它們是已經在主模型中的屬性的本地聲明。我沒有看到或理解本地模型的觀點,我不確定我是否在這裏。
對不起,我是設計模式的新手。
任何幫助將是非常讚賞,
感謝
感謝您的回答@ratnim。我同意模型部分。其實,我按照這裏討論的想法[鏈接](http://stackoverflow.com/questions/696027/design-pattern-builder)。遵循'數據對象'的想法對我來說似乎是可行的解決方案。但我保持這種questin開放,如果有任何更好的方法那裏有經驗的大師正在使用並能指導我 – Angloos