Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Circular dependencies

I have 2 projects.

Project#2 has a reference to Project#1

Now I need to reference Project#2 in Project#1, but vs.net is complaining about a circular dependency.

Is there a way out of this?

like image 1000
mrblah Avatar asked Jan 12 '10 21:01

mrblah


People also ask

What is meant by circular dependency?

A circular dependency occurs when two classes depend on each other. For example, class A needs class B, and class B also needs class A. Circular dependencies can arise in Nest between modules and between providers.

Are circular dependencies OK?

and, yes, cyclic dependencies are bad: They cause programs to include unnecessary functionality because things are dragged in which aren't needed. They make it a lot harder to test software. They make it a lot harder to reason about software.

How do you avoid circular dependencies?

Avoiding circular dependencies by refactoring The NestJS documentation advises that circular dependencies be avoided where possible. Circular dependencies create tight couplings between the classes or modules involved, which means both classes or modules have to be recompiled every time either of them is changed.


1 Answers

Absolutely not. Circular dependencies are a indication of bad design. I don't mean to be harsh. There are some ways out of this.

1) You can refactor common code to another project, say Project#0

2) You can fix your design, which is probably the way to go.

Uncle Bob has a good article on Packaging Principles which includes the Acyclic Dependencies Principle. http://www.objectmentor.com/resources/articles/granularity.pdf. Read this to know why cyclic dependencies are a bad thing.

like image 147
Craig Wilson Avatar answered Sep 24 '22 20:09

Craig Wilson