Questions tagged [circular-dependency]
54 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
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
- 15
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
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,873
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
- 274
6
votes
2 answers
How to easily avoid circular dependencies
In a legacy project's service layer, there are tens of service classes and among them there is one service, UtilityService using 2 other services:
class UtilityService{
private UserService userService;
private ContactService contactService;
…
Rui
- 1,935
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
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
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,750
4
votes
4 answers
Circular dependency and object creation when attempting DDD
I have a domain where an Organization has People.
Organization Entity
public class Organization {
private readonly List _people = new List();
public Person CreatePerson(string name) {
var person = new…
Matthew
- 2,026
3
votes
1 answer
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
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
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
- 453
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
- 138