Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPI机制的设计思路和使用场景没有讲到核心 #2378

Closed
mangyimang opened this issue Apr 25, 2024 · 0 comments
Closed

SPI机制的设计思路和使用场景没有讲到核心 #2378

mangyimang opened this issue Apr 25, 2024 · 0 comments

Comments

@mangyimang
Copy link
Contributor

mangyimang commented Apr 25, 2024

原文讲述SPI时,试图阐明其使用场景和原理,但遗憾的是前者探讨的不完全,严格来讲没有涉及到核心。以下是问题分析:

  • 原文表述:“SPI 即 Service Provider Interface ,字面意思就是:“服务提供者的接口”,我的理解是:专门提供给服务提供者或者扩展框架功能的开发者去使用的一个接口。SPI 将服务接口和具体的服务实现分离开来,将服务调用方和服务实现者解耦,能够提升程序的扩展性、可维护性。修改或者替换服务实现并不需要修改调用方。”
  • 问题:拿原文所举的日志例子来说,这个例子本身确实使用的是SPI机制实现的,但是请考虑以下三个问题:
  1. 为什么第三方实现商需要把你的jar包作为其实现规范?
  2. 规范应该是谁制定?谁实现?谁发现?谁加载?谁使用?

其实考虑以上问题无法完全得出SPI其实是为了原文所述的使用场景来设计的,这也暗含了这项机制的真正使用场景。

mangyimang added a commit to mangyimang/JavaGuide that referenced this issue Apr 25, 2024
问题来源:Snailclimb#2378
对于以上问题所指出的SPI机制的设计和使用场景的修正阐述
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant