# Redux: Circular Imports (Tim Cook)

**URL:** <https://discourse.openehr.org/t/redux-circular-imports-tim-cook/12907>\
**Category:** Implementers (archive)\
**Created:** [4 July 2008 01:18 UTC](https://discourse.openehr.org/t/redux-circular-imports-tim-cook/12907 "2008-07-04T01:18:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Max\_Young](https://discourse.openehr.org/letter_avatar_proxy/v4/letter/m/46a35a/32.png) [@Max\_Young](https://discourse.openehr.org/u/Max_Young)\
**Post date:** [4 July 2008 01:18 UTC](https://discourse.openehr.org/t/redux-circular-imports-tim-cook/12907/1 "2008-07-04T01:18:49Z")

</div>

There's nothing wrong with a class defining a reference to another (or  
the same) instance of that class - that's how most hierarchical OO  
implementations would work.  
I don't know Python - but other languages certainly won't worry about  
this - it's not a circular reference in as much as the reference is (at  
run time) to an instance of a class of the same type which may be the  
same object, but generally would not be.

In the case of the thumbnail attribute it does mean a thumbnail can have  
a thumbnail can have a thumbnail, for example - not likely but possible  
in the model. Not circular but hierarchical.

For storing/retrieving there then needs to be implemented some mechanism  
for 'walking' the structure from object to object - and if there is a  
circular reference there, it needs to be dealt with (usually by flagging  
each object as it is dealt with)

I'm not sure I read your email right, though - as you said you defined  
ontology in IArchetype? Maybe I'm missing some Pythonism but I would  
have had IArchetypeOntology implementing IArchetype, and  
ArchetypeOntology implementing IArchetypeOntology

Eg in C#  
&nbsp;&nbsp;&nbsp;&nbsp;public interface IArchetype  
&nbsp;&nbsp;{}  
&nbsp;&nbsp;public class Archetype : IArchetype  
&nbsp;&nbsp;{}  
&nbsp;&nbsp;public interface IArchetypeOntology : IArchetype  
&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;Archetype ParentArchetype { get; set;}  
&nbsp;&nbsp;}  
&nbsp;&nbsp;public class ArchetypeOntology : IArchetypeOntology  
&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;private Archetype parentArchetype;  
&nbsp;&nbsp;&nbsp;&nbsp;public Archetype ParentArchetype  
&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;get  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return parentArchetype;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;parentArchetype = value;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;}

And I can have

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Archetype a = new Archetype();  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ArchetypeOntology b = new ArchetypeOntology();  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b.ParentArchetype = a;

Sorry if I have missed the point entirely - my first post;

Max
