473,385 Members | 1,707 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,385 software developers and data experts.

Circular reference problem

I have two assemblies that each consist of several classes.
Each object instantiated from those classes can have one or more child- and/or parentobjects that are also instantiated from those classes. Most relationships exist within one assembly, but relationships between assemblies may sometimes occur. For each relationship, I have to make sure that an object from Class1 knows that it can have an object from Class2 as one of its children. Likewise, I have to make sure that an object from Class2 knows that it can have an object from Class1 as its parent.
With a relationship existing between two assemblies, this obviously results in a circular reference. However, in this case a circular reference is exactly what is required.

How can I solve this problem? Or, in other words, how can I work around the circular reference restriction?

Any help will be very much appreciated!

Vera

Nov 22 '05 #1
2 1975
Hi Vera,

You should put crossreferenced classes in shared third assembly.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

"Vera" <an*******@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com...
I have two assemblies that each consist of several classes.
Each object instantiated from those classes can have one or more child- and/or parentobjects that are also instantiated from those classes. Most
relationships exist within one assembly, but relationships between
assemblies may sometimes occur. For each relationship, I have to make sure
that an object from Class1 knows that it can have an object from Class2 as
one of its children. Likewise, I have to make sure that an object from
Class2 knows that it can have an object from Class1 as its parent. With a relationship existing between two assemblies, this obviously results in a circular reference. However, in this case a circular reference
is exactly what is required.
How can I solve this problem? Or, in other words, how can I work around the circular reference restriction?
Any help will be very much appreciated!

Vera

Nov 22 '05 #2
Vera,
In addition to Miha's suggestion.

The Separated Interface Pattern is very useful to avoid a circular reference
between assemblies.

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

Define an Interface that Class1 uses that Class2 implements. Put this
interface in the same assembly as Class1 (or a third assembly). The Class1
assembly needs to reference the assembly where the interface is defined if
its not in the same assembly. The Class2 assembly needs to reference the
Class1 assembly & the assembly where the interface is defined. Class2 can
reference Class1 directly, while Class1 can only reference Class2 via the
interface that it implements.

Something like:
' Assembly 1
Public Interface IClass2
Public Property Value1() As Integer
Public Sub Method1()
End Interface

Public Class Class1

Public Sub Test(ByVal object2 As IClass2)
If object2.Value1 = 100 Then
object2.Method1()
End If
End Sub

End Class

' Assembly 2
' References Assembly 1

Public Class Class2
Implements IClass2

Public Property Value1() As Integer Implements IClass2.Value1
...

Public Sub Method1() Implements IClass2.Value1
...

End Class

Note instead of an Interface, you could use an Abstract Base Class
(MustInherit).

Hope this helps
Jay

"Vera" <an*******@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com...
I have two assemblies that each consist of several classes.
Each object instantiated from those classes can have one or more child- and/or parentobjects that are also instantiated from those classes. Most
relationships exist within one assembly, but relationships between
assemblies may sometimes occur. For each relationship, I have to make sure
that an object from Class1 knows that it can have an object from Class2 as
one of its children. Likewise, I have to make sure that an object from
Class2 knows that it can have an object from Class1 as its parent. With a relationship existing between two assemblies, this obviously results in a circular reference. However, in this case a circular reference
is exactly what is required.
How can I solve this problem? Or, in other words, how can I work around the circular reference restriction?
Any help will be very much appreciated!

Vera

Nov 22 '05 #3

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

Similar topics

2
by: Vera | last post by:
I have two assemblies that each consist of several classes. Each object instantiated from those classes can have one or more child- and/or parentobjects that are also instantiated from those...
1
by: dotnetnewbie | last post by:
Hi all I am new to .NET and webservice so I wish someone can shed some light on me. I have a Project class and a Product class, the Project can contain multiple Products (as an ArrayList). In...
11
by: Steve Jorgensen | last post by:
I just came up with a really tidy little solution to the VB/VBA circular reference issue. It only works with Access 2000 or newer, but that's about the only down-side. The issue... You need an...
6
by: T Koster | last post by:
After a few years of programming C, I had come to believe that I finally knew how to correctly organise my structure definitions in header files for mutually dependent structures, but I find myself...
4
by: Henke | last post by:
I have this scenario. public class A { public int numbers; public class A() { }
12
by: Frank Rizzo | last post by:
I have a circular reference between 2 classes in the same project (i.e. each class refers to the other). The app runs fine and I am seeing no issues, which kind of surprised me. Are there any...
6
by: Stephen Robertson | last post by:
We are currently in a dead end with a circular reference issue using vb.net, and are hoping someone might help us resolve it. Idea... We have frmmain calling frmperson (dim f as new frmperson)...
3
by: Solution Seeker | last post by:
Hi All, I am here with a Query and need a Solution for it. The Query is as Follows, We have 3 Projects in a Solution - Say UI, CMN and PRD First One Deals with UI Forms Second One Deals...
2
by: Jeremy Kitchen | last post by:
I have inherited a project and I am trying to figure out why the failing units tests that exist fail. I a, getting the following error when I attempt serialization. Any advice on what I should...
3
by: =?Utf-8?B?UGF1bCBIYWxl?= | last post by:
Moving all User Controls to a single directory has solved my problem - Thanks Eliyahu. That said, I still got one Circular ref error yesterday, rebuilt again and the build was fine? Far far...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.