Circular dependency flagged at compile time

  • Thread starter Thread starter _DS
  • Start date Start date
D

_DS

I have two projects that currently need to refer to each other. More
precisely:

Proj A:
Class 1 refers to Proj B Class 1

Proj B:
Class 1
Class 2 refers to Proj A Class 1

Visual studio, for good reason, doesn't like that.

Obviously I could split Proj B into two separate projects. There are
no crossrefs between the two classes in Proj B, but the classes do
really belong together.

I've read about application of Interfaces to break the full circle but
I don't see any elegant way of applying that in this case.

Or I can kludge it and remove Proj B from Proj A's solution, then
replace 'Project' references with hard refs to DLLs. That would seem
to compromise build integrity (and would have to be changed for
release build).

Any alternatives?
 
_DS,

I would say a bit of refactoring is due here. I would combine the class
from Proj A with Proj B. They can still have separate namespaces. Either
that, or create project C, which Project A and B both reference.

Hope this helps.
 
Could you give them more descriptive names than A and B? If I knew a
little more about the domain in which you're working, and what the
classes / assemblies do, I could probably indicate how to solve your
problem using interfaces.
 
Could you give them more descriptive names than A and B? If I knew a
little more about the domain in which you're working, and what the
classes / assemblies do, I could probably indicate how to solve your
problem using interfaces.

To rephrase:

I have two projects that currently need to refer to each other. More
precisely:

Proj A 'ComplexDataType':
ComplexDataTypeCollection - Contains TypeX from proj B Class

Proj B: 'TypeXProcessor':
TypeXFormatConverter
TypeXWriter - Gets data from collection in Proj A

Proj A simply defines a complex data type and collections of that data
type. The data type includes a component of 'TypeX' so the
ComponentBuilder relies on the converter class in Proj B.

Proj B deals only with TypeX (a specific string format). It has a
class for converting to TypeX format, and a class for writing it to a
(specifically formatted) file.

As the ComplexDataType collection is built, it refers to
TypeXFormatConverter to create one of its fields. That's not the
problem. The problem arises because the ProjB's TypeX-derived file
writer needs to take the ComplexDataTypeCollection as an argument.

So Proj A needs to refer to the converter in Proj B.

Proj B needs the data type from Proj A.

The collection in Project A is used for lots of purposes, but happens
to encompass a TypeX field, among other things.

The functions in Project B all relate only to TypeX, so I'd like to
keep them together in one lib.

Aren't you sorry you asked? <g>
 
_DS said:
To rephrase:

I have two projects that currently need to refer to each other. More
precisely:

Proj A 'ComplexDataType':
ComplexDataTypeCollection - Contains TypeX from proj B Class

Proj B: 'TypeXProcessor':
TypeXFormatConverter
TypeXWriter - Gets data from collection in Proj A

Proj A simply defines a complex data type and collections of that data
type. The data type includes a component of 'TypeX' so the
ComponentBuilder relies on the converter class in Proj B.

Proj B deals only with TypeX (a specific string format). It has a
class for converting to TypeX format, and a class for writing it to a
(specifically formatted) file.

As the ComplexDataType collection is built, it refers to
TypeXFormatConverter to create one of its fields. That's not the
problem. The problem arises because the ProjB's TypeX-derived file
writer needs to take the ComplexDataTypeCollection as an argument.

So Proj A needs to refer to the converter in Proj B.

Proj B needs the data type from Proj A.

The collection in Project A is used for lots of purposes, but happens
to encompass a TypeX field, among other things.

The functions in Project B all relate only to TypeX, so I'd like to
keep them together in one lib.

Pass a list (array / array list...) of TypeX to ProjectB from the
ComplexDataTypeCollection. You have already stated that "ProjectB deals only
with TypeX" so there is no need for it to know anything about
ComplexDataTypeCollection so all you want is a simple list of TypeX's to
allow ProjectB to do it's stuff on the TypeX's.

SP
 

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

Back
Top