473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Circular References! Big Problem!

pnp
I'm developing an app (in C #) that uses 2 usercontrols that must be in
different dll's.
The problem is that each one needs to use the other, so as a result I get a
circular reference error when I try to add the references to the dll's.

Is there a way round this problem? In C++ one could use header files... What
can I do here?
Nov 16 '05 #1
4 872
pnp,
Use a Separated Interface Pattern.

http://www.martinfowler.com/eaaCatal...Interface.html

Project1 would define UserControl1 along with Interface2. UserControl1 would
maintain a reference to Interface2. Interface2 would have any Properties,
Subs, Functions, or Events that UserControl1 needed of UserControl2.

Project2 would define UserControl2 which implements Interfac2.

Project2 would reference Project1, however Project1 would not reference
Project2.

Your form's project could reference both Project1 & Project2 & connect the
two controls on the forms.
However! I have to ask the question: Aren't you introducing too much
coupling if UserControl1 requires UserControl2 & visa versa? I would
seriously consider a Mediator Pattern instead of a Separated Interface
Pattern, as the Mediator would have a reference to the two controls
mediating any communication between the two controls. The form itself could
be the Mediator, or the Mediator could be its own UserControl or Component.

Hope this helps
Jay

"pnp" <pnp.at.softlab.ece.ntua.gr> wrote in message
news:Os**************@TK2MSFTNGP09.phx.gbl...
I'm developing an app (in C #) that uses 2 usercontrols that must be in
different dll's.
The problem is that each one needs to use the other, so as a result I get a circular reference error when I try to add the references to the dll's.

Is there a way round this problem? In C++ one could use header files... What can I do here?

Nov 16 '05 #2
pnp
Thanks Jay, on your replying so soon.

