Naming convention for classes that represents different versions of the same thing [closed]
https://softwareengineering.stackexchange.com/questions/235828
-
03-10-2020 - |
Question
Let's imagine I have an abstract class named ProtocolA
that represents the basic operations to work with the protocol A. Such protocol is in version 1, but new revisions are expected in the future. Version 2 is coming. How should I name the classes that implements that abstract class for each version? ProtocolA1
and ProtocolA2
?
Cheers.
Solution
If you won't need to support the original version ever again, then simply overwrite the class and keep the same name.
However, I suspect if it were that simple you wouldn't be asking.
I'm a big fan of unambiguous names. Does the protocol specification have a unique identifier? Something like an RFC number? If so, I'd name it something like ProtocolARfc2048
.
I'd avoid a version number internal to your application, as that will get confusing.
OTHER TIPS
Use Factory(either factory method or factory object) to accept a version number(preferably enum, but string or numbers can also work) and construct the appropriate subclass. That way, naming won't matter that much since you'll never use them directly in the code.
As for the naming themselves, if your language has namespacing you can create a namespace for each version of the protocol and give classes the same name in different namespaces.