circular-dependency

OO design and circular dependencies

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 05:50:45
I am currently struggling with a circular dependency problem when designing my classes. Ever since I read about the Anemic Domain Model (something I was doing all the time), I have really been trying to get away from creating domain objects that were just "buckets of getters and setters" and return to my OO roots. However, the problem below is one that I come across a lot and I'm not sure how I should solve it. Say we have a Team class, that has many Players . It doesn't matter what sport this is :) A team can add and remove players, in much the same way a player can leave a team and join

How to solve circular dependency in Require.js?

爷,独闯天下 提交于 2019-12-03 03:09:55
Basically, the idea is that "sub" module creates an object, and that object should be part of a utilities library which is the "main" module. However, the "sub" object depends on utilities from "main": // Main module define(['sub'], function(sub) { var utils = { utilityMain: function () { // ... }; // ... }; tools.subModule = sub; return tools; }); // Sub module define(['main'], function(main) { return new (function () { // Singleton object using functions in main module var somestuff = function () { main.utilityMain(); // etc }; })(); }); How can I achieve this with require.js without

Objective C - Error: 'Expected a type'

南楼画角 提交于 2019-12-03 01:57:20
I'm getting a very strange error on something that I would have thought to be simple. #import <Foundation/Foundation.h> #import "ViewController.h" #import "GameObject.h" @interface GameController : NSObject @property (strong) GLKBaseEffect * effect; @property (strong) NSMutableArray * gameObjects; @property (strong) NSMutableArray * objectsToRemove; @property (strong) NSMutableArray * objectsToAdd; + (GameController *) sharedGameController; - (void) tick:(float)dt; - (void) initializeGame: (ViewController*) viewcontroller;//ERROR: EXPECTED A TYPE - (void) createObject:(Class) objecttype

RequireJS, Circular Dependencies and Exports “Magic” Method

倾然丶 夕夏残阳落幕 提交于 2019-12-02 22:08:23
问题 I've been trying to get RequireJS set up to handle circular dependencies using the special 'exports' magic module as recommended by James Burke's answer to this question. Following the example given by @jrburke in that question: define("Employee", ["exports", "Company"], function(Company) { function Employee(name) { this.name = name; this.company = new Company.Company(name + "'s own company"); }; exports.Employee = Employee; }); define("Company", ["exports", "Employee"], function(Employee) {

Python module dependency

落爺英雄遲暮 提交于 2019-12-02 20:40:38
Ok I have two modules, each containing a class, the problem is their classes reference each other. Lets say for example I had a room module and a person module containing CRoom and CPerson. The CRoom class contains infomation about the room, and a CPerson list of every one in the room. The CPerson class however sometimes needs to use the CRoom class for the room its in, for example to find the door, or too see who else is in the room. The problem is with the two modules importing each other I just get an import error on which ever is being imported second :( In c++ I could solve this by only

RequireJS, Circular Dependencies and Exports “Magic” Method

江枫思渺然 提交于 2019-12-02 12:39:59
I've been trying to get RequireJS set up to handle circular dependencies using the special 'exports' magic module as recommended by James Burke's answer to this question . Following the example given by @jrburke in that question: define("Employee", ["exports", "Company"], function(Company) { function Employee(name) { this.name = name; this.company = new Company.Company(name + "'s own company"); }; exports.Employee = Employee; }); define("Company", ["exports", "Employee"], function(Employee) { function Company(name) { this.name = name; this.employees = []; }; Company.prototype.addEmployee =

friend member function in C++ - forward declaration not working

烈酒焚心 提交于 2019-12-02 11:57:44
I'm having a situation similar to the one described in Specify a class member function as a friend of another class? . However in my case, class B needs to know class A since it's using it, so the solution given in that thread is not working for me. I tried to give also a forward declaration to the function itself but it didn't work as well. It seems that each class need the full definition of the other... Is there any easy way to solve it? I prefer a solution which doesn't involve new classes which wrap one of the old classes. code example: //A.h class B; //not helping void B::fB(); //not

Two classes with two circular references

◇◆丶佛笑我妖孽 提交于 2019-12-02 05:09:35
问题 I have two different classes made in two different units, how do i will creat circular references? in Delphi(the classes are in different units) unit1: Uses unit2; type Ta = class(tobject) public b:Tb; end; Unit2: type Tb = class(tobject) public a:Ta; end; 回答1: It is indeed possible to circumvent the circular unit reference, using class helpers . By adding a common UnitClassHelper including class helpers for both Ta and Tb it could be solved like this : unit Unit1; interface type Ta = class

Two classes with two circular references

我只是一个虾纸丫 提交于 2019-12-02 02:00:33
I have two different classes made in two different units, how do i will creat circular references? in Delphi(the classes are in different units) unit1: Uses unit2; type Ta = class(tobject) public b:Tb; end; Unit2: type Tb = class(tobject) public a:Ta; end; It is indeed possible to circumvent the circular unit reference, using class helpers . By adding a common UnitClassHelper including class helpers for both Ta and Tb it could be solved like this : unit Unit1; interface type Ta = class(tobject) public b : TObject; end; implementation uses UnitClassHelper; - unit Unit2; interface type Tb =

Circular dependency in Django ForeignKey?

左心房为你撑大大i 提交于 2019-12-02 01:12:47
I have two models in Django: A: b = ForeignKey("B") B: a = ForeignKey(A) I want these ForeignKeys to be non-NULL. However, I cannot create the objects because they don't have a PrimaryKey until I save(). But I cannot save without having the other objects PrimaryKey. How can I create an A and B object that refer to each other? I don't want to permit NULL if possible. If this is really a bootstrapping problem and not something that will reoccur during normal usage, you could just create a fixture that will prepopulate your database with some initial data. The fixture-handling code includes