Java:重构应用程序的便捷方法

发布于 2024-10-18 13:10:57 字数 316 浏览 2 评论 0原文

我们有一个基于 JSP 和 Servlet 构建的敏捷企业应用程序,没有任何设计策略。

该应用程序于 2002 年初构建,考虑到 1000 个用户。 2002年之后,我们收到了来自营销合作伙伴的大量请求。

目前,该应用程序有大量意大利面条式代码,其中包含大量 If 和 else。一个类有超过 20,000 行代码,其中包含大量没有抽象的函数。

现在,我们需要支持数十亿条记录, 我们需要立即和逐步做什么?

我们必须重构应用程序吗? 我们需要使用哪个框架? 该框架的使用对最终用户有何帮助? 如何说服领导进行重构? 如何获得比现有系统更快的响应时间?

We have an agile enterprise application built on JSP and Servlet without any design strategy.

This application was built in early 2002 considering 1000 users. After 2002, we received lots of requests from the marketing partners.

Currently, the application has lots of spaghetti code with lots of Ifs and elses. One class has more than 20,000 lines of code with a huge body of functions without abstraction.

Now, we need to support billions of records,
what we need to do immediately and gradually?

We have to refactor the application?
Which framework, we need to use?
How the usage of the framework will be helpful to the end users?
How to convince the leaders to do the refactoring?
How to gain the faster response time as compare to the current system?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

病女 2024-10-25 13:10:57

如果我有适当的公司资源可供使用(是的,正确的),我将如何处理这个问题:

  1. 在进行重大更改之前建立良好的质量保证流程,并设置自动回归测试。我不在乎你有多好,你不能对这样的系统进行单元测试并合理控制回归。
  2. 绘制出相互依赖关系,看看单个类可以作为一个单元进行多少测试。
  3. 你怎么吃大象?一次咬一口。采用给定的所需功能(最好是围绕增加负载需求的功能)并重构类中可以单独处理的部分。
  4. 通过阅读有效使用旧代码来了解如何执行上述 3 项操作。

Here is how I would approach this if I had appropriate company resources at my disposal (yeah right):

  1. Get a good QA process going, with automated regression testing set up before making significant changes. I don't care how good you are, you can't put a system like that under unit test and reasonably control for regressions.
  2. Map out interdependencies, see how much an individual class can be tested as a unit.
  3. How do you eat an elephant? One bite at a time. Take a given piece of required functionality (preferably something around the increase load requirements) and refactor the parts of the class or classes that can be worked on in isolation.
  4. Learn how do 3 above by reading Working Effectively with Legacy Code.
我不会写诗 2024-10-25 13:10:57

重构应用程序的便捷方法。

没有“方便”或“简单”的方法来重构现有代码库,特别是当代码库看起来像意大利面条时。

...我们需要立即和逐步做什么?

如果不了解系统当前的架构,就不可能回答这个问题。

我们必须重构应用程序吗?

一方面,您有很多设计/维护不佳的代码这一事实表明它需要一些重构工作。

然而,尚不清楚这是否足够。完全重写可能是一个更好的主意……特别是如果您需要扩大多个数量级。

我们需要使用哪个框架?

如果没有您申请的详细信息,则无法回答。

框架的使用对最终用户有何帮助?

它可能会减少响应时间。它可能会提高可靠性。它可能允许更多的在线用户同时在线。它可能不会执行上述任何操作。

使用框架并不能神奇地解决糟糕设计的问题。

如何说服领导进行重构?

您需要让他们相信该项目将带来良好的投资回报 (ROV)。您/他们还需要考虑替代方案:

  • 如果您/他们什么都不做会发生什么,或者
  • 完全重写可能会产生更好的结果。

如何获得比当前系统更快的响应时间?

如果不了解当前系统为何缓慢,就无法回答。


最重要的是,您可能需要直接团队之外的人员(例如外部顾问)对您当前的系统进行详细审查,并报告修复该系统的选项。听起来您的管理层不相信您的建议。

Convenient way to refactor the application.

There are no "convenient" or "easy" ways to refactor an existing codebase, especially if the codebase looks like spaghetti.

... what we need to do immediately and gradually?

That's impossible to answer without understanding your system's current architecture.

We have to refactor the application?

On the one hand, the fact that you have a lot of poorly designed / maintained code would suggest that it needs some refactoring work.

However, it is not clear that it will be sufficient. It could be that a complete rewrite would be a better idea ... especially if you need to scale up by many orders of magnitude.

Which framework, we need to use?

Impossible to answer without details for your application.

How the usage of the framework will be helpful to the end users?

It might reduce response times. It might improve reliability. It might allow more online users simultaneously. It might do none of the above.

Using a framework won't magically fix a problem of bad design.

How to convince the leaders to do the refactoring?

You need to convince them that the project is going to give a good return on investment (ROV). You / they also need to consider the alternatives:

  • what happens if you / they do nothing, or
  • is a complete rewrite likely to give a better outcome.

How to gain the faster response time as compare to the current system?

Impossible to answer without understanding why the current system is slow.


The bottom line is that you probably need someone from outside your immediate group (e.g. an external consultant) to do a detailed review your current system and report on your options for fixing it. It sounds like your management don't trust your recommendations.

琉璃繁缕 2024-10-25 13:10:57

这些都是很大很大的问题。确实太宽泛了,无法找到一个答案。

我最好的建议是:如果可以的话,从小事做起。一点一点地重构。最重要的是,在接触代码之前,针对当前代码库编写自动化测试,这样您就可以相对确定在重构代码时没有破坏任何内容。

可能无法编写这些测试,因为代码可能无法以其当前格式进行测试。但您仍然应该将此作为您的主要目标之一。

These are big, big questions. Too broad for one answer really.

My best advice is this: start small, if you can. Refactor piece by piece. And most importantly, before touching the code, write automated tests against the current codebase, so you can be relatively sure you haven't broken anything when you do refactor it.

It may not be possible to write these tests, as the code may not be testable in it's current format. But you should still make this one of your main goals.

凌乱心跳 2024-10-25 13:10:57

根据定义,重构不应该向用户显示任何差异。它只是为了帮助开发人员处理代码。听起来您想要进行更广泛的重写以使应用程序现代化。转向 JSF 之类的东西将使开发人员的生活变得更加轻松,并且使您能够访问 Web 组件库以改善用户体验。

By definition refactoring shouldn't show any difference to the users. It's only to help developers work on the code. It sounds like you want to do a more extensive rewrite to modernize the application. Moving to something like JSF will make life a lot easier for developers and will give you access to web component libraries to improve the user experience.

巷子口的你 2024-10-25 13:10:57

这是一个需要冗长答案的问题。首先,我建议该应用程序经过良好的测试并且按照规范运行。这意味着有足够的单元、集成和功能测试。功能测试也必须自动化。一旦这些到位,就可以逐步进行重构。您有足够的测试可以开始吗?

It is a question which needs a lengthy answer. To start with I would suggest that the application is tested well and is working as per the specification. This means there are enough unit, integration and functional tests. The functional tests also have to be automated. Once these are in place, a step by step refactoring can take place. Do you have enough tests to start?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文