1.使用類構造器實現例項化(bean的自身構造器)
1
2.使用靜態工廠方法實現例項化
2 public class OrderFactory{
3 private static OrderFactory orderFactory = new OrderFactory();
4 private OrderFactory();
5 public static OrderFactory createOrder(){
6 return OrderFactory;
7 }
8 }
3.使用例項化工廠方法實現例項化(透過別的實體的bean)
2
3 public class OrderFactory{
4 private static OrderService orderService = new OrderService();
5 private OrderFactory();
6 public static OrderService createOrderServiceBean{
7 return OrderService;
9
10 }
1.使用類構造器實現例項化(bean的自身構造器)
1
2.使用靜態工廠方法實現例項化
1
2 public class OrderFactory{
3 private static OrderFactory orderFactory = new OrderFactory();
4 private OrderFactory();
5 public static OrderFactory createOrder(){
6 return OrderFactory;
7 }
8 }
3.使用例項化工廠方法實現例項化(透過別的實體的bean)
1
2
3 public class OrderFactory{
4 private static OrderService orderService = new OrderService();
5 private OrderFactory();
6 public static OrderService createOrderServiceBean{
7 return OrderService;
8 }
9
10 }