我的程序试图在C#和WPF中绘制语法 。 我有:
1 DataStructure项目,描述了如何可视化的树结构。 树中的每个节点都与语法中的符号相关。 顶部的节点定义该非终结符号的规则。
1抽屉项目,描述WPF中的用户控件。
我需要在我的数据结构中引用抽屉,就像我遍历树时一样,我称之为DataStructure.draw(); 在每个节点上。 我还需要在抽屉项目中引用数据结构,以便我可以响应用户点击我的GUI,它将更新数据结构。
这创建了一个循环依赖,我试图使用控制器类但我不知道:/
My program is attempting to draw grammars in C# & WPF. I have:
1 DataStructure project which describes a tree structure of how it should be visualised. Each node in the tree relates to a symbol in the grammar. Nodes at the top define the rule for that nonterminal symbol.
1 Drawer project which describes the user controls in WPF.
I need to reference drawer in my datastructure as when i traverse the tree, I call DataStructure.draw(); on each node. I also need to reference the datastructure in my drawer project so I can respond to a user clicking on my GUI, it will update the data structure.
This creates a circular depedency, I have tried to use a controller class but I have no idea :/
最满意答案
您应该查看访问者模式,如下所述:
http://en.wikipedia.org/wiki/Visitor_pattern
这将允许您的数据结构项目接受任何类型的访问者,包括抽屉,但实际访问者(在您的情况下是绘图逻辑)的实现单独生活,不依赖于您不想要的方式。
You should look at the Visitor pattern, described here:
http://en.wikipedia.org/wiki/Visitor_pattern
This will allow your datastructure project to accept a visitor of any type, including a drawer, but the implementatin of the actual visitor (in your case the drawing logic) to live separately with no dependency in the way you don't want.
更多推荐
发布评论