Why service provider method is called "provider", but not "provide"?

David Holmes david.holmes at oracle.com
Tue Nov 24 12:04:48 UTC 2020


On 24/11/2020 5:38 pm, Alex Orlov wrote:
>  >The provider() method returns an instance of a class that provides a
>  >given service. provider() could be called serviceProvider() or
>  >serviceImplementor() - but providor() suffices.
> Following this logic we can change hashCode() in Object to provider(). 
> Because it will return a value, that provides a hashCode. 

No the value returned _is_ a hashcode.

You are confusing returning an object that is capable of providing a 
service, with asking that object to provide the service.

David

> I still think that provider()
> name is not quite good. I would name it either "service" or "provide".
> --
> Best regards, Alex Orlov
> 
>     Вторник, 24 ноября 2020, 10:26 +03:00 от David Holmes
>     <david.holmes at oracle.com>:
>     On 24/11/2020 4:46 pm, Alex Orlov wrote:
>      > Could you then explain the difference between service and service
>      > provider? As I understand
>      > you’re saying they are the same. I always thought, that they were two
>      > different things. For example,
> 
>     They are two different things and I'm certainly not saying they are the
>     same.
> 
>      > what we are talking about service factory/supplier/consumer we
>     separate
>      > service from
>      > factory/supplier/consumer. And even in
>      >
>     https://docs.oracle.com/javase/9/docs/api/java/util/ServiceLoader.Provider.html
>     <https://docs.oracle.com/javase/9/docs/api/java/util/ServiceLoader.Provider.html>
>      >
>     <https://docs.oracle.com/javase/9/docs/api/java/util/ServiceLoader.Provider.html
>     <https://docs.oracle.com/javase/9/docs/api/java/util/ServiceLoader.Provider.html>>
>      > we assume that this is a provider, and using this provider you
>     can get a
>      > service.
> 
>     I'm not seeing the connection with what we have been discussing
>     directly.
> 
>     The provider() method returns an instance of a class that provides a
>     given service. provider() could be called serviceProvider() or
>     serviceImplementor() - but providor() suffices.
> 
>     Cheers,
>     David
>     -----
> 
>      > --
>      > Best regards, Alex Orlov
>      >
>      > Вторник, 24 ноября 2020, 7:47 +03:00 от David Holmes
>      > <david.holmes at oracle.com </compose?To=david.holmes at oracle.com>>:
>      > On 23/11/2020 6:28 pm, Alex Orlov wrote:
>      > > > The method does return a "provider". It returns the object that
>      > is an
>      > > > instance of a class that provides the service - hence that
>      > object is a
>      > > > provider.
>      > > I don’t agree with that. It returns the object that is an
>     instance of
>      > > the service.
>      >
>      > And that object is the service provider.
>      >
>      > David
>      > -----
>      >
>      > > --
>      > > Best regards, Alex Orlov
>      > >
>      > > Понедельник, 23 ноября 2020, 1:30 +03:00 от David Holmes
>      > > <david.holmes at oracle.com </compose?To=david.holmes at oracle.com>
>     </compose?To=david.holmes at oracle.com>>:
>      > > On 20/11/2020 9:48 pm, Alex Orlov wrote:
>      > > >
>      > > > Hello all,
>      > > >
>      > > > According to this tutorial
>      > >
>      >
>     https://www.logicbig.com/tutorials/core-java-tutorial/modules/service-provider-method.html
>     <https://www.logicbig.com/tutorials/core-java-tutorial/modules/service-provider-method.html>
>      >
>     <https://www.logicbig.com/tutorials/core-java-tutorial/modules/service-provider-method.html
>     <https://www.logicbig.com/tutorials/core-java-tutorial/modules/service-provider-method.html>>
>      > >
>      >
>     <https://www.logicbig.com/tutorials/core-java-tutorial/modules/service-provider-method.html
>     <https://www.logicbig.com/tutorials/core-java-tutorial/modules/service-provider-method.html>
>      >
>     <https://www.logicbig.com/tutorials/core-java-tutorial/modules/service-provider-method.html
>     <https://www.logicbig.com/tutorials/core-java-tutorial/modules/service-provider-method.html>>>
>      > > > we can declare in module-info provider class with "provider"
>      > > method. For example,
>      > > >
>      > > >  ......
>      > > > public class TheServiceProvider {
>      > > >    public static AService provider() {
>      > > >        return new AServiceImpl();
>      > > >    }
>      > > > }
>      > > >
>      > > > The only thing what I don’t understand is why this method is
>      > > called "provider". The method doesn’t return
>      > > > provider, method returns an instance of the service, so, as I
>      > > understand, the method must be named
>      > > > "provide". And, as I understand, provider is usually the class,
>      > > that has "provide" method.
>      > >
>      > > The method does return a "provider". It returns the object that
>     is an
>      > > instance of a class that provides the service - hence that object
>      > is a
>      > > provider.
>      > >
>      > > Cheers,
>      > > David
>      > > -----
>      > >
>      > > > Of course that’s not very important, but it is JDK, so it was
>      > > developed by very experienced java developer
>      > > > who should know java naming convention and I want to understand
>      > > why this did so. Could anyone explain?
>      > > >
>      > > >
>      > > > --
>      > > > Best regards, Alex Orlov
>      > > >
>      > >
>      >
> 


More information about the jigsaw-dev mailing list