By using interfaces the problem still remains because I need to create
objects of
classA in Proj1 in classB in Proj2 and vice versa... These are graphical
usercontrols and I don't want to put them in the same dll because they need
to be seperate modules... :(

Besides the mediator function, is there something else that could be done?
Peter N. P.
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
pnp,
Use a Separated Interface Pattern.

http://www.martinfowler.com/eaaCatal...Interface.html

Project1 would define UserControl1 along with Interface2. UserControl1 would maintain a reference to Interface2. Interface2 would have any Properties,
Subs, Functions, or Events that UserControl1 needed of UserControl2.

Project2 would define UserControl2 which implements Interfac2.

Project2 would reference Project1, however Project1 would not reference
Project2.

Your form's project could reference both Project1 & Project2 & connect the
two controls on the forms.
However! I have to ask the question: Aren't you introducing too much
coupling if UserControl1 requires UserControl2 & visa versa? I would
seriously consider a Mediator Pattern instead of a Separated Interface
Pattern, as the Mediator would have a reference to the two controls
mediating any communication between the two controls. The form itself could be the Mediator, or the Mediator could be its own UserControl or Component.
Hope this helps
Jay

"pnp" <pnp.at.softlab.ece.ntua.gr> wrote in message
news:Os**************@TK2MSFTNGP09.phx.gbl...
I'm developing an app (in C #) that uses 2 usercontrols that must be in
different dll's.
The problem is that each one needs to use the other, so as a result I
get a
circular reference error when I try to add the references to the dll's.

Is there a way round this problem? In C++ one could use header files...

What
can I do here?


Nov 16 '05 #3
pnp,
No the problem does not still exist!

Are you saying you want to: create Control1 on top of Control2 on top of
Control1 on top of Control2 on infinity? that obviously wont work, or at
least it does not really make sense (to me) to visually nest one control on
another that is nested on itself.

What I gave will allow ClassA to have an instance of ClassB that also has a
reference to the first ClassA! Where ClassA & ClassB are in separate
projects.

Something like:

public interface Interface2
{
void Method2()
}

public class Class1
{

Interface2 i2;

public Class1(Interface2 i2)
{
this.i2 = i2;
}
}

public class Class2 : Interface2
{

Class1 c2;

public Class2()
{
c2 = new Class1(this);
}

void Method2()
{
}
}

Instead of passing is to expose a Interface2 property on UserControl1.
Depending on the requirements of the project I will actually use
Activator.CreateInstance to create an instance of the class that implements
the interface...

Because Project2 (class2) has a reference to Project1, Class2 can use
methods of Class1 directly. Class1 however uses methods of Class2 indirectly
via the interface. Note in this case the interface can be either an actual
Interface of a base Class.

Hope this helps
Jay
"pnp" <pnp.at.softlab.ece.ntua.gr> wrote in message
news:ea**************@TK2MSFTNGP12.phx.gbl...
Thanks Jay, on your replying so soon.

By using interfaces the problem still remains because I need to create
objects of
classA in Proj1 in classB in Proj2 and vice versa... These are graphical
usercontrols and I don't want to put them in the same dll because they need to be seperate modules... :(

Besides the mediator function, is there something else that could be done?
Peter N. P.
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
pnp,
Use a Separated Interface Pattern.

http://www.martinfowler.com/eaaCatal...Interface.html

Project1 would define UserControl1 along with Interface2. UserControl1

would
maintain a reference to Interface2. Interface2 would have any Properties, Subs, Functions, or Events that UserControl1 needed of UserControl2.

Project2 would define UserControl2 which implements Interfac2.

Project2 would reference Project1, however Project1 would not reference
Project2.

Your form's project could reference both Project1 & Project2 & connect the two controls on the forms.
However! I have to ask the question: Aren't you introducing too much
coupling if UserControl1 requires UserControl2 & visa versa? I would
seriously consider a Mediator Pattern instead of a Separated Interface
Pattern, as the Mediator would have a reference to the two controls
mediating any communication between the two controls. The form itself

could
be the Mediator, or the Mediator could be its own UserControl or

Component.

Hope this helps
Jay

"pnp" <pnp.at.softlab.ece.ntua.gr> wrote in message
news:Os**************@TK2MSFTNGP09.phx.gbl...
I'm developing an app (in C #) that uses 2 usercontrols that must be in different dll's.
The problem is that each one needs to use the other, so as a result I get
a
circular reference error when I try to add the references to the dll's.
Is there a way round this problem? In C++ one could use header

files... What
can I do here?



Nov 16 '05 #4
pnp
Thanks a lot Jay. You helped me get out of a lot of trouble!

Peter

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:ei**************@TK2MSFTNGP09.phx.gbl...
pnp,
No the problem does not still exist!

Are you saying you want to: create Control1 on top of Control2 on top of
Control1 on top of Control2 on infinity? that obviously wont work, or at
least it does not really make sense (to me) to visually nest one control on another that is nested on itself.

What I gave will allow ClassA to have an instance of ClassB that also has a reference to the first ClassA! Where ClassA & ClassB are in separate
projects.

Something like:

public interface Interface2
{
void Method2()
}

public class Class1
{

Interface2 i2;

public Class1(Interface2 i2)
{
this.i2 = i2;
}
}

public class Class2 : Interface2
{

Class1 c2;

public Class2()
{
c2 = new Class1(this);
}

void Method2()
{
}
}

Instead of passing is to expose a Interface2 property on UserControl1.
Depending on the requirements of the project I will actually use
Activator.CreateInstance to create an instance of the class that implements the interface...

Because Project2 (class2) has a reference to Project1, Class2 can use
methods of Class1 directly. Class1 however uses methods of Class2 indirectly via the interface. Note in this case the interface can be either an actual
Interface of a base Class.

Hope this helps
Jay
"pnp" <pnp.at.softlab.ece.ntua.gr> wrote in message
news:ea**************@TK2MSFTNGP12.phx.gbl...
Thanks Jay, on your replying so soon.

By using interfaces the problem still remains because I need to create
objects of
classA in Proj1 in classB in Proj2 and vice versa... These are graphical
usercontrols and I don't want to put them in the same dll because they

need
to be seperate modules... :(

Besides the mediator function, is there something else that could be done?


Peter N. P.
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
pnp,
Use a Separated Interface Pattern.

http://www.martinfowler.com/eaaCatal...Interface.html

Project1 would define UserControl1 along with Interface2. UserControl1

would
maintain a reference to Interface2. Interface2 would have any Properties, Subs, Functions, or Events that UserControl1 needed of UserControl2.

Project2 would define UserControl2 which implements Interfac2.

Project2 would reference Project1, however Project1 would not reference Project2.

Your form's project could reference both Project1 & Project2 & connect the two controls on the forms.
However! I have to ask the question: Aren't you introducing too much
coupling if UserControl1 requires UserControl2 & visa versa? I would
seriously consider a Mediator Pattern instead of a Separated Interface
Pattern, as the Mediator would have a reference to the two controls
mediating any communication between the two controls. The form itself

could
be the Mediator, or the Mediator could be its own UserControl or

Component.

Hope this helps
Jay

"pnp" <pnp.at.softlab.ece.ntua.gr> wrote in message
news:Os**************@TK2MSFTNGP09.phx.gbl...
> I'm developing an app (in C #) that uses 2 usercontrols that must be in > different dll's.
> The problem is that each one needs to use the other, so as a result
I get
a
> circular reference error when I try to add the references to the

dll's. >
> Is there a way round this problem? In C++ one could use header files... What
> can I do here?
>
>



Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: jinal jhaveri | last post by:
Hi All, I have one question regarding circular inheritance I have 3 files 1) A.py , having module A and some other modules 2) B.py having module B and some other modules 3) C.py having...
2
by: Earth Worm Jim | last post by:
I have been able to get simple circular references to be serialized in xml by using the ImportTypeMapping method on the SoapReflectionImporter class. But I am unable to serialise circular...
8
by: Jeff Connelly | last post by:
We're getting this error and don't know where to find the problem. I assume this is usually issued in the typical case where project A has a reference to project B, and project B has a reference...
3
by: Keith F. | last post by:
Visual Studio doesn't allow circular references between projects. I have a situation where I need to allow 2 projects to reference each other. Is there any way to make Visual Studio allow this? ...
0
by: Alan Samet | last post by:
Before telling me what I already know about what this error means, please read the post. I encountered this bizarre error when running aspnet_compiler.exe. Unfortunately, I don't know of a way...
2
by: Lapu-Lapu | last post by:
I have authored a web service using ASP 2.0. The web services return objects that use generics and that also contain circular references. Programmatically, everything works well, as long as you...
5
by: Madhur | last post by:
Hello If I define two classes in the same cs file. And in each class, I define the object of other class as a member. Can anyone explain me how .NET or its compiler will resolve this kind of...
0
balabaster
by: balabaster | last post by:
Hi, I have a couple of tables: Units( Unit_PKey Int Identity(1,1) Primary Key, Unit_Name nvarchar(8), Unit_Description nvarchar(32) )
1
by: Marc Gravell | last post by:
The only common issue with circular object references is tree-based serialization (for example, XmlSerializer and DataContractSerializer in its default mode). Graph-based serializers...
2
by: Dansk | last post by:
Hi all, I am currently writing some code that explores assemblies dependencies. I start loading the first assembly with Assmebly.LoadFrom which gives me an Assembly instance. Then, I...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.