views:

147

answers:

2

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 :/

+3  A: 

You should look at the Visitor pattern, described here:

http://en.wikipedia.org/wiki/Visitor%5Fpattern

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.

David M
A: 

Extract common functionality out of your objects until a third layer of abstraction. You may also want to look at MVC where your grammer would be the Model, your drawer would be the View, and you still need the controller.

GrayWizardx