import AbstractFactory.Sample.factory.*;
public class Main
{
public static void main(String[] args)
{
if (args.length != 1)
{
System.out.println("Usage: java Main class.name.of.ConcreteFactory");
System.out.println("Example 1: java Main AbstractFactory.Sample.listfactory.ListFactory");
System.out.println("Example 2: java Main AbstractFactory.Sample.tablefactory.TableFactory");
System.exit(0);
}
Factory factory = Factory.getFactory(args[0]);
Link nba = factory.createLink("China NBA", "http://www.nba.china.com/");
Link sohu = factory.createLink("SOHU Sport ", "http://www.sohu.sport.com/");
Link apache = factory.createLink("Apache", "http://www.apache.org");
Link qq = factory.createLink("QQ", "http://www.qq.com/");
Link hk = factory.createLink("Google HK", "http://www.google.com.hk/");
Link google = factory.createLink("Google", "http://www.google.com/");
Tray root1 = factory.createTray("favorite");
root1.add(nba);
root1.add(sohu);
root1.add(qq);
Tray g = factory.createTray("Google city country");
g.add(hk);
g.add(google);
Tray d = factory.createTray("directory");
d.add(apache);
Tray root2 = factory.createTray("Google");
root2.add(g);
root2.add(d);
Page page = factory.createPage("LinkPage", "albert");
page.add(root1);
page.add(root2);
page.output();
}
}
抽象工厂模式【ABSTRACT FACTORY PATTERN】test
最新推荐文章于 2024-02-14 14:52:29 发布
986

被折叠的 条评论
为什么被折叠?



