You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
581 B

package factory;
public class Main {
/**
* 主方法,用于测试工厂方法模式
* @param args 命令行参数
*/
public static void main(String[] args) {
// 创建具体工厂实例
Creator creator = new ConcreteCreator();
// 调用工厂的操作方法,该方法会使用工厂方法创建产品并调用产品的操作
creator.someOperation();
// 直接使用工厂方法创建产品
Product product = creator.factoryMethod();
product.operation();
}
}