帮助将一个大类分成两部分的工具
有没有一个好的帮助/工具可以帮助我将一个大类分成几个部分? 该代码很好地完成了它的工作,但是一个类超过 500 行就不太舒服了。我确信它可以分成更小的部分。
这次我对python的一个工具感兴趣,但我确信它不算。
Is there a good aid/tool for helping me split a huge class into parts?
The code does its job well, but having a class over 500 lines is not comfortable. I am sure it could be split up into smaller pieces.
This time I am interested in a tool for python, but I am sure it does not count.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为什么你不能手动执行此操作? 500 行并没有那么多需要处理。我怀疑任何工具都能够在其服务目的的背景下有意义地分割一个类。我建议您自己将其拆分并重新设计/重构代码。
Why can't you do this manually? 500 lines is not that much to deal with. I doubt any tool will be able to split up a class meaningfully in the context of the purpose it serves. I suggest you split it up on your own and redesign/refactor the code while you're at it.
首先,这500行代码到底是什么让你“不舒服”?为什么您认为只需将班级分成两个新班级?也许班级本身就很好(500 人并不算多),或者,也许班级需要分成 3 或 4 个不同的班级。
如果没有更多信息,我想说,除非您能够理解为什么需要将其分成更小的部分,否则工具不会对您有所帮助。没有工具会告诉您如何如何拆分类。
问问自己班级的单一职责是什么。如果你想出了多个,那么班级至少应该按照职责划分。如果你想出了 6 个,那么你就有相当多的工作要做。
First of all, what is it about the 500 lines of code that makes you "not comfortable"? Why do you think you need to only split the class into two new classes? Perhaps the class is fine as it is (500 isn't huge), or, perhaps the class needs to be split into 3 or 4 different classes.
Without more information, I'd say that a tool isn't going to help you until you can understand why you feel the need to split it into smaller pieces. No tool will tell you how to split the class.
Ask yourself what the single responsibility of the class is. If you come up with more than one, then the class should be split at least along the lines of responsibility. If you come up with 6, you have a fair amount of work to do.
嗯,这取决于你所指的语言。与 Python 等语言相比,您可以对 Java 等语言进行更安全的自动重构(因为 Python 的动态特性)。
在 Python 中,使用
getattr()
是正常的(“pythonic”),而在 Java 中使用内省更像是“除非必须,否则不要使用它” ”。这些技术使得自动重构工具几乎不可能工作,因为它们无法检测所有关系。无论如何,对于 java 和 python,我都使用 Eclipse 进行重构。它的工作做得很好。对于 python,您将需要 pydev 插件或 aptana studio。
Well, it counts what language you mean. You can do much safer automated refactoring for languages like java compared to languages like python (because of dynamic nature of python).
In Python it is normal ("pythonic") to use
getattr()
while in java using introspection is more like "don't use it unless you have to". Such techniques makes it almost impossible to for automated refactoring tools to work because they are not able to detect all relations.Anyhow, for both java and python I use Eclipse for refactoring. It does the job quite well. For python, you will need pydev plugin or aptana studio.
我找到了 ExtC Visualizer,它适用于 java,但无法运行然而。
I have found ExtC Visualizer, which is for java, and can't get it working yet.