circular-dependency

Dealing with circular inclusion in a parent/child class relationship

↘锁芯ラ 提交于 2020-01-03 15:12:21
问题 Assume I've made a class, say Parent , that has a composition relation with Child . The parent class holds a list of children. I want all children to hold a reference to the parent, so every child holds a Parent pointer. This will cause circular inclusion. I refer to Child in parent.h and I refer to Parent in child.h . Therefore Parent will need to include Child , which needs to include Parent . What's the best way to work around this? 回答1: You'll have to use forward declaration: //parent.h

Depedency injection: injecting partially-initialized objects

拜拜、爱过 提交于 2020-01-03 10:42:06
问题 This question is about Unity Container but I guess it is applicable to any dependency container. I have two classes with circular dependencies: class FirstClass { [Dependency] public SecondClass Second { get; set; } } class SecondClass { public readonly FirstClass First; public SecondClass(FirstClass first) { First = first; } } Technically it's possible to instantiate and correctly inject dependencies for both of them if treat them as singletons: var firstObj = new FirstClass(); var secondObj

Why is circular dependency allowed with namespaces in c#?

百般思念 提交于 2020-01-03 09:25:34
问题 In c# you're allowed to have a statement in file a.cs (which has namespace of MyApp.A): using MyApp.B; while file b.cs (which has namespace of MyApp.B) already have the statement using MyApp.A; If a similar dependency would exist in different dll's (where a.dll has a reference to b.dll and vice versa) it wouldn't be allowed because of circular dependency error, so why is it allowed with namespaces (and compiler doesn't even produce a warning)? Isn't it a code smell to do so anyway? 回答1:

Fortran OOP circular dependency handling, interfaces

纵然是瞬间 提交于 2020-01-03 03:33:05
问题 Compiler: ifort version 12.1.5 I'm writing some Fortran code and I'd like to make use of some F2003 OOP features, but I'm hitting some stumbling blocks. Paring down the example, I wish to have two derived types A and B, each of which have a pointer to instances of the other. In Fortran, circular dependencies between modules are explicitly disallowed, so these two types would have to reside in the same module. This compiles: module testModule implicit none type A type(B),pointer :: b1 end type

Circular-dependency best practice

自古美人都是妖i 提交于 2020-01-02 04:33:06
问题 I'm currently writing a web scraper which retrieves information from the internet. Simplified it looks like this. Data access project Objects to retrieve raw data Objects to parse the the raw data into objects (!!) The entities that the parser returns. Now, I'm creating the actual parser, and I'm going to use it like this: using Application.DataAccess; using Application.DataAccess.Entities; namespace Application{ public class TestScraper{ public static ScrapeIt() { var source = DataAcces

ClassCircularityError thrown by ClassLoader.defineClass

非 Y 不嫁゛ 提交于 2020-01-02 00:58:09
问题 I'm loading classes using a custom class loader. For the most part, everything works, but sometimes when I load particularly complex projects/libraries, I get a strange bug: Exception in thread "main" java.lang.ClassCircularityError: org/apache/commons/codec/binary/Hex at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632) at java.lang.ClassLoader.defineClass(ClassLoader.java:616) at java.lang.ClassLoader.defineClass(ClassLoader

Circular import with structs in Golang [duplicate]

一世执手 提交于 2020-01-01 04:37:16
问题 This question already has answers here : Registering packages in Go without cyclic dependency (2 answers) Closed 4 years ago . I have a project with several modules in Golang. I am having problem with circular imports because of the scenario below: Details A module Game contains a struct with the current Game state. Another module (Modifier) is doing some game specific stuff and calculations and therefore modifies the game state. Because of this, Modifier will need the struct Game, but not

Visual Studio 2012 - Find Circular References Efficiently

ⅰ亾dé卋堺 提交于 2020-01-01 02:53:10
问题 Currently if I want to check for circular references inside a solution I select Architecture - Generate Dependency Graph - For Solution . Then from the new tab that opens I select Layout - Analyzers - Circular References Analyzer . Finally if I drill down from the individual assemblies and there are circular references I can see them highlighted in red on the graph and they also appear as warnings in the Error List. Since I intend to spot circular references even between methods of the same

C++ circular reference problem

纵饮孤独 提交于 2019-12-31 06:53:21
问题 I have 2 classes: DataObject and DataElement . DataObject holds pointers to (only) DataElement s, and a DataElement contains pointers to several types, among which a DataObject . This used to be no problem, since I only use pointers to DataObject s in DataElement , so a forward declaration of DataObject in the header of DataElement is enough. Now, however, I try to add a destructor to DataElement , in which I need a delete on a DataObject . On this the compiler says: dataelement/destructor.cc

Circular dependency in Django ForeignKey?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-31 02:56:10
问题 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. 回答1: If this is really a bootstrapping problem and not something that will reoccur during normal usage, you could just create a