java 服务提供者设计模式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25226312/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Service provider design pattern
提问by Rookie
I am looking for some explanation or reference info on the service provider design pattern as i came across this while studying the Grapht @defaultImplementation code (http://grepcode.com/file/repo1.maven.org/maven2/org.grouplens.grapht/grapht/0.5.0/org/grouplens/grapht/annotation/DefaultImplementation.java)
我在研究 Grapht @defaultImplementation 代码(http://grepcode.com/file/repo1.maven.org/maven2/org.grouplens. grapht/grapht/0.5.0/org/grouplens/grapht/annotation/DefaultImplementation.java)
This annotation is used with annotations in the LensKit implementation as in 28:57 of this video: https://www.youtube.com/watch?v=ug_JfORWK7w
此注释与 LensKit 实现中的注释一起使用,如本视频的 28:57:https: //www.youtube.com/watch?v=ug_JfORWK7w
I am looking for explanation or references to learn & understand the utility of this design pattern.
我正在寻找解释或参考资料来学习和理解这种设计模式的实用性。
Please advise
请指教
Thanks
谢谢
回答by DavidPostill
Service Provider Interface: Creating Extensible Java Applications
服务提供者接口:创建可扩展的 Java 应用程序
An application is an aggregation of cohesive services. While an application offers a broader set of functionality in terms of application programming interfaces (APIs) and classes, a service provides access to some specific application functionality or feature. The service defines the interfaces for the functionality and a way to retrieve an implementation. For example, consider an application that provides a variety of information about a geographical location, such as real estate data, weather information, demographics, etc. The weather service, a part of the application, may define only the interface for retrieving the weather information (more on this example shortly).
A service provider interface (SPI) is the set of public interfaces and abstract classes that a service defines. A SPI may be represented by a single interface (type) or abstract class or a set of interfaces or abstract classes that define the service contract.
应用程序是内聚服务的聚合。虽然应用程序在应用程序编程接口 (API) 和类方面提供了更广泛的功能集,但服务提供了对某些特定应用程序功能或特性的访问。该服务定义了功能的接口和检索实现的方法。例如,考虑一个提供有关地理位置的各种信息的应用程序,例如房地产数据、天气信息、人口统计等。作为应用程序一部分的天气服务可能只定义检索天气信息的接口(稍后将详细介绍此示例)。
服务提供者接口 (SPI) 是服务定义的一组公共接口和抽象类。SPI 可以由单个接口(类型)或抽象类或一组定义服务契约的接口或抽象类来表示。
Source Service Provider Interface: Creating Extensible Java Applications