OOP GUI 类 使用 MVC 设计

OOP GUI classes designing with MVC

我有基于树的数据模型。我需要在树查看器上显示它的树,在元素查看器上显示其中一个元素树,如下所示:

tree viewer | element viewer:
Element A   | There should be content from selected element (Element C).
 -Element B |
 -Element C |
  (Selected)|

树查看器和元素查看器都可以对模型进行更改。

现在我有以下代码:

public class TreeNode{...};
public class AClass extends TreeNode{...};
public class BClass extends TreeNode{...};
public class CClass extends TreeNode{...};

public class Viewer{
    ...
    //Specifies how to display data from a treeNode
    public abstract void showModel();
    ...
};
public class AViewer extends Viewer{...};
public class BViewer extends Viewer{...};
public class CViewer extends Viewer{...};

public class Controller{
    ...
    public void chooseViewer(TreeNode treeNode ){
        if (treeNode instanceof AClass) elementViewer = new AViewer(treeNode);
        else if (treeNode instanceof BClass) elementViewer = new BViewer(treeNode);
        else if (treeNode instanceof CClass) elementViewer = new CViewer(treeNode);
    }
}

如何从 OOP 和 MVC 设计模式的角度正确解决这个任务?

MVC 和 OOP 有时确实会发生冲突。话虽如此,解决方案似乎只是将查看器选择移动到树节点:

public class TreeNode {
    Viewer getViewer();
}