English 中文(简体)
我怎么能重新解释这种不幸的 部分阶级呢?
原标题:How can I refactor this unfortunate partial class?

我开始使用一个 Linq2Sql 数据访问层, 它有一个“ 神级” 部分类, 其另一部分是生成的 JubeSet 。 这个部分类会做各种各样的事情, 比如将自己序列到 Json, 做数据库呼叫和各种工具功能, 以及定义一系列方便属性和与“ 部分” 模式互动的方法 。

作为副作用,它不可能 连成系列, 和所有其他的问题 与“上帝级”的反模式。

将这些班级分开以更好地将关注问题分开的好设计模式是什么? 我想强调降低影响,因为这个班级在整个应用程序中都充斥着。

问题回答

与大多数遗留代码Id 的重构一样,建议引入一个中间适配器类(见adapter 模式 ),该类从仅代表旧功能开始。然后,随着新代码的引入,包装器可以开始将工作委托给新代码。直到最终能够完全删除包装。

此外,我还要说,你应该写测试(单位或整合),只要你能够发现/核实该类各部分的功能,然后当再考虑因素时,你就会确定你没有破坏任何功能,因为你将有一套回归测试可以返回。





相关问题
Choosing the right subclass to instantiate programmatically

Ok, the context is some serialization / deserialization code that will parse a byte stream into an object representation that s easier to work with (and vice-versa). Here s a simplified example ...

Design pattern for managing queues and stacks?

Is there a design pattern for managing a queue or a stack? For example, we are looking to manage a list of tasks. These tasks will be added to a group queue, users will then be able to pull off the ...

Organizing classes using the repository design pattern

I have started upgrading one of our internal software applications, written in ASP.NET Web Forms, and moving to ASP.NET MVC. I am trying to leverage the Repository design pattern for my classes, ...

Misuse of Observer Pattern?

I have a Car object which contains a latitude field and a longitude field. I use the observer pattern so that any time either of these fields change in my application, my car object is notified. I ...

How are Models (in MVC) and DAOs supposed to interact?

How are models and DAOs supposed to interact? I m in the process of putting together a simple login module and I m unsure where to put the "business logic." If I put the logic with the data in the ...

热门标签