I'm working on a Spring-based REST api that has v1 and v2 variants:
/api/v1/dates
/api/v2/dates
Correspondingly, there are v1 and v2 packages in the code base:
com.company.api.v1
com.company.api.v2
Is it a good practice to postfix class names with version number like below:
- DatesControllerV1.java (in v1 package)
- DatesControllerV2.java (in v2 package)
I prefer not postfixing version in the class name as:
- their package names should tell you about the version already, redundant;
- I simply don't like numeric character in class name.
However, not postfixing version(ie. same class name but in different packages) will increase the probability of using the wrong class accidentally due to IDE auto-complete/auto-import by careless developers.
I tried looking for a github repo that has similar code base structure and see how they deal with it. But could not find one unfortunately.
I'm wondering which approach do you think is better and the reason. I'm also wondering if there is a better approach(for the current code base setup) than these two?
UPDATE
With the help from Azuaron and CormacMulhall, I realized that I really don't have other options to improve my current situation, given that both the v1 and v2 APIs reside in the same code base and I cannot change this setup.
For those who are seeking for the proper way of doing this(having different versions of APIs), please see Azuaron's answer below.