Distribution of number of references to other object in an object

I been thinking about an improvement to a garbage collector (details not important for this question) and wished to know how often does a object have no reference to other objects. Clearly this will depend on the language.

Many people must have research this and published the data, yet I can’t come up with the correct words to type into Google.

Circular dependence and many references to the same object

I have tried to design a class diagram for my first game. But then I realized that there are some ugly parts.

First, there is reference from StateSystem to State and from State to StateSystem. The StateSystem object contains references to State instances and one of them is always current. StateSystem calls it’s update and render functions. But every instance of State also has to have a reference back to StateSystem, so it can change state to another one. I’d like to know how to avoid the circular dependence in this case.

Secondly, I don’t know where to hold reference(s) to the Input object. Generally, all classes which belong to the UI (green classes) need a reference to the same instance (only existing instance) of Input due to mouse collision detection. Input contains stored information about pressed keys, mouse coordinates and so on. Should I store the reference in every object that needs it?

Moreover, what about TextureManager class? The only thing it does is store Texture instances via string IDs (and preparing it for OpenGL) and when needed, it returns a texture according to a given ID. Should I consider using, for example, the Builder pattern and let only the “director” object own the texture manager and create concrete textures for objects?

Circular References

I have always ‘designed’ systems so that each process was a discrete ‘program’ – so setting up a customer would be a discrete executable program, as would setting up a supplier or maintaining the codes used in the system. Each ‘program’ then had an callable function to allow it to start any of the other programs or to attach notes/documents to the ‘object’ being maintained.

However, I have just been setting up a small system for my own use and decided to ‘funtionalise’ the programs – so each program became a function call. So now a ‘program’ is called rather than executed. This then gives me circular references: Function A -> Function B -> Function C -> Function A.

The question is then, if I require the ability to be able to start any ‘program’ from any other, is the only way to do this without circular references, what I had initially – i.e. each program is a discrete executable in its own right?

How to delete foreign key with lots of references

Table B have several thousand records that references table A with a foreign key.

The application sends a request to delete the row from table A. It’s important that the synchronous operation would be immediate and won’t be at risk for timeouts.

If a cascade delete is used, and thus several thousands of records will be deleted as well, could it cause the deletion to take a long time? (not immediate).

