简体   繁体   English

将嵌套类放在单独的文件中

[英]Putting Nested Classes In Separate Files

I have a file with nested classes, but it's becoming long enough to be unreadable. 我有一个带有嵌套类的文件,但是它已经足够长以至于无法读取。 Is there a way I can break out the nested classes into separate files? 有没有办法将嵌套的类分解为单独的文件?

Use the right tools. 使用正确的工具。

替代文字

I'm afraid not. 恐怕不是。
As an alternative, you could consider converting some of them to plain Java classes: although nested classes increase encapsulation, you can certainly create good OO design without them. 作为替代方案,您可以考虑将其中一些转换为简单的Java类:尽管嵌套类增加了封装,但是如果没有它们,您当然可以创建良好的OO设计。

My two cents. 我的两分钱。

Write unit-tests to cover the code you are going to refactor. 编写单元测试以覆盖您将要重构的代码。

Then use refactoring tools, eg Eclipse/JDT to extract each class. 然后使用重构工具(例如Eclipse / JDT)提取每个类。 Run the tests for each refactoring job. 为每个重构作业运行测试。

For extra fun, you can do this without the unit tests. 为了获得更多乐趣,您可以在不进行单元测试的情况下执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM