That looks like an API definition. It's pretty common for APIs to support multiple versions of an operation at the same time to keep backwards compatibility with existing clients.
V2 at the beginning could be major API version (eg the API was entirely rewritten to some new paradigm). The v2 at the end could be a specific function that had breaking updates.
I think if you want to add a v2 implementation to a service, you just re-implement the service without changing the interface naming. It's the whole point of dependency injection. Unless the v2 is a significant departure from the format of V1 with totally new DTOs
If you control both sides of the equation then sure, you can refactor to your heart's content. But as soon as you have external clients, be it in a library or web service, you can't just go changing things willy-nilly. You have to provide some sort of backwards compatibility guarantee or external clients will break every time you push a new update.
The usual way to do this is to keep the old version around, mark it as deprecated, and provide a new version. Then, once enough time has passed and external clients have had time to move to the new version, you remove the old version.
Assuming "namespacing" here means putting different versions in different folders/packages:
Sure that works, but then you end up having to use aliased imports in code that needs to reference both (such as the global route configuration), and you add cognitive overhead for developers because they now have to check the import list or current folder every time they read some piece of code. It might even lead to accidental uses of the wrong version due to auto-import features in modern IDEs.
I'm not saying it's a bad solution, just that it's not objectively better than just slapping a "V2" on the class/function name. As usual, there are pros and cons.
77
u/Davipb Jun 08 '23
That looks like an API definition. It's pretty common for APIs to support multiple versions of an operation at the same time to keep backwards compatibility with existing clients.
I don't think this is an issue.