服务定位器和工厂设计模式之间有什么区别? [英] What's the difference between the Service Locator and the Factory Design pattern?
本文介绍了服务定位器和工厂设计模式之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用unity,并且正在创建一个包装它的类,但我不知道如何调用它(服务定位器或工厂),它们都封装了对象的创建,所以……有什么区别?
I'm using unity and I'm creating a class that wrapps it and I dont' know how to call it, service locator or factory, both encapsulate the creation of the objects, so.... what's the difference?
推荐答案
工厂在需要时为您创建对象。
A factory creates objects for you, when requested.
服务定位器返回可能已经存在的对象,也就是说,对于您而言某处可能已经存在的服务。
Service locator returns objects that may already exist, that is services that may already exist somewhere for you.
只需考虑名称的含义:
- 工厂:创建对象的地方。
- 服务:是可以为您提供服务的东西
- 服务定位器:可以找到可以执行服务的东西。
这篇关于服务定位器和工厂设计模式之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文