无证的,神秘的类-垃圾,还是我不知道的设计模式?

问题描述

| 我继承了以下代码: (为了保护无辜者,有些名称已更改。)
package foo.bar.baz;
import javax.swing.JPanel;

//Main panel in the GUI
class DemoRootPanel extends JPanel {
    private final MainGUIClass demo;

    DemoRootPanel(MainGUIClass demo) {
        super();   
        this.demo = demo;
    }

    public MainGUIClass getDragAndDropPanelsDemo() {
        return demo;
    }
}
我没有立即知道为什么它很重要,所以我在源代码树中摸索着看到它被使用了。这些都是结果:
$ ack -i rootpanel
DemoRootPanel.java
5:class DemoRootPanel extends JPanel {
8:    DemoRootPanel(MainGUIClass demo) {

MainGUIClass.java
70: private final DemoRootPanel rootPanel;
124:        rootPanel = new DemoRootPanel(MainGUIClass.this);
821:                    containerPanels.add(new ContainerPanel(rootPanel));
846:                            containerPanels.add(new ContainerPanel(rootPanel));
1777:               ContainerPanel newContainer = new ContainerPanel(rootPanel);

ContainerPanel.java
30: DemoRootPanel rootPanel;
49: public ContainerPanel(DemoRootPanel rootPanel) {
51:     this.rootPanel = rootPanel;
$ ack getDragAndDropPanelsDemo
DemoRootPanel.java
13:    public PileSortGUI getDragAndDropPanelsDemo() {
据我所知,这完全没有必要。但这是我的第一份工作,我还没去上大学,等等,所以我想知道这是否不是重要但不是我惯用的习语。 PS-我对SO也比较陌生。我相信可以肯定地回答这个问题,但它的技术性似乎比正常情况低。如果还不行,请通知我,我将其删除。 (或者只是修改它:P)     

解决方法

        看起来这只是一个空的JPanel,另外还包含对主类对象的引用。 可能可以简单地将其替换为简单的
JPanel
(省略the4ѭ参数)。 可能是某人计划将此类用于某个目标,但后来却忘记了这一点。或者有人误解并认为一个人使用的每个GUI对象都必须有一个自己的子类。注释ѭ5看起来像这样。 如果您有编写此代码的人,请问他(或她)-否则,我将用一个简单的JPanel代替它的使用,以减少类的数量。 (您有一个版本控制系统,对吗?)     

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...