Questions tagged [circular-dependency]
49 questions
52
votes
3 answers
How to solve circular dependency?
I have three classes that are circular dependant to each other:
TestExecuter execute requests of TestScenario and save a report file using ReportGenerator class.
So:
TestExecuter depends on ReportGenerator to generate the report
ReportGenerator…

sabrina2020
- 687
- 1
- 5
- 7
27
votes
5 answers
How to model a circular reference between immutable objects in C#?
In the following code example, we have an class for immutable objects that represents a room. North, South, East, and West represent exits into other rooms.
public sealed class Room
{
public Room(string name, Room northExit, Room southExit, Room…

Rock Anthony Johnson
- 963
- 9
- 14
24
votes
10 answers
What's the proper way to model this real-world activity that seems to need circular references in OOP?
I've been wrestling with a problem in a Java project about circular references. I'm trying to model a real-world situation in which it seems the objects in question are interdependent and need to know about each other.
The project is a generic…

Damian Walker
- 243
- 2
- 5
16
votes
5 answers
If A has B and B holds reference of A, is it a flawed design need to be fixed?
Suppose, I have class Boss and Worker; Boss has a Worker and Worker holds a reference of Boss:
Boss.h
#include "Worker.h"
class Boss{
public:
Worker worker;
};
Worker.h
class Boss;
class Worker{
Boss* boss;
};
In C++, Worker doesn't need…

ggrr
- 5,725
- 11
- 35
- 37
7
votes
2 answers
What are the potential problems with operational circular dependency between microservices
I am relatively new to microservice architecture and I was never before involved in a project where the architect insists on having a circular dependency between services.
I am in a position without a choice to design two microservices with circular…

gsf
- 264
- 3
- 8
5
votes
3 answers
How to avoid DI dependency cycle for observer pattern
In my project I'm using the observer pattern in several places, i.e. the subject notifies the observers about something, and expect them to act. The subject does not know anything about the details of these observers.
With Spring I…

C-Otto
- 169
- 6
5
votes
1 answer
How can I resolve circular dependency within service layer in a n-tier architecture system?
I am currently starting a new project with a 4-tier architecture design. The layers is set as follow.
+------------------+
+----------------+ Presentation |
…

mannok
- 189
- 5
5
votes
3 answers
Resolving circular dependency between two classes
I am trying to resolve a circular dependency between two components in my system. The Messenger component is responsible for sending and receiving messages on a web socket. The Controller component requires use of the Messenger component to be able…

Robert Hunt
- 159
- 1
- 1
- 3
4
votes
3 answers
Is 2 methods calling each other code smell?
For example, if 2 classes depend on each other, it is a kind of circular dependency and should be avoided. How about methods? for example, if I have 2 methods which call each other:
public void methodA(){
//some other code
if(something){
…

ocomfd
- 5,652
- 8
- 29
- 37
3
votes
0 answers
How to structure python modules/packages according to dependecy inversion
If I am working on a project, say it has this file structure:
car/
body/
__init__.py
doors.py
bonnet.py
engine/
cyclinderhead/
__init__.py
pistons.py
__init__.py
crankshaft.py
…

run_the_race
- 139
- 4
3
votes
2 answers
Is circular reference with Typescript array properties bad design?
I understand that having circular dependency can be bad design. However, I have a question regarding a certain class structure.
As an example:
ocean.ts
import {Boat} from './boat';
export class Ocean {
boats: Array = [];
…

Ray
- 49
- 1
- 5
3
votes
1 answer
Circular dependency problem
"Single item in a set depends on the whole set. Set depends on that item."
I'm creating a compiler (https://github.com/SuperJMN/Plotty). In the last stage, the Intermediate Code is converted to Machine Instructions. I have them represented with the…

SuperJMN
- 413
- 3
- 9
3
votes
4 answers
Circular Interface references
I've heard circular references are generally an issue, however I was wondering if this was true for interfaces that reference other interfaces, for example:
IQuestion{
IAnswer getCorrectAnswer();
IList getAllAnswers();
}
IAnswer{
…

Aidan Connelly
- 139
- 5
3
votes
2 answers
What other approaches are there to break circular dependency in MVC?
I'm attempting to build a web front-end based on the MVC pattern, as opposed to based on the libraries involved (e.g. React.js).
I'm using constructor-based dependency injection and interfaces to de-couple the implementations of each element (of…

pleasedesktop
- 131
- 3
3
votes
3 answers
What is the motivation or usage to create a interface use once only just for breaking circular dependency?
I understand if 2 classes have circular dependency, eg:
public class MyWindow{
public MyWindow(){
new MyDialog(this);
}
public onDialogResponse(int option){
}
}
public class MyDialog{
MyWindow myWindow;
public…

ggrr
- 5,725
- 11
- 35
- 37