circular dependency

M

Mike

I ran into a problem with circular dependencies. My code
looks somthing like:

using B
namespace A
{
class formA
{
void foo()
{
formB B = new formB();
B.show();
}

void changeMenu()
{
...
}
}
}

--------------------------------------------------------

//using A // this would create a circular dependency
namespace B
{
class formB
{
formA A;
void formB()
{
A = (formA)this.parentForm;
A.changeMenu(); //formA is the parent MDI
//form and I want to change
//the menu of formA when
//formB gets displayed inside
//it.
}
}
}

The way it's written, the .cs file that contains
namespace B won't compile because there is no reference
to namespace A. But I can't add a reference because it
would create a circular dependency. Is there anything I
can do without putting these into the same project? Does
C# have something similar to forward references in C++?
This has been driving crazy so any suggestions would be
most geatly appreciated. Thank you for your reply.

Mike
 
D

Darrin J Olson

My suggestion would be to create a custom event with a custom delegate and
event parameters. Throw the event when you need to, and catch it with your
parent form (MDI form). The event could then carry the information you need
to change the menu, and could be thrown whenever you need it.

-Darrin
 
G

Grant Richins [MS]

You could create an interface that formA uses. Then both projects would
reference the interface, and formB would not reference formA.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top