Java:重构应用程序的便捷方法
我们有一个基于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果我有适当的公司资源可供使用(是的,正确的),我将如何处理这个问题:
Here is how I would approach this if I had appropriate company resources at my disposal (yeah right):
没有“方便”或“简单”的方法来重构现有代码库,特别是当代码库看起来像意大利面条时。
如果不了解系统当前的架构,就不可能回答这个问题。
一方面,您有很多设计/维护不佳的代码这一事实表明它需要一些重构工作。
然而,尚不清楚这是否足够。完全重写可能是一个更好的主意……特别是如果您需要扩大多个数量级。
如果没有您申请的详细信息,则无法回答。
它可能会减少响应时间。它可能会提高可靠性。它可能允许更多的在线用户同时在线。它可能不会执行上述任何操作。
使用框架并不能神奇地解决糟糕设计的问题。
您需要让他们相信该项目将带来良好的投资回报 (ROV)。您/他们还需要考虑替代方案:
如果不了解当前系统为何缓慢,就无法回答。
最重要的是,您可能需要直接团队之外的人员(例如外部顾问)对您当前的系统进行详细审查,并报告修复该系统的选项。听起来您的管理层不相信您的建议。
There are no "convenient" or "easy" ways to refactor an existing codebase, especially if the codebase looks like spaghetti.
That's impossible to answer without understanding your system's current architecture.
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.
Impossible to answer without details for your application.
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.
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:
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.
这些都是很大很大的问题。确实太宽泛了,无法找到一个答案。
我最好的建议是:如果可以的话,从小事做起。一点一点地重构。最重要的是,在接触代码之前,针对当前代码库编写自动化测试,这样您就可以相对确定在重构代码时没有破坏任何内容。
可能无法编写这些测试,因为代码可能无法以其当前格式进行测试。但您仍然应该将此作为您的主要目标之一。
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.
根据定义,重构不应该向用户显示任何差异。它只是为了帮助开发人员处理代码。听起来您想要进行更广泛的重写以使应用程序现代化。转向 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.
这是一个需要冗长答案的问题。首先,我建议该应用程序经过良好的测试并且按照规范运行。这意味着有足够的单元、集成和功能测试。功能测试也必须自动化。一旦这些到位,就可以逐步进行重构。您有足够的测试可以开始吗?
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?