Assuming that it could lead to a long deletion operation, what could be done as an alternative? I’ve though perhaps to delete the record as “deleted” and to perform the actual deletion in some background process (where the referencing rows would be deleted before the parent), but this approach feels rather error prone (since all of the existing queries will need to reference this new “markedAsDeleted” column.

Any ideas?

Creation of aggregate root that contains references to other aggregate roots

I would like to model the following entities: “Person”, “Company” and the aggregate that ties the two together “Membership”. I have identified that Person and Company are aggregate roots. Thus, “Membership” would hold a reference (id) of both those aggregate roots, plus other value objects/entities that a membership holds (for example the title that the person has for that company).

In my architecture I have the following layers: Api controllers, services, domains, repository. When creating a Membership object, the controller receives two identifiers (for person and for company). Currently the service is responsible for making a call to the CompanyService – to ensure that a company with that id exists and to the PersonService – to ensure a person with that id exists. However, in the Domain model I currently have a constructor that takes in two ids, which makes it feel really anemic. Also, in a further iteration, there will be the addition of a list of references to a third aggregate root, Vehicle. Thus a vehicle can exist by itself, or it can also belong to a membership.

Is this a bad way of modelling these entities? Is there a better way? I have read about the notion of domain services and application services, but my application does not currently have that distinction and I don’t know if that concept would help in this case.

Even the behaviour of the aggregate roots feels a bit dry when it comes to functionality related to the other aggregate roots it holds references for: ie. the Membership domain model would have the ability to “Link a car”, setting a car for itself, but again, receiving just an identifier that it would add to a list of identifiers.

How to avoid circular references in JavaScript?

I have two classes. A Bot class and a Client class.

Heres a relevant section of the Bot class.

class Bot {     constructor(client) {         this.client = client;         this.client.on(ChatEvent.NEW_MESSAGE, this.processMessage.bind(this));         this.client.on(ChatEvent.EDIT, this.processMessage.bind(this));     }      async processMessage(msg) {}     saveData(name, data){} } 

As you can see the Bot constructor accepts a Client instance.

Here’s a relevant section of the Client class.

class Client {    async getSites() {         let sites = this.bot.loadData('sites', sites);         if(rep){           return sites;         }         resp = await request({             [...]         });         sites = JSON.parse(resp);         this.bot.saveData('sites', sites);         return sites;      } } 

The Client class needs to access the Bot instance in the line this.bot.loadData and this.bot.saveData.

How can I do this without a circular reference?

Ideally I would want to be able to do:

const bot = new Bot(new Client([...])); 

The following way might work, but it uses a circular references:

bot = new Bot(); bot.client = new Client(bot); 

Does Tarjan algorithm fail for this test case ? references :gfg and Tushar roy’s tutorial

The test case is : There are 3 vertices 1,2,3 such

edge: source-destination

1-2 1-3 2-3 

As dfs proceeds from 1 to 2 and then to 3 . Following are the discovery and low times :

1 discT:0,lowT:0;  2 discT:1,lowT:1;  3 discT:2,lowT:2; 

Since 2’s disc time is less than 3’s low time . 2 becomes the articulation point due to the theorem which should NOT BE.

Am i doing something wrong . Kindly explain. Below is my dfs function->

public void dfs(){              ArrayDeque<vertex> st=new ArrayDeque<>();              st.push(vertexList.get(0));              int pt=1;             vertexList.get(0).discTime=0;             vertexList.get(0).lowTime=0;             vertexList.get(0).visited=true;             int numberOfverticesCovered=0;              while(!st.isEmpty()){                  vertex v=st.peek();                  System.out.println("considering "+v.label);                  vertex p=getAdjacent(v);                  if(p==null)                  {                      System.out.println("left with no unvisited adjacent vertices "+v.label);                      if(v!=vertexList.get(0)){                          LinkedList<edge> le=adjList.get(v.label-1);                          for (edge e : le)                          {                                  if(v.discTime<=e.destination.lowTime)                                  {                                     artPoints.add(v);                                      System.out.println("new articulation point found "+v.label+" for edge "+e.source.label+" and "+e.destination.label);                                      System.out.println("disc time of "+v.label+"  is "+v.discTime+" and low time is "+v.lowTime);                                      System.out.println("disc time of adj "+e.destination.label+"  is "+e.destination.discTime+" and low time is "+e.destination.lowTime);                                     break;                                  }                                     v.lowTime=Math.min(v.lowTime, e.destination.lowTime);                                     System.out.println("new low time of "+v.label+"  is "+v.lowTime);                          }                      }                      numberOfverticesCovered+=1;                      st.pop();                  }                  else                  {                      v.children+=1;     //                 System.out.println("adding child "+p.label+" to parent "+v.label);                      p.discTime=pt;                      p.lowTime=pt;                      p.parent=v;                      st.push(p);                      pt+=1;                  }                  if(st.isEmpty()&& numberOfverticesCovered!=vertexList.size()){                      for (vertex object : vertexList) {                          if(!object.visited)                          {                              object.discTime=pt;                              object.lowTime=pt;                              object.visited=true;                              st.push(object);                              break;                          }                      }                  }              }               if(vertexList.get(0).children>1 ) //  put in check for back edge for the other children so that they are not connected to each other.              {                               artPoints.add(vertexList.get(0));                  System.out.println("added root as an articulation point and it has "+vertexList.get(0).children);              }           }       } 

MAINTAINING CROSS REFERENCES WHILST DIVIDING DOCUMENT

I need to divide one 1000 page document into four 250 page documents but preserve the cross references. Thus footnote 22 ‘See p 688’ appearing on page 45 would now automatically change to ‘See Book 2, page 124.’ Or footnote 569 on pg 1029 ‘See p 45’ would automatically change to ‘See Book 1, pg 45’ Is this possible either in Word or another programme to which I can transfer the 1000 page document.?

Many Thanks.