0

我有一个基于 Java 的服务器,通过 TCP/IP 将数据从许多远程设备传输到一个应用程序。我需要开发它的几个版本。我如何在不需要为 2 个项目进行编码的情况下开发并保留它们?
我不仅要求那个项目,而且要求不同的方法。

4

4 回答 4

1

在行为不同的地方,使行为“数据驱动” - 通常通过将驱动行为的数据外部化到在运行时/启动时读取的属性文件。

目标是拥有一个单一的二进制文件,其行为取决于运行时环境中的属性文件。

Java supports this pattern through the Properties class, which offers convenient ways of loading properties. In fact, most websites operate in this way, for example the production database user/pass details are never (should never be) in the code. The sysadmins will edit a properties file that is read at start up, and which is protected by the operating system's file permissions.

Other options are to use a database to store the data that drives behaviour.

It can be a very powerful pattern, but it can be abused too, so some discretion is advised.

于 2012-06-25T07:39:59.713 回答
0

I think you need to read up on Source Control Management (SCM) and Version Control Systems (VCS).

I would recommend setting up a git or Subversion repository and adding the code initially to trunk and then branching it off to the number of branches (versions you'll be working on).

The idea of different versions is this: You're developing your code and have it in your SCM's trunk (or otherwise known as a HEAD). At some point you consider the code stable enough for a release. You therefore create a tag (let's call it version 1.0). You cannot (should not) make changes to tags -- they're only there as a marker in time for you. If you have a client who has version 1.0 and reports bugs which you would like to fix, you create a branch based on a copy of your tag. The produced version would (normally) be 1.x (1.1, 1.2, etc). When you're done with your fixes, you tag again and release the new version.

Usually, most of the development happens on your trunk. When you are ready with certain fixes, or know that certain fixes have already been applied to your trunk, you can merge these changes to other branches, if necessary.

于 2012-06-25T07:40:03.720 回答
0

通过重用代码库、配置和任何其他资产,在前一个版本的基础上制作任何其他版本。如果一次应该有多个版本,请使用配置管理实践。可能您应该考虑在服务器端进行一些路由活动和客户端版本检查。这就是“向后兼容性”发挥作用的地方。

于 2012-06-25T07:08:38.467 回答
0

主要方法是首先找到并提取不会从一个版本更改为另一个版本的代码。最好是最大化这部分以共享最大的代码库并简化维护(纠正一个错误意味着纠正所有错误)。

然后,这取决于从一个版本到另一个版本的真正变化。最好的是,在主项目上,您可以使用一些抽象类或接口,您可以为每个特定项目实现这些类或接口。

于 2012-06-25T07:20:41.907 回答