I created an application that provides several services.
Now I would add the ability to ask the application what are the services it provides, so I thought to create another service with two methods:
- the first method returns true if the specified service is provided by the application;
- the second method returns a list (of strings) with the names of the services provided by the application.
What do you think of this approach?
Are there better ways to find out what services are offered by an application?
What you explain kind of makes sense initially but in fact I think you only need the first method.
This reminds me those questions when first working with COM a decade ago or so, you can query if an object implements an interface but you do need to know the interface you are querying for. People used to say why can’t I call a method and get a list of all implemented interfaces? Simply the answer is that even if you get a list, if you do not know what those interfaces are and do you can’t use the results.
Similarly, in your case, even if you get a list like Add, Multiply, Sell, Go, Take… if the client application does not exactly know what those methods or services are and how to use them the whole list makes no sense.
Better to have your client applications to ask for a specific service and be able to get true in case such service is exposed and that’s it.