业务代表与服务定位器 [英] Business Delegate Vs Service Locator

查看:118
本文介绍了业务代表与服务定位器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

业务代表和服务定位器之间有什么区别?既负责封装查找和创建机制。如果业务代表使用服务定位器来隐藏查找和创建机制,那么什么是业务代表专门用于,不能服务定位器替换业务代表。

解决方案

我不知道你是否已经


使用一个业务代表封装对业务服务的访问。业务代表隐藏业务服务的实现细节,例如查找和访问机制。


服务定位器封装了所需的逻辑搜索和/或获取基于一般注册表的特定服务的位置,限制和必填字段。业务代表封装了一组相关服务,并以一种凝聚力的方式公开他们,以防止服务客户必须搜索和访问与某项功能相关的所有服务。



此外,您阻止客户实际了解服务定位器及其应消费的服务,将其留给特定的业务代表。客户端只需要该委托来执行一组相关任务或依赖于各种服务的任务。






示例



业务代表实际上并不封装一组服务定位器。它通过服务定位器提供一个抽象层,以提供一个内聚的服务子集。通常只有一个服务定位器实例,多个实例需要额外的映射,您应该知道WHICH服务定位器提供的服务X,并将其视为需要服务定位器定位器。 >

一个例子应该有助于澄清事情。



想想用户帐户管理。 UserBusinessDelegate 查找注册服务注册用户,然后查找身份验证服务以允许登录。客户端只需要一个业务代表来访问这些服务,需要知道两个服务的ID。



这些服务标识被封装在 UserBusinessDelegate 中,避免了声明ids并使用服务定位器到处。考虑一下,如果一个服务ID发生变化,会发生什么?



在这种情况下,负责的业务代表更新,避免对客户产生直接的影响。 p>

What is the difference between Business Delegate and Service Locator.Do both responsible for encapsulating lookup and creation mechanism.If Business Delegate uses Service Locator for hiding lookup and creation mechanism then what is Business Delegate exclusively meant for, can't Service Locator replace Business Delegate.

解决方案

I don't know if you already checked this out, but it's a good start.

Use a Business Delegate to encapsulate access to a business service. The Business Delegate hides the implementation details of the business service, such as lookup and access mechanisms.

A Service Locator encapsulates the logic required to search and/or obtain the location, restrictions and required fields for a certain service based on a general registry. A Business Delegate encapsulates a group of related services and exposes them in a cohesive way to prevent a service customer from having to search and access all the services related to a certain functionality.

Plus, you prevent the customer from having to actually know the Service Locator and the services it should consume, leaving that to a particular Business Delegate. A client only needs that delegate to perform a group of related tasks or a task that relies in various services.


Example

A Business Delegate doesn't actually encapsulate a group of Service Locators. It provides an abstraction layer over a Service Locator to provide a cohesive subset of services. Usually there's only one instance of a Service Locator, multiple instances require an additional mapping where you should know WHICH Service Locator provides Service X, think of it as if you would need a Service Locator Locator.

An example should help clarify things.

Think about user account management. The UserBusinessDelegate looksup the registration service to register an user and then looksup the authentication service to allow a log in. The client only needs one Business Delegate to access those services and he doesn't need to know the id of both services.

Those service ids are encapsulated in the UserBusinessDelegate avoiding the need of declaring the ids and using a Service Locator everywhere. Think about this, what would happen if one service id changes?.

In such cases the Business Delegate in charge is updated, avoiding a direct impact for the client.

这篇关于业务代表与服务定位器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