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 }