本文介绍了从具有公共成员的多个类创建超类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在已经多次这样了。在较长时间运行的软件项目中,两个或三个类在一开始就完全不同。然而,随着时间的推移需求变化,用户会变得更聪明,在极少数情况下我甚至会变得更聪明,两个看似不同的流程变得非常相似。因此,需要修改代码,这两个或三个类最终看起来太相似而不舒适。他们只是尖叫着从一个共同的超类继承。

I've had this a number of times now. In longer running software projects two or three classes are totally different at the outset. However, as time goes by requirements change, users get a bit smarter, on rare occasions I even get a bit smarter and two seemingly different processes turn out to be very similar. As a consequence, code needs to be modified and these two or three classes end up looking too similar for comfort. They're just screaming to be inherited from a common superclass.

现在我是一个与生俱来的懒人(我之所以做软件的原因)和我很想拥有一个可以合并为超级类的工具。使用Resharper,我可以从一种类型创建一个超类。

Now I'm an innate lazy guy (reason why I'm making software in the first place) and I'd love to have a tool that does the merging into a superclass for me. With Resharper I can create a superclass from one type.

有没有人知道一个可以用多个类做这个技巧的工具,或者其他某种比较工具许多类之间的共性?

Does anyone know of a tool that can do this trick with multiple classes, or otherwise some kind of comparison tool that presents commonalities between a number of classes?

推荐答案

我所知道的工具不需要两个或更多类,只需定义共性。

There is no tool I know of that can take two or more classes and simply define commonalities.

我在重构工具中看到的最接近的工作只能在单个类上运行,但仍需要程序员输入。

The closest I have seen in refactoring tools would only operate on a single class and still require input from a programmer.

这是一件很复杂的事情,所以在我看来程序员是最好的工具...

This is a complex thing to do automatically, so in my opinion a programmer is the best tool...

这篇关于从具有公共成员的多个类创建超类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 17:08