int main() { CustomDialog* pDialog = new CustomDialog(new WindowsWidgetFactory()); pDialog->ShowDialog();
CustomDialog* pMacDialog = new CustomDialog(new MacWidgetFactory()); pMacDialog->ShowDialog(); }
public CustomDialog void ShowDialog(){} |
在Abstract Factory模式中将具体的Product封装在具体Factory实现中,而客户仍只要面对Factory与Product的抽象介面,避免依赖于具体的Factory与Product,由于Factory封装了所必须的Product,所以要更换掉所有的元件,只要简单的抽换掉Factory就可以了,不用修改客户端的程式。