从code后面重构单独的业务逻辑 [英] Refactoring to separate business logic from code behind

查看:124
本文介绍了从code后面重构单独的业务逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了一个asp.net项目,我发现网页背后的code中含有大量的业务逻辑。

I've inherited a asp.net project and I'm finding that the code behind pages contain a lot of business logic.

我已经决定,在大多数情况下,最好离开工作code的地方不是试图做大规模重构。然而,有执行的功能在命令行实用程序可以重新用于批处理的页面。我想集中在这些网页上我的能量,重构出业务逻辑和引用,在其他实用程序。

I've decided that in most cases it's better to leave the working code in place than try and do a massive refactoring. However there are pages that perform functionality that could be re-used in command line utilities for batch processing. I'd like to focus my energies on these pages, refactoring out the business logic and referencing that in other utilities.

我目前正在重构其已在code后面的6200线code的这个特定页面。什么我发现它是非常繁琐的工作试图找到背后的code和页面特定对象之间的依赖关系。

I am currently looking to refactor this particular page which has 6200 lines of code in the code behind. What I'm finding is it's very tedious work trying to locate the dependencies between the code behind and the page specific objects.

我想知道如果任何人的一个工具,一个VS功能,或者,让我系统地定位并攻击这些依赖关系的方法知道?东西,这将让我确定code引用ViewState中,一个文本框,面板的任何区域,落downlist,等等,这样我就可以将这些引用方法的参数,并最终推动这一功能出来的页面类。

I'm wondering if anybody knows of a tool, a VS feature, or a method that would allow me to systematically locate and attack these dependencies? Something that will allow me to identify any area of the code that references ViewState, a textbox, panel, drop downlist, etc..., so I can move these references to method parameters and ultimately move this functionality out of the page class.

推荐答案

我要通过检查不符合的单一职责原则并打破他们,让他们做。一旦这样做了,你应该对code做什么处理,你应该能集团的code更容易,并将其移动到专用类的群体建立必要的对象,当您去使用。我觉得 ReSharper的是帮助做到这一切非常有用的工具。最终,你将永远需要有code中基本面扎实抓好可以成功地重构了。

I would begin by examining any method that doesn't follow the Single Responsibility Principle and break them down so that they do. Once that's done you should have a handle on what the code does and you should be able to group the code more easily and move it into dedicated classes for those groups creating the necessary objects to use as you go. I find ReSharper is a very useful tool to help do all this. Ultimately you will always need to have a solid grasp of the fundamentals within the code before you can successfully refactor.

我们都在那里在某些时候,你有我最深切的同情,而是你愿意尝试它在所有意味着你已经在正确的方向前进。祝你好运!

We've all been there at some point and you have my deepest sympathy but your willingness to attempt it at all means you're already heading in the right direction. Good Luck!

这篇关于从code后面重构单独的业务逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