我应该如何在.NET中安排我的项目/类以避免循环依赖(How should I arrange my projects/classes in .NET to avoid circular depend

编程入门 行业动态 更新时间:2024-10-21 15:51:08
我应该如何在.NET中安排我的项目/类以避免循环依赖(How should I arrange my projects/classes in .NET to avoid circular dependecies)

我的程序试图在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.

更多推荐

本文发布于:2023-08-05 18:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1437437.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   如何在   以避免   NET   arrange

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!