I ran at the problem of keeping backwards compatibility during app update. I have a client-server architecture and client sends to a server some information and in response receives up-to-date data. In the next version of the app, some new fields and methods are added. And if I use old client version some errors (like null pointers or incorrect workflow) may appear on server. I can check new features for null, but when there’re 3-4 different version clients – we’ll have spaghetti-code and a lot of potential hidden bugs.
Are there any design patterns that will help to resolve this problem? How to react on different client version?
Thank you, in advance.
Try this approach: Add a version field either to the login message each client message.
The latter works if you don’t have a session. If the version field is missing, you know it’s “version 0”.
On the server dispatch messages to handlers based on the version field. Many handlers can be split into an abstract base class which handles the common cases plus simple extensions per message version.
This allows you to avoid the spaghetti code.